Merge pull request #587 from exislow:515-should-upc-be-barcode-instead
feat(metadata): ✨ add UPC metadata handling and configuration
This commit is contained in:
@@ -70,3 +70,16 @@ class AudioExtensionsValid(StrEnum):
|
||||
MP3 = ".mp3"
|
||||
OGG = ".ogg"
|
||||
ALAC = ".alac"
|
||||
|
||||
|
||||
class MetadataTargetUPC(StrEnum):
|
||||
UPC = "UPC"
|
||||
BARCODE = "BARCODE"
|
||||
EAN = "EAN"
|
||||
|
||||
|
||||
METADATA_LOOKUP_UPC: dict[str, dict[str, str]] = {
|
||||
"UPC": {"MP3": "UPC", "MP4": "UPC", "FLAC": "UPC"},
|
||||
"BARCODE": {"MP3": "BARCODE", "MP4": "BARCODE", "FLAC": "BARCODE"},
|
||||
"EAN": {"MP3": "EAN", "MP4": "EAN", "FLAC": "EAN"},
|
||||
}
|
||||
|
||||
@@ -35,12 +35,14 @@ from tidal_dl_ng.constants import (
|
||||
CHUNK_SIZE,
|
||||
COVER_NAME,
|
||||
EXTENSION_LYRICS,
|
||||
METADATA_LOOKUP_UPC,
|
||||
PLAYLIST_EXTENSION,
|
||||
PLAYLIST_PREFIX,
|
||||
REQUESTS_TIMEOUT_SEC,
|
||||
AudioExtensionsValid,
|
||||
CoverDimensions,
|
||||
MediaType,
|
||||
MetadataTargetUPC,
|
||||
QualityVideo,
|
||||
)
|
||||
from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token
|
||||
@@ -1218,9 +1220,13 @@ class Download:
|
||||
|
||||
path_cover = self.cover_to_file(path_media.parent, cover_data_album_file)
|
||||
|
||||
metadata_target_upc = MetadataTargetUPC(self.settings.data.metadata_target_upc)
|
||||
target_upc: dict[str, str] = METADATA_LOOKUP_UPC[metadata_target_upc]
|
||||
|
||||
# `None` values are not allowed.
|
||||
m: Metadata = Metadata(
|
||||
path_file=path_media,
|
||||
target_upc=target_upc,
|
||||
lyrics=lyrics,
|
||||
copy_right=copy_right,
|
||||
title=name_builder_title(track),
|
||||
|
||||
@@ -29,11 +29,13 @@ class Metadata:
|
||||
url_share: str
|
||||
replay_gain_write: bool
|
||||
upc: str
|
||||
target_upc: dict[str, str]
|
||||
m: mutagen.mp4.MP4 | mutagen.mp4.MP4 | mutagen.flac.FLAC
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
path_file: str | pathlib.Path,
|
||||
target_upc: dict[str, str],
|
||||
album: str = "",
|
||||
title: str = "",
|
||||
artists: str = "",
|
||||
@@ -78,6 +80,7 @@ class Metadata:
|
||||
self.url_share = url_share
|
||||
self.replay_gain_write = replay_gain_write
|
||||
self.upc = upc
|
||||
self.target_upc = target_upc
|
||||
self.m: mutagen.FileType = mutagen.File(self.path_file)
|
||||
|
||||
def _cover(self) -> bool:
|
||||
@@ -134,7 +137,7 @@ class Metadata:
|
||||
self.m.tags["ISRC"] = self.isrc
|
||||
self.m.tags["LYRICS"] = self.lyrics
|
||||
self.m.tags["URL"] = self.url_share
|
||||
self.m.tags["UPC"] = self.upc
|
||||
self.m.tags[self.target_upc["FLAC"]] = self.upc
|
||||
|
||||
if self.replay_gain_write:
|
||||
self.m.tags["REPLAYGAIN_ALBUM_GAIN"] = str(self.album_replay_gain)
|
||||
@@ -157,7 +160,7 @@ class Metadata:
|
||||
self.m.tags.add(TSRC(encoding=3, text=self.isrc))
|
||||
self.m.tags.add(USLT(encoding=3, lang="eng", desc="desc", text=self.lyrics))
|
||||
self.m.tags.add(WOAS(encoding=3, text=self.isrc))
|
||||
self.m.tags.add(TXXX(encoding=3, desc="UPC", text=self.upc))
|
||||
self.m.tags.add(TXXX(encoding=3, desc=self.target_upc["MP3"], text=self.upc))
|
||||
|
||||
if self.replay_gain_write:
|
||||
self.m.tags.add(TXXX(encoding=3, desc="REPLAYGAIN_ALBUM_GAIN", text=str(self.album_replay_gain)))
|
||||
@@ -179,7 +182,7 @@ class Metadata:
|
||||
self.m.tags["\xa9lyr"] = self.lyrics
|
||||
self.m.tags["isrc"] = self.isrc
|
||||
self.m.tags["\xa9url"] = self.url_share
|
||||
self.m.tags["----:com.apple.iTunes:UPC"] = self.upc.encode("utf-8")
|
||||
self.m.tags[f"----:com.apple.iTunes:{self.target_upc['MP4']}"] = self.upc.encode("utf-8")
|
||||
|
||||
if self.replay_gain_write:
|
||||
self.m.tags["----:com.apple.iTunes:REPLAYGAIN_ALBUM_GAIN"] = str(self.album_replay_gain).encode("utf-8")
|
||||
|
||||
@@ -3,7 +3,7 @@ from dataclasses import dataclass
|
||||
from dataclasses_json import dataclass_json
|
||||
from tidalapi import Quality
|
||||
|
||||
from tidal_dl_ng.constants import CoverDimensions, QualityVideo
|
||||
from tidal_dl_ng.constants import CoverDimensions, MetadataTargetUPC, QualityVideo
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@@ -54,6 +54,7 @@ class Settings:
|
||||
metadata_delimiter_album_artist: str = ", "
|
||||
filename_delimiter_artist: str = ", "
|
||||
filename_delimiter_album_artist: str = ", "
|
||||
metadata_target_upc: MetadataTargetUPC = MetadataTargetUPC.UPC
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@@ -117,6 +118,9 @@ class HelpSettings:
|
||||
metadata_delimiter_album_artist: str = "Metadata tag delimiter for multiple album artists. Default: ', '"
|
||||
filename_delimiter_artist: str = "Filename delimiter for multiple artists. Default: ', '"
|
||||
filename_delimiter_album_artist: str = "Filename delimiter for multiple album artists. Default: ', '"
|
||||
metadata_target_upc: str = (
|
||||
"Select the target metadata tag ('UPC', 'BARCODE', 'EAN') where to write the UPC information to. Default: 'UPC'."
|
||||
)
|
||||
|
||||
|
||||
@dataclass_json
|
||||
|
||||
Reference in New Issue
Block a user