From 6f5fc85e28fa6e0098a9aa6c0137dded77b59a50 Mon Sep 17 00:00:00 2001 From: Raoul Engelbrecht <62550766+glaceorizer@users.noreply.github.com> Date: Fri, 21 Apr 2023 02:41:26 +0200 Subject: [PATCH] Load all existing subtitles before downloading subtitles Now checks before subtitles are downloaded if subtitle folders exist. If yes, sub-auto is set to all and the files are rescanned. --- autosub.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/autosub.lua b/autosub.lua index f399f52..2c00231 100644 --- a/autosub.lua +++ b/autosub.lua @@ -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' @@ -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')) @@ -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