From dab823d09efb2065d0fbdc82aff6c02fff6815c5 Mon Sep 17 00:00:00 2001 From: Raju komati Date: Mon, 25 Oct 2021 09:22:53 +0530 Subject: [PATCH] updated folder name --- {src => zspotify}/album.py | 9 ++++++--- {src => zspotify}/app.py | 33 ++++++++++++++++++++++++--------- {src => zspotify}/const.py | 3 +++ {src => zspotify}/playlist.py | 6 ++++-- {src => zspotify}/podcast.py | 0 {src => zspotify}/track.py | 0 {src => zspotify}/utils.py | 0 {src => zspotify}/zspotify.py | 0 8 files changed, 37 insertions(+), 14 deletions(-) rename {src => zspotify}/album.py (78%) rename {src => zspotify}/app.py (81%) rename {src => zspotify}/const.py (95%) rename {src => zspotify}/playlist.py (93%) rename {src => zspotify}/podcast.py (100%) rename {src => zspotify}/track.py (100%) rename {src => zspotify}/utils.py (100%) rename {src => zspotify}/zspotify.py (100%) diff --git a/src/album.py b/zspotify/album.py similarity index 78% rename from src/album.py rename to zspotify/album.py index 12f86eb6..a331a222 100644 --- a/src/album.py +++ b/zspotify/album.py @@ -1,3 +1,4 @@ +"""It's provides functions for downloading the albums""" from tqdm import tqdm from const import ITEMS, ARTISTS, NAME, ID @@ -16,7 +17,8 @@ def get_album_tracks(album_id): limit = 50 while True: - resp = ZSpotify.invoke_url_with_params(f'{ALBUM_URL}/{album_id}/tracks', limit=limit, offset=offset) + resp = ZSpotify.invoke_url_with_params(f'{ALBUM_URL}/{album_id}/tracks', + limit=limit, offset=offset) offset += limit songs.extend(resp[ITEMS]) if len(resp[ITEMS]) < limit: @@ -42,9 +44,10 @@ def download_album(album): """ Downloads songs from an album """ artist, album_name = get_album_name(album) tracks = get_album_tracks(album) - for n, track in tqdm(enumerate(tracks, start=1), unit_scale=True, unit='Song', total=len(tracks)): + for album_number, track in tqdm(enumerate(tracks, start=1), unit_scale=True, + unit='Song', total=len(tracks)): download_track(track[ID], f'{artist}/{album_name}', - prefix=True, prefix_value=str(n), disable_progressbar=True) + prefix=True, prefix_value=str(album_number), disable_progressbar=True) def download_artist_albums(artist): diff --git a/src/app.py b/zspotify/app.py similarity index 81% rename from src/app.py rename to zspotify/app.py index d1c234d5..97ea7b43 100644 --- a/src/app.py +++ b/zspotify/app.py @@ -1,3 +1,4 @@ +"""Entrypoint of ZSpotify app. It provides functions for searching""" import sys from librespot.audio.decoders import AudioQuality @@ -5,7 +6,7 @@ from tabulate import tabulate from album import download_album, download_artist_albums from const import TRACK, NAME, ID, ARTISTS, ITEMS, TRACKS, EXPLICIT, ALBUMS, OWNER, \ - PLAYLISTS, DISPLAY_NAME + PLAYLISTS, DISPLAY_NAME, LIMIT, OFFSET, TYPE, S_NO, ALBUM from playlist import download_from_user_playlist, download_playlist, \ download_playlist_with_id from podcast import download_episode, get_show_episodes @@ -40,6 +41,9 @@ def client() -> None: def process_args_input(): + """ + process the sys args + """ if sys.argv[1] == '-p' or sys.argv[1] == '--playlist': download_from_user_playlist() elif sys.argv[1] == '-ls' or sys.argv[1] == '--liked-songs': @@ -54,6 +58,11 @@ def process_args_input(): def process_url_input(url, call_search=False): + """ + process the input and calls appropriate download method + @param url: input url + @param call_search: boolean variable to notify calling search method + """ track_id, album_id, playlist_id, episode_id, show_id, artist_id = regex_input_for_urls(url) if track_id: @@ -75,7 +84,7 @@ def process_url_input(url, call_search=False): def search(search_term): """ Searches Spotify's API for relevant data """ - params = {'limit': '10', 'offset': '0', 'q': search_term, 'type': 'track,album,artist,playlist'} + params = {LIMIT: '10', OFFSET: '0', 'q': search_term, TYPE: 'track,album,artist,playlist'} resp = ZSpotify.invoke_url_with_params(SEARCH_URL, **params) total_tracks = total_albums = total_artists = 0 @@ -90,7 +99,8 @@ def search(search_term): ','.join([artist[NAME] for artist in track[ARTISTS]])]) counter += 1 total_tracks = counter - 1 - print(tabulate(track_data, headers=['S.NO', 'Name', 'Artists'], tablefmt='pretty')) + print(tabulate(track_data, headers=[S_NO, NAME.title(), ARTISTS.title()], + tablefmt='pretty')) print('\n') albums = resp[ALBUMS][ITEMS] @@ -98,10 +108,12 @@ def search(search_term): print('### ALBUMS ###') album_data = [] for album in albums: - album_data.append([counter, album[NAME], ','.join([artist[NAME] for artist in album[ARTISTS]])]) + album_data.append([counter, album[NAME], ','.join([artist[NAME] + for artist in album[ARTISTS]])]) counter += 1 total_albums = counter - total_tracks - 1 - print(tabulate(album_data, headers=['S.NO', 'Album', 'Artists'], tablefmt='pretty')) + print(tabulate(album_data, headers=[S_NO, ALBUM.title(), ARTISTS.title()], + tablefmt='pretty')) print('\n') artists = resp[ARTISTS][ITEMS] @@ -112,7 +124,7 @@ def search(search_term): artist_data.append([counter, artist[NAME]]) counter += 1 total_artists = counter - total_tracks - total_albums - 1 - print(tabulate(artist_data, headers=['S.NO', 'Name'], tablefmt='pretty')) + print(tabulate(artist_data, headers=[S_NO, NAME.title()], tablefmt='pretty')) print('\n') playlists = resp[PLAYLISTS][ITEMS] @@ -121,13 +133,16 @@ def search(search_term): for playlist in playlists: playlist_data.append([counter, playlist[NAME], playlist[OWNER][DISPLAY_NAME]]) counter += 1 - print(tabulate(playlist_data, headers=['S.NO', 'Name', 'Owner'], tablefmt='pretty')) + print(tabulate(playlist_data, headers=[S_NO, NAME.title(), OWNER.title()], tablefmt='pretty')) print('\n') perform_action(tracks, albums, playlists, artists, total_tracks, total_albums, total_artists) -def perform_action(tracks: list, albums: list, playlists: list, artists: list, total_tracks: int, total_albums: int, - total_artists: int): +def perform_action(tracks: list, albums: list, playlists: list, artists: list, + total_tracks: int, total_albums: int, total_artists: int): + """ + process and downloads the user selection + """ if len(tracks) + len(albums) + len(playlists) == 0: print('NO RESULTS FOUND - EXITING...') else: diff --git a/src/const.py b/zspotify/const.py similarity index 95% rename from src/const.py rename to zspotify/const.py index 44d7e688..d9ec2b20 100644 --- a/src/const.py +++ b/zspotify/const.py @@ -1,3 +1,4 @@ +""" provides commonly used string across different modules""" SANITIZE = ('\\', '/', ':', '*', '?', '\'', '<', '>', '"') SAVED_TRACKS_URL = 'https://api.spotify.com/v1/me/tracks' @@ -107,3 +108,5 @@ PLAYLIST_ID = 'PlaylistID' ALBUM_ID = 'AlbumID' TRACK_ID = 'TrackID' + +S_NO = 'S.NO' \ No newline at end of file diff --git a/src/playlist.py b/zspotify/playlist.py similarity index 93% rename from src/playlist.py rename to zspotify/playlist.py index ed51673c..26bd4d4a 100644 --- a/src/playlist.py +++ b/zspotify/playlist.py @@ -32,7 +32,8 @@ def get_playlist_songs(playlist_id): limit = 100 while True: - resp = ZSpotify.invoke_url_with_params(f'{PLAYLISTS_URL}/{playlist_id}/tracks', limit=limit, offset=offset) + resp = ZSpotify.invoke_url_with_params(f'{PLAYLISTS_URL}/{playlist_id}/tracks', + limit=limit, offset=offset) offset += limit songs.extend(resp[ITEMS]) if len(resp[ITEMS]) < limit: @@ -52,7 +53,8 @@ def download_playlist_with_id(playlist_id): playlist_songs = [song for song in get_playlist_songs(playlist_id) if song[TRACK][ID]] p_bar = tqdm(playlist_songs, unit='song', total=len(playlist_songs), unit_scale=True) for song in p_bar: - download_track(song[TRACK][ID], sanitize_data(name.strip()) + '/', disable_progressbar=True, create_m3u_file=True) + download_track(song[TRACK][ID], sanitize_data(name.strip()) + '/', disable_progressbar=True, + create_m3u_file=True) p_bar.set_description(song[TRACK][NAME]) diff --git a/src/podcast.py b/zspotify/podcast.py similarity index 100% rename from src/podcast.py rename to zspotify/podcast.py diff --git a/src/track.py b/zspotify/track.py similarity index 100% rename from src/track.py rename to zspotify/track.py diff --git a/src/utils.py b/zspotify/utils.py similarity index 100% rename from src/utils.py rename to zspotify/utils.py diff --git a/src/zspotify.py b/zspotify/zspotify.py similarity index 100% rename from src/zspotify.py rename to zspotify/zspotify.py