From 3c2516f4edb09ff7530c9e2af96159ef867f0aee Mon Sep 17 00:00:00 2001 From: codezjx Date: Tue, 12 Jul 2022 22:01:07 +0800 Subject: [PATCH] Fix merge error and some code optimization --- ncm/downloader.py | 2 +- ncm/file_util.py | 43 +++++++++++++++++-------------------------- ncm/start.py | 2 +- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/ncm/downloader.py b/ncm/downloader.py index f611807..18565c0 100644 --- a/ncm/downloader.py +++ b/ncm/downloader.py @@ -72,7 +72,7 @@ def download_song_by_song(song, download_folder, sub_folder=True, program=False) if program: cover_url = song['coverUrl'] else: - cover_url = song['album']['coverUrl'] + cover_url = song['album']['blurPicUrl'] if cover_url is None: if program: diff --git a/ncm/file_util.py b/ncm/file_util.py index 3be0745..2dfa875 100644 --- a/ncm/file_util.py +++ b/ncm/file_util.py @@ -18,7 +18,7 @@ def resize_img(file_path, max_size=(640, 640), quality=90): img.save(file_path, quality=quality) -def add_metadata_to_song(file_path, cover_path, song, is_program = False): +def add_metadata_to_song(file_path, cover_path, song, is_program=False): # If no ID3 tags in mp3 file try: audio = MP3(file_path, ID3=ID3) @@ -53,20 +53,15 @@ def add_metadata_to_song(file_path, cover_path, song, is_program = False): ) # add artist name if is_program: - id3.add( - TPE1( - encoding=3, - text=song['dj']['nickname'] - ) - ) + art_name = song['dj']['nickname'] else: - id3.add( - TPE1( - encoding=3, - text=song['artists'][0]['name'] - ) + art_name = song['artists'][0]['name'] + id3.add( + TPE1( + encoding=3, + text=art_name ) - + ) # add song name id3.add( TIT2( @@ -76,25 +71,21 @@ def add_metadata_to_song(file_path, cover_path, song, is_program = False): ) # add album name if is_program: - id3.add( - TALB( - encoding=3, - text=song['dj']['brand'] - ) - ) + album_name = song['dj']['brand'] else: - id3.add( - TALB( - encoding=3, - text=song['album']['name'] - ) + album_name = song['album']['name'] + id3.add( + TALB( + encoding=3, + text=album_name ) - #add track no + ) + # add track no if not is_program: id3.add( TRCK( encoding=3, - text="%s/%s" %(song['no'],song['album']['size']) + text="%s/%s" % (song['no'], song['album']['size']) ) ) # programs doesn't have a valid album info. diff --git a/ncm/start.py b/ncm/start.py index 61e8461..bac71eb 100644 --- a/ncm/start.py +++ b/ncm/start.py @@ -36,7 +36,7 @@ def download_album_songs(album_id): def download_program(program_id): program = api.get_program(program_id) - folder_name = format_string(program['dj']['brand']) + ' - album' + folder_name = format_string(program['dj']['brand']) + ' - program' folder_path = os.path.join(config.DOWNLOAD_DIR, folder_name) download_song_by_song(program, folder_path, False, True)