From 424a6969f55b7fa72f90908867c24771112efe41 Mon Sep 17 00:00:00 2001 From: jbannon Date: Thu, 28 Apr 2022 05:34:45 +0000 Subject: [PATCH] use beets mediafile in favor of old music-tag library --- config.yaml | 2 +- setup.cfg | 2 +- src/ytdl_sub/plugins/music_tags.py | 15 ++++++++--- subscriptions.yaml | 40 +++++++++++++++--------------- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/config.yaml b/config.yaml index 19f57796..b59930b8 100644 --- a/config.yaml +++ b/config.yaml @@ -22,7 +22,7 @@ presets: albumartist: "{artist}" title: "{title}" album: "{album}" - tracknumber: "{track_number}" + track: "{track_number}" year: "{album_year}" genre: "{genre}" diff --git a/setup.cfg b/setup.cfg index a0215047..f65b0083 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,7 +25,7 @@ install_requires = argparse==1.4.0 dicttoxml==1.7.4 mergedeep==1.3.4 - music-tag==0.4.3 + mediafile==0.9.0 Pillow==9.1.0 PyYAML==6.0 yt-dlp==2022.4.8 diff --git a/src/ytdl_sub/plugins/music_tags.py b/src/ytdl_sub/plugins/music_tags.py index de9a4066..26b22d6c 100644 --- a/src/ytdl_sub/plugins/music_tags.py +++ b/src/ytdl_sub/plugins/music_tags.py @@ -1,4 +1,4 @@ -import music_tag +import mediafile from ytdl_sub.entries.entry import Entry from ytdl_sub.plugins.plugin import Plugin @@ -28,7 +28,16 @@ class MusicTagsPlugin(Plugin[MusicTagsOptions]): """ Tags the entry's audio file using values defined in the metadata options """ - audio_file = music_tag.load_file(entry.get_download_file_path()) + audio_file = mediafile.MediaFile(entry.get_download_file_path()) for tag, tag_formatter in self.plugin_options.tags.dict.items(): - audio_file[tag] = self.overrides.apply_formatter(formatter=tag_formatter, entry=entry) + if tag not in audio_file.fields(): + # TODO: Add proper logger and warn here + print( + f"[ytld-sub: WARN] tag {tag} is not supported for {entry.ext} files. Supported " + f"tags: {', '.join(audio_file.sorted_fields())}" + ) + + tag_value = self.overrides.apply_formatter(formatter=tag_formatter, entry=entry) + setattr(audio_file, tag, tag_value) + audio_file.save() diff --git a/subscriptions.yaml b/subscriptions.yaml index 5b391c96..bfc55eb6 100644 --- a/subscriptions.yaml +++ b/subscriptions.yaml @@ -18,13 +18,13 @@ # artist: "DeLorra" # genre: "Synthwave / Electronic" # -#bl00dwave: -# preset: "soundcloud_with_id3_tags" -# soundcloud: -# username: bl00dwave -# overrides: -# artist: "bl00dwave" -# genre: "Synthwave / Electronic" +bl00dwave: + preset: "soundcloud_with_id3_tags" + soundcloud: + username: bl00dwave + overrides: + artist: "bl00dwave" + genre: "Synthwave / Electronic" # #tom_petty: # preset: "music_videos" @@ -56,16 +56,16 @@ # overrides: # artist: "The Gogos" -recent_channel_test: - preset: "yt_channel" - ytdl_options: - break_on_reject: True - youtube: - channel_id: "UCsvn_Po0SmunchJYOWpOxMg" - after: today-13days - output_options: - output_directory: "/tmp/dunkey" - keep_files: - after: today-3days - overrides: - tv_show_name: "Youtube: Dunkey" \ No newline at end of file +#recent_channel_test: +# preset: "yt_channel" +# ytdl_options: +# break_on_reject: True +# youtube: +# channel_id: "UCsvn_Po0SmunchJYOWpOxMg" +# after: today-13days +# output_options: +# output_directory: "/tmp/dunkey" +# keep_files: +# after: today-3days +# overrides: +# tv_show_name: "Youtube: Dunkey" \ No newline at end of file