From d810377d9f25c64055f94eebe78e1edc2d1d8e15 Mon Sep 17 00:00:00 2001 From: codezjx Date: Wed, 5 Jul 2017 00:01:51 +0800 Subject: [PATCH] Update package name to 'ncm', and add setuptools. --- {netease => ncm}/__init__.py | 0 {netease => ncm}/api.py | 14 ++++---- {netease => ncm}/config.py | 0 {netease => ncm}/constants.py | 0 {netease => ncm}/downloader.py | 4 +-- {netease => ncm}/encrypt.py | 2 +- {netease => ncm}/file_util.py | 0 {netease => ncm}/start.py | 65 +++++++++++++++++----------------- setup.py | 24 +++++++++++++ 9 files changed, 66 insertions(+), 43 deletions(-) rename {netease => ncm}/__init__.py (100%) rename {netease => ncm}/api.py (90%) rename {netease => ncm}/config.py (100%) rename {netease => ncm}/constants.py (100%) rename {netease => ncm}/downloader.py (97%) rename {netease => ncm}/encrypt.py (95%) rename {netease => ncm}/file_util.py (100%) rename {netease => ncm}/start.py (57%) diff --git a/netease/__init__.py b/ncm/__init__.py similarity index 100% rename from netease/__init__.py rename to ncm/__init__.py diff --git a/netease/api.py b/ncm/api.py similarity index 90% rename from netease/api.py rename to ncm/api.py index d068f0d..8129ba6 100644 --- a/netease/api.py +++ b/ncm/api.py @@ -2,13 +2,13 @@ import requests -from encrypt import encrypted_request -from constants import headers -from constants import song_download_url -from constants import get_song_url -from constants import get_album_url -from constants import get_artist_url -from constants import get_playlist_url +from ncm.encrypt import encrypted_request +from ncm.constants import headers +from ncm.constants import song_download_url +from ncm.constants import get_song_url +from ncm.constants import get_album_url +from ncm.constants import get_artist_url +from ncm.constants import get_playlist_url class CloudApi(object): diff --git a/netease/config.py b/ncm/config.py similarity index 100% rename from netease/config.py rename to ncm/config.py diff --git a/netease/constants.py b/ncm/constants.py similarity index 100% rename from netease/constants.py rename to ncm/constants.py diff --git a/netease/downloader.py b/ncm/downloader.py similarity index 97% rename from netease/downloader.py rename to ncm/downloader.py index 2296758..4e8a0d8 100644 --- a/netease/downloader.py +++ b/ncm/downloader.py @@ -3,8 +3,8 @@ import os import requests -from api import CloudApi -from file_util import add_metadata_to_song +from ncm.api import CloudApi +from ncm.file_util import add_metadata_to_song def download_song_by_id(song_id, download_folder): diff --git a/netease/encrypt.py b/ncm/encrypt.py similarity index 95% rename from netease/encrypt.py rename to ncm/encrypt.py index 2f62ec9..a214e85 100644 --- a/netease/encrypt.py +++ b/ncm/encrypt.py @@ -6,7 +6,7 @@ import json import binascii from Crypto.Cipher import AES -from constants import modulus, nonce, pub_key +from ncm.constants import modulus, nonce, pub_key def encrypted_request(text): diff --git a/netease/file_util.py b/ncm/file_util.py similarity index 100% rename from netease/file_util.py rename to ncm/file_util.py diff --git a/netease/start.py b/ncm/start.py similarity index 57% rename from netease/start.py rename to ncm/start.py index 5732824..f0f33b6 100644 --- a/netease/start.py +++ b/ncm/start.py @@ -1,32 +1,14 @@ # -*- coding: utf-8 -*- import argparse import os -import config -from api import CloudApi -from downloader import download_song_by_id -from downloader import download_song_by_song +from ncm import config +from ncm.api import CloudApi +from ncm.downloader import download_song_by_id +from ncm.downloader import download_song_by_song # load the config first config.load_config() -print('max:', config.DOWNLOAD_HOT_MAX) -print('dir:', config.DOWNLOAD_DIR) -print('name_type:', config.SONG_NAME_TYPE) -print('folder_type:', config.SONG_FOLDER_TYPE) - - -parser = argparse.ArgumentParser(description='Welcome to netease cloud music downloader!') -parser.add_argument('-s', metavar='song_id', dest='song_id', - help='Download a song by song_id') -parser.add_argument('-ss', metavar='song_ids', dest='song_ids', nargs='+', - help='Download a song list, song_id split by space') -parser.add_argument('-hot', metavar='artist_id', dest='artist_id', - help='Download an artist hot 50 songs by artist_id') -parser.add_argument('-a', metavar='album_id', dest='album_id', - 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') -args = parser.parse_args() api = CloudApi() @@ -57,17 +39,34 @@ def download_playlist_songs(playlist_id): download_song_by_song(song, folder_path) -if args.song_id: - download_song_by_id(args.song_id, config.DOWNLOAD_DIR) -elif args.song_ids: - for song_id in args.song_ids: - download_song_by_id(song_id, config.DOWNLOAD_DIR) -elif args.artist_id: - download_hot_songs(args.artist_id) -elif args.album_id: - download_album_songs(args.album_id) -elif args.playlist_id: - download_playlist_songs(args.playlist_id) +def main(): + parser = argparse.ArgumentParser(description='Welcome to netease cloud music downloader!') + parser.add_argument('-s', metavar='song_id', dest='song_id', + help='Download a song by song_id') + parser.add_argument('-ss', metavar='song_ids', dest='song_ids', nargs='+', + help='Download a song list, song_id split by space') + parser.add_argument('-hot', metavar='artist_id', dest='artist_id', + help='Download an artist hot 50 songs by artist_id') + parser.add_argument('-a', metavar='album_id', dest='album_id', + 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') + args = parser.parse_args() + if args.song_id: + download_song_by_id(args.song_id, config.DOWNLOAD_DIR) + elif args.song_ids: + for song_id in args.song_ids: + download_song_by_id(song_id, config.DOWNLOAD_DIR) + elif args.artist_id: + download_hot_songs(args.artist_id) + elif args.album_id: + download_album_songs(args.album_id) + elif args.playlist_id: + download_playlist_songs(args.playlist_id) + + +if __name__ == '__main__': + main() # song = api.get_song('464035731') diff --git a/setup.py b/setup.py index 633f866..9892476 100644 --- a/setup.py +++ b/setup.py @@ -1,2 +1,26 @@ # -*- coding: utf-8 -*- +from setuptools import setup, find_packages +setup( + name='netease-cloud-music-dl', + version='0.0.1', + packages=find_packages(), + install_requires=[ + 'requests>=2.17.3', + 'pycrypto>=2.6.1', + 'mutagen>=1.38.0', + ], + + entry_points={ + 'console_scripts': [ + 'ncm = ncm.start:main', + ] + }, + + license='Apache License V2', + author='codezjx', + author_email='code.zjx@gmail.com', + url='https://github.com/codezjx/netease-cloud-music-dl', + description='Netease cloud music downloader, with full ID3 metadata!', + keywords=['ncm', 'cloud-music', 'downloader'], +) \ No newline at end of file