Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load all existing subtitles before downloading subtitles #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions autosub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ local includes = {
-- Full paths are also allowed, e.g.:
-- '/home/david/Videos',
}
local scan_folders = {'ass', 'srt', 'sub', 'subs', 'subtitles'} -- Before downloading subtitles scan if these folders exist
--=============================================================================
local utils = require 'mp.utils'

Expand Down Expand Up @@ -164,6 +165,24 @@ function control_downloads()
log('No subtitles were found')
end

function scan_folder_present()
local p = io.popen('dir /b /ad "'..directory..'"')
for folder in p:lines() do
if folder ~= directory then
for _, scan_folder in ipairs(scan_folders) do
mp.msg.warn('checking folder ' .. scan_folder)
if string.find(string.lower(folder), string.lower(scan_folder)) then
log('Subtitles found inside directory "' .. folder .. '"')
mp.set_property('sub-auto', 'all')
mp.command('rescan_external_files')
return true
end
end
end
end
return false
end

-- Check if subtitles should be auto-downloaded:
function autosub_allowed()
local duration = tonumber(mp.get_property('duration'))
Expand All @@ -176,6 +195,8 @@ function autosub_allowed()
mp.msg.warn('Video is less than 15 minutes\n' ..
'=> NOT auto-downloading subtitles')
return false
elseif scan_folder_present() then
return false
elseif directory:find('^http') then
mp.msg.warn('Automatic subtitle downloading is disabled for web streaming')
return false
Expand Down