Compare commits

...

4 Commits

Author SHA1 Message Date
Rohit
e9a49de89c added the newline back which i removed by mistake 2023-12-29 22:37:54 +05:30
Rohit
823543c2a4 Fix encoding issues in embedthumbnail.py and embed_lyrics() 2023-12-29 22:11:18 +05:30
fjueic
51af60e6d7
Update yt_dlp/postprocessor/ffmpeg.py
Co-authored-by: Simon Sawicki <accounts@grub4k.xyz>
2023-12-29 07:38:41 -08:00
fjueic
79bb8f51e4
Update yt_dlp/postprocessor/embedthumbnail.py
Co-authored-by: Simon Sawicki <accounts@grub4k.xyz>
2023-12-29 07:37:00 -08:00
2 changed files with 15 additions and 12 deletions

View File

@ -100,12 +100,12 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
del audio['APIC'] del audio['APIC']
with open(thumbnail_filename, 'rb') as thumbfile: with open(thumbnail_filename, 'rb') as thumbfile:
audio['APIC'] = mutagen.id3.APIC( audio['APIC'] = mutagen.id3.APIC(
encoding=3, mime='image/%s' % thumbnail_ext, type=3, encoding=mutagen.id3.Encoding.UTF8, mime='image/%s' % thumbnail_ext, type=3,
desc=u'Cover (front)', data=thumbfile.read()) desc=u'Cover (front)', data=thumbfile.read())
audio.save() audio.save()
temp_filename = filename # Mutagen saves to the original file temp_filename = filename # Mutagen saves to the original file
except Exception as err: except Exception as err:
self.report_warning('unable to embed using mutagen; %s' % error_to_compat_str(err)) self.report_warning(f'unable to embed using mutagen; {err}')
success = False success = False
# Method 2: Use ffmpeg # Method 2: Use ffmpeg
else: else:

View File

@ -639,6 +639,7 @@ class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
if not mp4_ass_warn and ext == 'mp4' and sub_ext == 'ass': if not mp4_ass_warn and ext == 'mp4' and sub_ext == 'ass':
mp4_ass_warn = True mp4_ass_warn = True
self.report_warning('ASS subtitles cannot be properly embedded in mp4 files; expect issues') self.report_warning('ASS subtitles cannot be properly embedded in mp4 files; expect issues')
if not sub_langs: if not sub_langs:
return [], info return [], info
@ -672,19 +673,21 @@ class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
def embed_lyrics(self, input_files): def embed_lyrics(self, input_files):
audio_file = input_files[0] audio_file = input_files[0]
subs = input_files[1] subs = input_files[1]
if len(input_files) > 2:
self.report_warning('More than one subtitle file found. Only one will be embedded')
if not subs.endswith('.lrc'): 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')
with open(subs, 'r', encoding='utf-8') as f:
lyrics = f.read().strip()
if audio_file.endswith('.mp3'):
audio = mutagen.id3.ID3(audio_file)
audio.add(mutagen.id3.USLT(encoding=mutagen.id3.Encoding.UTF8, lang='und', desc='', text=lyrics))
audio.save()
else: else:
with open(subs, 'r', encoding='utf-8') as f: metadata = mutagen.File(audio_file)
lyrics = f.read().strip() metadata['©lyr' if audio_file.endswith('.m4a') else 'lyrics'] = [lyrics]
if audio_file.endswith('.mp3'): metadata.save()
audio = mutagen.id3.ID3(audio_file)
audio.add(mutagen.id3.USLT(encoding=3, lang='eng', desc='', text=lyrics))
audio.save()
else:
metadata = mutagen.File(audio_file)
metadata['©lyr' if audio_file.endswith('.m4a') else 'lyrics'] = [lyrics]
metadata.save()
class FFmpegMetadataPP(FFmpegPostProcessor): class FFmpegMetadataPP(FFmpegPostProcessor):