Fix merge error and some code optimization

This commit is contained in:
codezjx 2022-07-12 22:01:07 +08:00
parent cf5cffe60e
commit 3c2516f4ed
3 changed files with 19 additions and 28 deletions

View File

@ -72,7 +72,7 @@ def download_song_by_song(song, download_folder, sub_folder=True, program=False)
if program: if program:
cover_url = song['coverUrl'] cover_url = song['coverUrl']
else: else:
cover_url = song['album']['coverUrl'] cover_url = song['album']['blurPicUrl']
if cover_url is None: if cover_url is None:
if program: if program:

View File

@ -18,7 +18,7 @@ def resize_img(file_path, max_size=(640, 640), quality=90):
img.save(file_path, quality=quality) 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 # If no ID3 tags in mp3 file
try: try:
audio = MP3(file_path, ID3=ID3) 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 # add artist name
if is_program: if is_program:
id3.add( art_name = song['dj']['nickname']
TPE1(
encoding=3,
text=song['dj']['nickname']
)
)
else: else:
id3.add( art_name = song['artists'][0]['name']
TPE1( id3.add(
encoding=3, TPE1(
text=song['artists'][0]['name'] encoding=3,
) text=art_name
) )
)
# add song name # add song name
id3.add( id3.add(
TIT2( TIT2(
@ -76,25 +71,21 @@ def add_metadata_to_song(file_path, cover_path, song, is_program = False):
) )
# add album name # add album name
if is_program: if is_program:
id3.add( album_name = song['dj']['brand']
TALB(
encoding=3,
text=song['dj']['brand']
)
)
else: else:
id3.add( album_name = song['album']['name']
TALB( id3.add(
encoding=3, TALB(
text=song['album']['name'] encoding=3,
) text=album_name
) )
#add track no )
# add track no
if not is_program: if not is_program:
id3.add( id3.add(
TRCK( TRCK(
encoding=3, 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. # programs doesn't have a valid album info.

View File

@ -36,7 +36,7 @@ def download_album_songs(album_id):
def download_program(program_id): def download_program(program_id):
program = api.get_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) folder_path = os.path.join(config.DOWNLOAD_DIR, folder_name)
download_song_by_song(program, folder_path, False, True) download_song_by_song(program, folder_path, False, True)