meeb / tubesync

Syncs YouTube channels and playlists to a locally hosted media server
GNU Affero General Public License v3.0
1.98k stars 129 forks source link

Thumbnail is not embedded into audio files even with "Embed Thumbnails" turned on #538

Open SSS-Says-Snek opened 3 months ago

SSS-Says-Snek commented 3 months ago

I'm using tubesync to download audio files from my playlist and play them on my phone (with the Musicolet app). I turned on both "Embed thumbnail" and "Embed metadata", and while metadata seems to be working fine, the thumbnails are not appearing in the previews. image

What I tried

I tried many different combinations of embedding thumbnail, embedding metadata, writing NFO, and changing the audio codec. None of them had any embedded thumbnails.

I also wrote a test script to see if anything was wrong with yt-dlp. However, I saw that this actually did embed the thumbnail into the file:

import yt_dlp

ytopts = {
    'format': 'm4a',
    'writethumbnail': True,
    'postprocessors': [{'key': 'FFmpegMetadata', 'add_metadata': True}, {'key': 'EmbedThumbnail'}],
    'quiet': False
}
with yt_dlp.YoutubeDL(ytopts) as y:
    y.download(['https://www.youtube.com/watch?v=aSXtXLAVgkE'])

with the output

[youtube] Extracting URL: https://www.youtube.com/watch?v=aSXtXLAVgkE
[youtube] aSXtXLAVgkE: Downloading webpage
[youtube] aSXtXLAVgkE: Downloading ios player API JSON
[youtube] aSXtXLAVgkE: Downloading web creator player API JSON
[youtube] aSXtXLAVgkE: Downloading m3u8 information
[info] aSXtXLAVgkE: Downloading 1 format(s): 140
[info] Downloading video thumbnail 46 ...
[info] Writing video thumbnail 46 to: Rachmaninoff: Piano Concerto #3 (Weissenberg 1968) [with score] [aSXtXLAVgkE].webp
[download] Destination: Rachmaninoff: Piano Concerto #3 (Weissenberg 1968) [with score] [aSXtXLAVgkE].m4a
[download] 100% of   40.05MiB in 00:00:04 at 9.37MiB/s
[FixupM4a] Correcting container of "Rachmaninoff: Piano Concerto #3 (Weissenberg 1968) [with score] [aSXtXLAVgkE].m4a"
[Metadata] Adding metadata to "Rachmaninoff: Piano Concerto #3 (Weissenberg 1968) [with score] [aSXtXLAVgkE].m4a"
[ThumbnailsConvertor] Converting thumbnail "Rachmaninoff: Piano Concerto #3 (Weissenberg 1968) [with score] [aSXtXLAVgkE].webp" to png
[EmbedThumbnail] mutagen: Adding thumbnail to "Rachmaninoff: Piano Concerto #3 (Weissenberg 1968) [with score] [aSXtXLAVgkE].m4a"
Tubesync Test script
image image

I skimmed tubesync's codebase, and I think that my test script's writethumbnail option may have something to do with it? I'm not sure though, since I can't test it because manually running tubesync without a container doesn't seem to be working for me (#534)

I also might be entirely getting the wrong idea of what embedding thumbnails is supposed to do 😅 Regardless, loving tubesync rn! Keep up the good work!

DorH92 commented 3 months ago

Same here. Thumbnail doesn't get embedded in the audio files..

meeb commented 3 months ago

Thanks for the issue. There are occasions where a relatively esoteric combination of yt-dlp and ffmpeg flags are required to get some metadata features to work. tubesync does set the same keys as you:

https://github.com/meeb/tubesync/blob/main/tubesync/sync/youtube.py#L164

The only difference is tubesync doesn't set 'writethumbnail': True for yt-dlp because thumbnails are downloaded separately and enabling this would download two copies of thumbnails with different file names.

I'll poke into it but it would seem that this particular container / encoding pair might require 'writethumbnail': True to work if your test is correct.