Skip to content

Commit

Permalink
Add upc and album_type to tidal metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
justin025 committed Dec 15, 2024
1 parent 7d759a8 commit a2bc121
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 74 deletions.
20 changes: 12 additions & 8 deletions src/onthespot/api/tidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,19 @@ def tidal_get_track_metadata(token, item_id):
track_data = make_call(f"{BASE_URL}/tracks/{item_id}", headers=headers, params=params)
if not track_data:
return
album_data = make_call(f"{BASE_URL}/albums/{track_data['album']['id']}", headers=headers, params=params)
album_track_data = make_call(f"{BASE_URL}/albums/{track_data['album']['id']}/tracks", headers=headers, params=params)

params["include"] = "items"
album_data = make_call(f"{BASEV2_URL}/albums/{track_data['album']['id']}", headers=headers, params=params)

# Artists
artists = []
for artist in track_data.get('artists', ''):
artists.append(artist.get('name', ''))

# Track Number
for i, track in enumerate(album_track_data['items']):
if track['id'] == int(item_id):
track_number = None
for i, track in enumerate(album_data.get('included', [])):
if track.get('id', '') == str(item_id):
track_number = i + 1
break
if not track_number:
Expand All @@ -244,10 +246,12 @@ def tidal_get_track_metadata(token, item_id):
info['album_artists'] = track_data.get('artist', '').get('name', '')
info['artists'] = conv_list_format(artists)
info['album_name'] = track_data.get('album', '').get('title', '')
info['total_tracks'] = album_data.get('numberOfTracks', '')
info['total_discs'] = album_data.get('numberOfVolumes', '')
info['release_year'] = album_data.get('releaseDate', '').split("-")[0]
info['image_url'] = f'https://resources.tidal.com/images/{(track_data.get("album", "").get("cover", "") or "").replace("-", "/")}/1280x1280.jpg'
info['total_tracks'] = album_data.get('data', {}).get('attributes', {}).get('numberOfItems', '')
info['total_discs'] = album_data.get('data', {}).get('attributes', {}).get('numberOfVolumes', '')
info['release_year'] = album_data.get('data', {}).get('attributes', {}).get('releaseDate', '').split("-")[0]
info['upc'] = album_data.get('data', {}).get('attributes', {}).get('barcodeId', '')
info['image_url'] = album_data.get('data', {}).get('attributes', {}).get('imageLinks', {})[0].get('href', '')
info['album_type'] = album_data.get('data', {}).get('attributes', {}).get('type', '').lower()
info['is_playable'] = track_data.get('streamReady', '')

return info
Expand Down
137 changes: 78 additions & 59 deletions src/onthespot/gui/qtui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-285</y>
<y>-2801</y>
<width>627</width>
<height>3225</height>
</rect>
Expand Down Expand Up @@ -3494,23 +3494,23 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_78">
<widget class="QGroupBox" name="groupBox_91">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_150">
<layout class="QHBoxLayout" name="horizontalLayout_163">
<item>
<widget class="QCheckBox" name="inp_embed_service_id">
<widget class="QCheckBox" name="inp_embed_upc">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Service ID</string>
<string>Embed UPC</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_87">
<spacer name="horizontalSpacer_100">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand Down Expand Up @@ -3538,23 +3538,23 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_94">
<item>
<widget class="QGroupBox" name="groupBox_80">
<widget class="QGroupBox" name="groupBox_78">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_152">
<layout class="QHBoxLayout" name="horizontalLayout_150">
<item>
<widget class="QCheckBox" name="inp_embed_timesignature">
<widget class="QCheckBox" name="inp_embed_service_id">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Time Signature</string>
<string>Embed Service ID</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_89">
<spacer name="horizontalSpacer_87">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand All @@ -3570,23 +3570,23 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_85">
<widget class="QGroupBox" name="groupBox_80">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_157">
<layout class="QHBoxLayout" name="horizontalLayout_152">
<item>
<widget class="QCheckBox" name="inp_embed_acousticness">
<widget class="QCheckBox" name="inp_embed_timesignature">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Acousticness</string>
<string>Embed Time Signature</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_94">
<spacer name="horizontalSpacer_89">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand Down Expand Up @@ -3614,23 +3614,23 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_95">
<item>
<widget class="QGroupBox" name="groupBox_81">
<widget class="QGroupBox" name="groupBox_85">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_153">
<layout class="QHBoxLayout" name="horizontalLayout_157">
<item>
<widget class="QCheckBox" name="inp_embed_danceability">
<widget class="QCheckBox" name="inp_embed_acousticness">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Danceability</string>
<string>Embed Acousticness</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_90">
<spacer name="horizontalSpacer_94">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand All @@ -3646,23 +3646,23 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_86">
<widget class="QGroupBox" name="groupBox_81">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_158">
<layout class="QHBoxLayout" name="horizontalLayout_153">
<item>
<widget class="QCheckBox" name="inp_embed_energy">
<widget class="QCheckBox" name="inp_embed_danceability">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Energy</string>
<string>Embed Danceability</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_95">
<spacer name="horizontalSpacer_90">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand Down Expand Up @@ -3690,23 +3690,23 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_96">
<item>
<widget class="QGroupBox" name="groupBox_90">
<widget class="QGroupBox" name="groupBox_86">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_162">
<layout class="QHBoxLayout" name="horizontalLayout_158">
<item>
<widget class="QCheckBox" name="inp_embed_instrumentalness">
<widget class="QCheckBox" name="inp_embed_energy">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Instrumentalness</string>
<string>Embed Energy</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_99">
<spacer name="horizontalSpacer_95">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand All @@ -3722,23 +3722,23 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_83">
<widget class="QGroupBox" name="groupBox_90">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_155">
<layout class="QHBoxLayout" name="horizontalLayout_162">
<item>
<widget class="QCheckBox" name="inp_embed_liveness">
<widget class="QCheckBox" name="inp_embed_instrumentalness">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Liveness</string>
<string>Embed Instrumentalness</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_92">
<spacer name="horizontalSpacer_99">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand Down Expand Up @@ -3766,23 +3766,23 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_97">
<item>
<widget class="QGroupBox" name="groupBox_87">
<widget class="QGroupBox" name="groupBox_83">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_159">
<layout class="QHBoxLayout" name="horizontalLayout_155">
<item>
<widget class="QCheckBox" name="inp_embed_loudness">
<widget class="QCheckBox" name="inp_embed_liveness">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Loudness</string>
<string>Embed Liveness</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_96">
<spacer name="horizontalSpacer_92">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand All @@ -3798,23 +3798,23 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_88">
<widget class="QGroupBox" name="groupBox_87">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_160">
<layout class="QHBoxLayout" name="horizontalLayout_159">
<item>
<widget class="QCheckBox" name="inp_embed_speechiness">
<widget class="QCheckBox" name="inp_embed_loudness">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Speechiness</string>
<string>Embed Loudness</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_97">
<spacer name="horizontalSpacer_96">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand All @@ -3841,6 +3841,38 @@
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_99">
<item>
<widget class="QGroupBox" name="groupBox_88">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_160">
<item>
<widget class="QCheckBox" name="inp_embed_speechiness">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Embed Speechiness</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_97">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_89">
<property name="title">
Expand Down Expand Up @@ -3873,19 +3905,6 @@
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_17">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
Expand Down
2 changes: 2 additions & 0 deletions src/onthespot/gui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def load_config(self):

# Checkboxes
self.inp_overwrite_existing_metadata.setChecked(config.get("overwrite_existing_metadata"))
self.inp_embed_upc.setChecked(config.get("embed_upc"))
self.inp_embed_service_id.setChecked(config.get("embed_service_id"))
self.inp_windows_explorer_thumbnails.setChecked(config.get("windows_10_explorer_thumbnails"))
self.inp_close_to_tray.setChecked(config.get("close_to_tray"))
Expand Down Expand Up @@ -208,6 +209,7 @@ def save_config(self):

# Checkboxes: config.set_('key', bool)
config.set_('overwrite_existing_metadata', self.inp_overwrite_existing_metadata.isChecked())
config.set_('embed_upc', self.inp_embed_upc.isChecked())
config.set_('embed_service_id', self.inp_embed_service_id.isChecked())
config.set_('windows_10_explorer_thumbnails', self.inp_windows_explorer_thumbnails.isChecked())
config.set_('close_to_tray', self.inp_close_to_tray.isChecked())
Expand Down
1 change: 1 addition & 0 deletions src/onthespot/otsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(self, cfg_path=None):
"embed_compilation": True,
"embed_lyrics": False,
"embed_explicit": False,
"embed_upc": False,
"embed_service_id": False,
"embed_timesignature": False,
"embed_acousticness": False,
Expand Down
Loading

0 comments on commit a2bc121

Please sign in to comment.