mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 17:51:24 +01:00
Compare commits
No commits in common. "83d4013ccb37c36790e6ce4eeed8b5598e84f16e" and "e9a49de89cb68c1f674d53003a6b07643edb2ab0" have entirely different histories.
83d4013ccb
...
e9a49de89c
|
@ -107,10 +107,8 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.report_warning(f'unable to embed using mutagen; {err}')
|
self.report_warning(f'unable to embed using mutagen; {err}')
|
||||||
success = False
|
success = False
|
||||||
else:
|
|
||||||
success = False
|
|
||||||
# Method 2: Use ffmpeg
|
# Method 2: Use ffmpeg
|
||||||
if not success:
|
else:
|
||||||
options = [
|
options = [
|
||||||
'-c', 'copy', '-map', '0:0', '-map', '1:0', '-write_id3v1', '1', '-id3v2_version', '3',
|
'-c', 'copy', '-map', '0:0', '-map', '1:0', '-write_id3v1', '1', '-id3v2_version', '3',
|
||||||
'-metadata:s:v', 'title="Album cover"', '-metadata:s:v', 'comment=Cover (front)']
|
'-metadata:s:v', 'title="Album cover"', '-metadata:s:v', 'comment=Cover (front)']
|
||||||
|
|
|
@ -587,8 +587,8 @@ class FFmpegVideoRemuxerPP(FFmpegVideoConvertorPP):
|
||||||
|
|
||||||
|
|
||||||
class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
|
class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
|
||||||
SUPPORTS_LYRICS = ('mp3', 'm4a', 'flac', 'opus')
|
AUDIO_EXTS = ('mp3', 'm4a', 'flac', 'opus')
|
||||||
SUPPORTED_EXTS = ('mp4', 'mov', 'm4a', 'webm', 'mkv', 'mka', *SUPPORTS_LYRICS)
|
SUPPORTED_EXTS = ('mp4', 'mov', 'm4a', 'webm', 'mkv', 'mka')
|
||||||
|
|
||||||
def __init__(self, downloader=None, already_have_subtitle=False):
|
def __init__(self, downloader=None, already_have_subtitle=False):
|
||||||
super().__init__(downloader)
|
super().__init__(downloader)
|
||||||
|
@ -596,8 +596,8 @@ class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
|
||||||
|
|
||||||
@PostProcessor._restrict_to(images=False)
|
@PostProcessor._restrict_to(images=False)
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
if info['ext'] not in self.SUPPORTED_EXTS:
|
if info['ext'] not in self.SUPPORTED_EXTS + self.AUDIO_EXTS:
|
||||||
self.to_screen(f'Subtitles can only be embedded in {", ".join(self.SUPPORTED_EXTS)} files')
|
self.to_screen(f'Subtitles can only be embedded in {", ".join(self.SUPPORTED_EXTS+self.AUDIO_EXTS)} files')
|
||||||
return [], info
|
return [], info
|
||||||
subtitles = info.get('requested_subtitles')
|
subtitles = info.get('requested_subtitles')
|
||||||
if not subtitles:
|
if not subtitles:
|
||||||
|
@ -661,8 +661,8 @@ class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
|
||||||
|
|
||||||
temp_filename = prepend_extension(filename, 'temp')
|
temp_filename = prepend_extension(filename, 'temp')
|
||||||
self.to_screen('Embedding subtitles in "%s"' % filename)
|
self.to_screen('Embedding subtitles in "%s"' % filename)
|
||||||
if info['ext'] in self.SUPPORTS_LYRICS:
|
if info['ext'] in self.AUDIO_EXTS:
|
||||||
self.embed_lyrics(info['filepath'], sub_dict=info['requested_subtitles'])
|
self.embed_lyrics(input_files)
|
||||||
else:
|
else:
|
||||||
self.run_ffmpeg_multiple_files(input_files, temp_filename, opts)
|
self.run_ffmpeg_multiple_files(input_files, temp_filename, opts)
|
||||||
os.replace(temp_filename, filename)
|
os.replace(temp_filename, filename)
|
||||||
|
@ -670,24 +670,23 @@ class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
|
||||||
files_to_delete = [] if self._already_have_subtitle else sub_filenames
|
files_to_delete = [] if self._already_have_subtitle else sub_filenames
|
||||||
return files_to_delete, info
|
return files_to_delete, info
|
||||||
|
|
||||||
def embed_lyrics(self, audio_file, sub_dict):
|
def embed_lyrics(self, input_files):
|
||||||
if len(sub_dict) > 1:
|
audio_file = input_files[0]
|
||||||
self.report_warning('More than one subtitle file found. Your media player will likely be unable to display all of them.')
|
subs = input_files[1]
|
||||||
|
if len(input_files) > 2:
|
||||||
if sub_dict[list(sub_dict.keys())[0]]['ext'] != 'lrc':
|
self.report_warning('More than one subtitle file found. Only one will be embedded')
|
||||||
|
if not subs.endswith('.lrc'):
|
||||||
raise PostProcessingError('LRC subtitles required. Use "--convert-subs lrc" to convert')
|
raise PostProcessingError('LRC subtitles required. Use "--convert-subs lrc" to convert')
|
||||||
|
|
||||||
lyrics_list = []
|
with open(subs, 'r', encoding='utf-8') as f:
|
||||||
for lyrics in sub_dict.keys():
|
lyrics = f.read().strip()
|
||||||
lyrics_list.append(sub_dict[lyrics]['data'])
|
|
||||||
if audio_file.endswith('.mp3'):
|
if audio_file.endswith('.mp3'):
|
||||||
for lyrics in lyrics_list:
|
|
||||||
audio = mutagen.id3.ID3(audio_file)
|
audio = mutagen.id3.ID3(audio_file)
|
||||||
audio.add(mutagen.id3.USLT(encoding=3, lang='und', desc='', text=lyrics))
|
audio.add(mutagen.id3.USLT(encoding=mutagen.id3.Encoding.UTF8, lang='und', desc='', text=lyrics))
|
||||||
audio.save()
|
audio.save()
|
||||||
else:
|
else:
|
||||||
metadata = mutagen.File(audio_file)
|
metadata = mutagen.File(audio_file)
|
||||||
metadata['©lyr' if audio_file.endswith('.m4a') else 'lyrics'] = lyrics_list
|
metadata['©lyr' if audio_file.endswith('.m4a') else 'lyrics'] = [lyrics]
|
||||||
metadata.save()
|
metadata.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user