From c172937fcba06200158cd7065a3a6d22593d75c4 Mon Sep 17 00:00:00 2001 From: aisuneko Date: Fri, 2 Jul 2021 23:23:07 +0800 Subject: [PATCH 1/2] implement custom useragent flag --- ncm/start.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ncm/start.py b/ncm/start.py index b5240e8..dc115db 100644 --- a/ncm/start.py +++ b/ncm/start.py @@ -9,10 +9,11 @@ from ncm.downloader import get_song_info_by_id from ncm.downloader import download_song_by_id from ncm.downloader import download_song_by_song from ncm.downloader import format_string +from ncm.constants import headers # load the config first config.load_config() -api = CloudApi() +#api = CloudApi() def download_hot_songs(artist_id): @@ -64,7 +65,12 @@ def main(): help='Download an album all songs by album_id') parser.add_argument('-p', metavar='playlist_id', dest='playlist_id', help='Download a playlist all songs by playlist_id') + parser.add_argument('-ua', metavar='user_agent', dest='user_agent', + help='Specify the User-Agent to be used when downloading') args = parser.parse_args() + if args.user_agent: + headers.update({'User-Agent':args.user_agent}) + #api = CloudApi() if args.song_id: download_song_by_id(get_parse_id(args.song_id), config.DOWNLOAD_DIR) elif args.song_ids: @@ -80,3 +86,4 @@ def main(): if __name__ == '__main__': main() + \ No newline at end of file From 263370524c86b046c66ba0522140d27738f8d223 Mon Sep 17 00:00:00 2001 From: aisuneko Date: Sat, 10 Jul 2021 20:43:29 +0800 Subject: [PATCH 2/2] re-add api initializing --- ncm/start.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ncm/start.py b/ncm/start.py index dc115db..f8ff485 100644 --- a/ncm/start.py +++ b/ncm/start.py @@ -13,7 +13,7 @@ from ncm.constants import headers # load the config first config.load_config() -#api = CloudApi() +api = CloudApi() def download_hot_songs(artist_id): @@ -70,7 +70,6 @@ def main(): args = parser.parse_args() if args.user_agent: headers.update({'User-Agent':args.user_agent}) - #api = CloudApi() if args.song_id: download_song_by_id(get_parse_id(args.song_id), config.DOWNLOAD_DIR) elif args.song_ids: