Download max hot song numbers by config, and add comment for local config.
This commit is contained in:
parent
15f12dc9f2
commit
642081bb9d
|
@ -15,7 +15,8 @@ _CONFIG_FILE_PATH = os.path.join(_CONFIG_MAIN_PATH, 'ncm.ini')
|
||||||
_DEFAULT_DOWNLOAD_PATH = os.path.join(_CONFIG_MAIN_PATH, 'download')
|
_DEFAULT_DOWNLOAD_PATH = os.path.join(_CONFIG_MAIN_PATH, 'download')
|
||||||
|
|
||||||
# Global config value
|
# Global config value
|
||||||
DOWNLOAD_HOT_MAX = 50
|
DOWNLOAD_HOT_MAX_DEFAULT = 50
|
||||||
|
DOWNLOAD_HOT_MAX = DOWNLOAD_HOT_MAX_DEFAULT
|
||||||
DOWNLOAD_DIR = ''
|
DOWNLOAD_DIR = ''
|
||||||
SONG_NAME_TYPE = 1
|
SONG_NAME_TYPE = 1
|
||||||
SONG_FOLDER_TYPE = 1
|
SONG_FOLDER_TYPE = 1
|
||||||
|
@ -42,11 +43,40 @@ def load_config():
|
||||||
def init_config_file():
|
def init_config_file():
|
||||||
default_config = '''\
|
default_config = '''\
|
||||||
[settings]
|
[settings]
|
||||||
{key_max} = 50
|
|
||||||
|
#--------------------------------------
|
||||||
|
# Max download hot song numbers
|
||||||
|
#
|
||||||
|
# Range: 0 < hot_max < 50
|
||||||
|
#--------------------------------------
|
||||||
|
{key_max} = {value_max}
|
||||||
|
|
||||||
|
#--------------------------------------
|
||||||
|
# Song download directory
|
||||||
|
#--------------------------------------
|
||||||
{key_dir} = {value_dir}
|
{key_dir} = {value_dir}
|
||||||
|
|
||||||
|
#--------------------------------------
|
||||||
|
# Song name type, maybe one of the
|
||||||
|
# following values:
|
||||||
|
#
|
||||||
|
# 1: song_name.mp3
|
||||||
|
# 2: artist_name - song_name.mp3
|
||||||
|
# 3: song_name - artist_name.mp3
|
||||||
|
#--------------------------------------
|
||||||
{key_name_type} = 1
|
{key_name_type} = 1
|
||||||
|
|
||||||
|
#--------------------------------------
|
||||||
|
# Song folder type, maybe one of the
|
||||||
|
# following values:
|
||||||
|
#
|
||||||
|
# 1: download.dir
|
||||||
|
# 2: download.dir/artist_name
|
||||||
|
# 3: download.dir/artist_name/album_name
|
||||||
|
#--------------------------------------
|
||||||
{key_folder_type} = 1
|
{key_folder_type} = 1
|
||||||
'''.format(key_max=_CONFIG_KEY_DOWNLOAD_HOT_MAX,
|
'''.format(key_max=_CONFIG_KEY_DOWNLOAD_HOT_MAX,
|
||||||
|
value_max=DOWNLOAD_HOT_MAX_DEFAULT,
|
||||||
key_dir=_CONFIG_KEY_DOWNLOAD_DIR,
|
key_dir=_CONFIG_KEY_DOWNLOAD_DIR,
|
||||||
value_dir=_DEFAULT_DOWNLOAD_PATH,
|
value_dir=_DEFAULT_DOWNLOAD_PATH,
|
||||||
key_name_type=_CONFIG_KEY_SONG_NAME_TYPE,
|
key_name_type=_CONFIG_KEY_SONG_NAME_TYPE,
|
||||||
|
|
|
@ -16,7 +16,8 @@ def download_hot_songs(artist_id):
|
||||||
songs = api.get_hot_songs(artist_id)
|
songs = api.get_hot_songs(artist_id)
|
||||||
folder_name = songs[0]['artists'][0]['name'] + ' - hot50'
|
folder_name = songs[0]['artists'][0]['name'] + ' - hot50'
|
||||||
folder_path = os.path.join(config.DOWNLOAD_DIR, folder_name)
|
folder_path = os.path.join(config.DOWNLOAD_DIR, folder_name)
|
||||||
for i, song in enumerate(songs):
|
download_count = config.DOWNLOAD_HOT_MAX if (0 < config.DOWNLOAD_HOT_MAX < 50) else config.DOWNLOAD_HOT_MAX_DEFAULT
|
||||||
|
for i, song in zip(range(download_count), songs):
|
||||||
print(str(i + 1) + ' song name:' + song['name'])
|
print(str(i + 1) + ' song name:' + song['name'])
|
||||||
download_song_by_song(song, folder_path, False)
|
download_song_by_song(song, folder_path, False)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue