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:
cover_url = song['coverUrl']
else:
cover_url = song['album']['coverUrl']
cover_url = song['album']['blurPicUrl']
if cover_url is None:
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)
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.

View File

@ -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)