From 94c445fb9a76bcb1052dcaf6b205732a477254fc Mon Sep 17 00:00:00 2001 From: Justin Donofrio Date: Sun, 17 Nov 2024 14:22:37 -0500 Subject: [PATCH] add option to save search settings and use content types in deezer and soundcloud --- src/onthespot/api/deezer.py | 112 +++++++++++++++++--------------- src/onthespot/api/soundcloud.py | 49 +++++++------- src/onthespot/gui/settings.py | 16 +++++ src/onthespot/otsconfig.py | 7 ++ 4 files changed, 109 insertions(+), 75 deletions(-) diff --git a/src/onthespot/api/deezer.py b/src/onthespot/api/deezer.py index 56dde61..ed3b2ce 100644 --- a/src/onthespot/api/deezer.py +++ b/src/onthespot/api/deezer.py @@ -68,15 +68,15 @@ def deezer_get_artist_albums(artist_id): def deezer_get_track_metadata(token, item_id): logger.info(f"Get track info for: '{item_id}'") - + track_data = make_call(f"{DEEZER_BASE}/track/{item_id}") album_data = make_call(f"{DEEZER_BASE}/album/{track_data.get('album', {}).get('id', '')}") info = {} - # Initialize an empty list to store contributor names + # Initialize an empty list to store contributor names artists = [] - # Append all contributor names to the list + # Append all contributor names to the list for artist in track_data.get('contributors', ''): artists.append(artist['name']) @@ -157,8 +157,8 @@ def decryptfile(data_chunks, key, fo): Decrypt using blowfish with . Only every third 2048 byte block is encrypted. """ - blockSize = 2048 - i = 0 + blockSize = 2048 + i = 0 total_length = len(data_chunks) for start in range(0, total_length, blockSize): @@ -202,12 +202,12 @@ def deezer_login_user(account): # Prepare to call the API method = 'deezer.getUserData' - params = { + params = { 'api_version': "1.0", 'api_token': 'null', 'input': '3', 'method': 'deezer.getUserData' - } + } user_data = session.post( "http://www.deezer.com/ajax/gw-light.php", @@ -265,52 +265,60 @@ def deezer_get_search_results(token, search_term, content_types): playlist_url = f"{DEEZER_BASE}/search/playlist" track_url = f"{DEEZER_BASE}/search/track" - album_search = requests.get(album_url, params=params).json() - artist_search = requests.get(artist_url, params=params).json() - playlist_search = requests.get(playlist_url, params=params).json() - track_search = requests.get(track_url, params=params).json() - search_results = [] - for album in album_search['data']: - search_results.append({ - 'item_id': album['id'], - 'item_name': album['title'], - 'item_by': album['artist']['name'], - 'item_type': "album", - 'item_service': "deezer", - 'item_url': album['link'], - 'item_thumbnail_url': album["cover"] - }) - for artist in artist_search['data']: - search_results.append({ - 'item_id': artist['id'], - 'item_name': artist['name'], - 'item_by': artist['name'], - 'item_type': "artist", - 'item_service': "deezer", - 'item_url': artist['link'], - 'item_thumbnail_url': artist["picture"] - }) - for playlist in playlist_search['data']: - search_results.append({ - 'item_id': playlist['id'], - 'item_name': playlist['title'], - 'item_by': playlist['user']['name'], - 'item_type': "playlist", - 'item_service': "deezer", - 'item_url': playlist['link'], - 'item_thumbnail_url': playlist["picture"] - }) - for track in track_search['data']: - search_results.append({ - 'item_id': track['id'], - 'item_name': track['title'], - 'item_by': track['artist']['name'], - 'item_type': "track", - 'item_service': "deezer", - 'item_url': track['link'], - 'item_thumbnail_url': track["album"]["cover"] - }) + + if 'album' in content_types: + album_search = requests.get(album_url, params=params).json() + for album in album_search['data']: + search_results.append({ + 'item_id': album['id'], + 'item_name': album['title'], + 'item_by': album['artist']['name'], + 'item_type': "album", + 'item_service': "deezer", + 'item_url': album['link'], + 'item_thumbnail_url': album["cover"] + }) + + + if 'artist' in content_types: + artist_search = requests.get(artist_url, params=params).json() + for artist in artist_search['data']: + search_results.append({ + 'item_id': artist['id'], + 'item_name': artist['name'], + 'item_by': artist['name'], + 'item_type': "artist", + 'item_service': "deezer", + 'item_url': artist['link'], + 'item_thumbnail_url': artist["picture"] + }) + + if 'playlist' in content_types: + playlist_search = requests.get(playlist_url, params=params).json() + for playlist in playlist_search['data']: + search_results.append({ + 'item_id': playlist['id'], + 'item_name': playlist['title'], + 'item_by': playlist['user']['name'], + 'item_type': "playlist", + 'item_service': "deezer", + 'item_url': playlist['link'], + 'item_thumbnail_url': playlist["picture"] + }) + + if 'track' in content_types: + track_search = requests.get(track_url, params=params).json() + for track in track_search['data']: + search_results.append({ + 'item_id': track['id'], + 'item_name': track['title'], + 'item_by': track['artist']['name'], + 'item_type': "track", + 'item_service': "deezer", + 'item_url': track['link'], + 'item_thumbnail_url': track["album"]["cover"] + }) logger.info(search_results) diff --git a/src/onthespot/api/soundcloud.py b/src/onthespot/api/soundcloud.py index 37ecf34..c11e699 100644 --- a/src/onthespot/api/soundcloud.py +++ b/src/onthespot/api/soundcloud.py @@ -136,30 +136,33 @@ def soundcloud_get_search_results(token, search_term, content_types): track_url = f"{SOUNDCLOUD_BASE}/search/tracks" playlist_url = f"{SOUNDCLOUD_BASE}/search/playlists" - track_search = requests.get(track_url, headers=headers, params=params).json() - playlist_search = requests.get(playlist_url, headers=headers, params=params).json() - search_results = [] - for track in track_search['collection']: - search_results.append({ - 'item_id': track['id'], - 'item_name': track['title'], - 'item_by': track['user']['username'], - 'item_type': "track", - 'item_service': "soundcloud", - 'item_url': track['permalink_url'], - 'item_thumbnail_url': track["artwork_url"] - }) - for playlist in playlist_search['collection']: - search_results.append({ - 'item_id': playlist['id'], - 'item_name': playlist['title'], - 'item_by': playlist['user']['username'], - 'item_type': "playlist", - 'item_service': "soundcloud", - 'item_url': playlist['permalink_url'], - 'item_thumbnail_url': playlist["artwork_url"] - }) + + if 'track' in content_types: + track_search = requests.get(track_url, headers=headers, params=params).json() + for track in track_search['collection']: + search_results.append({ + 'item_id': track['id'], + 'item_name': track['title'], + 'item_by': track['user']['username'], + 'item_type': "track", + 'item_service': "soundcloud", + 'item_url': track['permalink_url'], + 'item_thumbnail_url': track["artwork_url"] + }) + + if 'playlist' in content_types: + playlist_search = requests.get(playlist_url, headers=headers, params=params).json() + for playlist in playlist_search['collection']: + search_results.append({ + 'item_id': playlist['id'], + 'item_name': playlist['title'], + 'item_by': playlist['user']['username'], + 'item_type': "playlist", + 'item_service': "soundcloud", + 'item_url': playlist['permalink_url'], + 'item_thumbnail_url': playlist["artwork_url"] + }) logger.info(search_results) return search_results diff --git a/src/onthespot/gui/settings.py b/src/onthespot/gui/settings.py index 78632d8..eddf65c 100644 --- a/src/onthespot/gui/settings.py +++ b/src/onthespot/gui/settings.py @@ -69,6 +69,14 @@ def load_config(self): # Checkboxes + self.inp_enable_search_tracks.setChecked(config.get("enable_search_tracks")) + self.inp_enable_search_albums.setChecked(config.get("enable_search_albums")) + self.inp_enable_search_artists.setChecked(config.get("enable_search_artists")) + self.inp_enable_search_playlists.setChecked(config.get("enable_search_playlists")) + self.inp_enable_search_episodes.setChecked(config.get("enable_search_episodes")) + self.inp_enable_search_shows.setChecked(config.get("enable_search_shows")) + self.inp_enable_search_audiobooks.setChecked(config.get("enable_search_audiobooks")) + self.inp_show_download_thumbnails.setChecked(config.get("show_search_thumbnails")) self.inp_show_search_thumbnails.setChecked(config.get("show_search_thumbnails")) self.inp_use_lrc_file.setChecked(config.get("use_lrc_file")) @@ -151,6 +159,14 @@ def save_config(self): # Checkboxes: config.set_('key', bool) + config.set_('enable_search_tracks', self.inp_enable_search_tracks.isChecked()) + config.set_('enable_search_albums', self.inp_enable_search_albums.isChecked()) + config.set_('enable_search_playlists', self.inp_enable_search_playlists.isChecked()) + config.set_('enable_search_artists', self.inp_enable_search_artists.isChecked()) + config.set_('enable_search_episodes', self.inp_enable_search_episodes.isChecked()) + config.set_('enable_search_shows', self.inp_enable_search_shows.isChecked()) + config.set_('enable_search_audiobooks', self.inp_enable_search_audiobooks.isChecked()) + config.set_('show_download_thumbnails', self.inp_show_search_thumbnails.isChecked()) config.set_('show_search_thumbnails', self.inp_show_search_thumbnails.isChecked()) config.set_('use_lrc_file', self.inp_use_lrc_file.isChecked()) diff --git a/src/onthespot/otsconfig.py b/src/onthespot/otsconfig.py index 8fc1e36..e634b46 100755 --- a/src/onthespot/otsconfig.py +++ b/src/onthespot/otsconfig.py @@ -74,6 +74,13 @@ def __init__(self, cfg_path=None): "create_m3u_playlists": False, # Create m3u based playlist "translate_file_path": False, # Translate downloaded file path to application language "ffmpeg_args": [], # Extra arguments for ffmpeg + "enable_search_tracks": True, # Enable listed category in search + "enable_search_albums": True, # Enable listed category in search + "enable_search_playlists": True, # Enable listed category in search + "enable_search_artists": True, # Enable listed category in search + "enable_search_episodes": True, # Enable listed category in search + "enable_search_shows": True, # Enable listed category in search + "enable_search_audiobooks": True, # Enable listed category in search "show_search_thumbnails": True, # Show thumbnails in search view "show_download_thumbnails": True, # Show thumbnails in download view "explicit_label": "🅴", # Explicit label in app and download path