Added option to merge subtitles into one mp4 file or separate into .vtt files (#100)

This commit is contained in:
Fede14it 2024-04-11 15:22:46 +02:00 committed by GitHub
parent eb6110e14f
commit 8e8c458024
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 11 deletions

View File

@ -105,6 +105,7 @@ You can change some behaviors by tweaking the configuration file.
| M3U8_OPTIONS | | Contains options specific to M3U8 file format. | | | M3U8_OPTIONS | | Contains options specific to M3U8 file format. | |
| download_audio | true | Indicates whether audio files should be downloaded or not. | false | | download_audio | true | Indicates whether audio files should be downloaded or not. | false |
| download_subtitles | true | Indicates whether subtitles should be downloaded or not. | false | | download_subtitles | true | Indicates whether subtitles should be downloaded or not. | false |
| merge_subtitles | true | Indicates if you want to merge subs in mp4 file or separate files .vtt| false |
| specific_list_audio | ["ita"] | A list of specific audio languages to download. | ["eng", "fra"] | | specific_list_audio | ["ita"] | A list of specific audio languages to download. | ["eng", "fra"] |
| specific_list_subtitles | ["eng"] | A list of specific subtitle languages to download. | ["spa", "por"] | | specific_list_subtitles | ["eng"] | A list of specific subtitle languages to download. | ["spa", "por"] |
|map_episode_name |%(tv_name)_S%(season)E%(episode)_%(episode_name)| Mapping to choose the name of all episode of TV Show (see [Episode Name Usage](#Episode-name-usage)). |map_episode_name |%(tv_name)_S%(season)E%(episode)_%(episode_name)| Mapping to choose the name of all episode of TV Show (see [Episode Name Usage](#Episode-name-usage)).

View File

@ -54,6 +54,7 @@ DOWNLOAD_AUDIO = config_manager.get_bool('M3U8_OPTIONS', 'download_audio')
DOWNLOAD_SUBTITLES = config_manager.get_bool('M3U8_OPTIONS', 'download_subtitles') DOWNLOAD_SUBTITLES = config_manager.get_bool('M3U8_OPTIONS', 'download_subtitles')
DOWNLOAD_SPECIFIC_AUDIO = config_manager.get_list('M3U8_OPTIONS', 'specific_list_audio') DOWNLOAD_SPECIFIC_AUDIO = config_manager.get_list('M3U8_OPTIONS', 'specific_list_audio')
DOWNLOAD_SPECIFIC_SUBTITLE = config_manager.get_list('M3U8_OPTIONS', 'specific_list_subtitles') DOWNLOAD_SPECIFIC_SUBTITLE = config_manager.get_list('M3U8_OPTIONS', 'specific_list_subtitles')
MERGE_SUBTITLES = config_manager.get_bool('M3U8_OPTIONS', 'merge_subtitles')
TQDM_MAX_WORKER = config_manager.get_int('M3U8', 'tdqm_workers') TQDM_MAX_WORKER = config_manager.get_int('M3U8', 'tdqm_workers')
TQDM_PROGRESS_TIMEOUT = config_manager.get_int('M3U8', 'tqdm_progress_timeout') TQDM_PROGRESS_TIMEOUT = config_manager.get_int('M3U8', 'tqdm_progress_timeout')
COMPLETED_PERCENTAGE = config_manager.get_float('M3U8', 'download_percentage') COMPLETED_PERCENTAGE = config_manager.get_float('M3U8', 'download_percentage')
@ -823,6 +824,7 @@ class Downloader():
# Check if there are any downloaded subtitles # Check if there are any downloaded subtitles
if len(self.downloaded_subtitle) > 0: if len(self.downloaded_subtitle) > 0:
if MERGE_SUBTITLES:
# Log adding subtitles # Log adding subtitles
console.log(f"[cyan]Add subtitles.") console.log(f"[cyan]Add subtitles.")
@ -836,6 +838,19 @@ class Downloader():
self.downloaded_subtitle, self.downloaded_subtitle,
os.path.join(self.base_path, "out.mkv") os.path.join(self.base_path, "out.mkv")
) )
else:
console.log("[cyan]Moving subtitle out of tmp folder.")
for obj_sub in self.downloaded_subtitle:
try:
language = obj_sub.get('language').lower()
# Modifica la stringa se contiene "forced-", altrimenti la converte in minuscolo
language = (language.replace("forced-", "") + ".forced") if 'forced-' in language else language
sub_path = self.output_filename.replace(".mp4", f".{language}.vtt")
os.rename(obj_sub.get('path'), sub_path)
except Exception as e:
logging.error(f"Error moving subtitle: {e}. Skipping...")
continue
self.path_video_and_audio = path_video_and_audio self.path_video_and_audio = path_video_and_audio
self.path_join_subtitles = path_join_subtitles self.path_join_subtitles = path_join_subtitles

View File

@ -35,6 +35,7 @@
"M3U8_OPTIONS": { "M3U8_OPTIONS": {
"download_audio": true, "download_audio": true,
"download_subtitles": true, "download_subtitles": true,
"merge_subtitles": true,
"specific_list_audio": [ "specific_list_audio": [
"ita" "ita"
], ],