def main(): fail_list = [] if os.path.exists(LOVE_PLAYLIST_FILE): with open(LOVE_PLAYLIST_FILE, encoding='utf-8') as lpf: love_playlist = json.load(lpf) else: api = NetEase() user = api.login(USERNAME, md5(PASSWORD).hexdigest()) print(user) user_id = user['account']['id'] prase = Parse() ps = prase.playlists(api.user_playlist(user_id)) love_playlist_id = [m for m in ps if m['playlist_name'] == f"{m['creator_name']}喜欢的音乐"][ 0]['playlist_id'] print(love_playlist_id) love_playlist = api.playlist_detail(love_playlist_id) with open(LOVE_PLAYLIST_FILE, mode='w', encoding='utf-8') as lpf: json.dump(love_playlist, lpf) for i, d in enumerate(love_playlist): try: search_and_download_music(d['name'], d['ar'][0]['name'], d['al']['name']) print(f'{i+1}/{len(love_playlist)} {d["name"]} 下载完成') except Exception as e: fail_list.append(d["name"]) print(f'{i+1}/{len(love_playlist)} {d["name"]} 下载失败!!!!:{e}') print('-' * 20, '下载失败的歌曲', '-' * 20) print(fail_list)
def test_api(self): api = NetEase() ids = [347230, 496619464, 405998841, 28012031] print(api.songs_url(ids)) print(api.songs_detail(ids)) print(Parse.song_url(api.songs_detail(ids)[0])) # user = api.login('*****@*****.**', md5(b'').hexdigest()) # user_id = user['account']['id'] # print(user) # api.logout() # print(api.user_playlist(3765346)) # print(api.song_comments(347230)) # print(api.search('海阔天空')['result']['songs']) # print(api.top_songlist()[0]) # print(Parse.song_url(api.top_songlist()[0])) # print(api.djchannels()) # print(api.search('测', 1000)) # print(api.album(38721188)) # print(api.djchannels()[:5]) # print(api.channel_detail([348289113])) # print(api.djprograms(243, True, limit=5)) # print(api.request('POST', '/weapi/djradio/hot/v1', params=dict( # category='旅途|城市', # limit=5, # offset=0 # ))) # print(api.recommend_resource()[0]) print(api.songs_url([561307346]))
def start_download(self): check = self.download_lock.acquire(False) if not check: return False while True: if self.stop: break if not self.enable: break self.check_lock.acquire() if len(self.downloading) <= 0: self.check_lock.release() break data = self.downloading.pop() self.check_lock.release() song_id = data[0] song_name = data[1] artist = data[2] url = data[3] onExit = data[4] output_path = Constant.download_dir output_file = str(artist) + ' - ' + str(song_name) + '.mp3' full_path = os.path.join(output_path, output_file) new_url = NetEase().songs_detail_new_api([song_id])[0]['url'] log.info('Old:{}. New:{}'.format(url, new_url)) try: para = ['aria2c', '--auto-file-renaming=false', '--allow-overwrite=true', '-d', output_path, '-o', output_file, new_url] para[1:1] = self.aria2c_parameters self.aria2c = subprocess.Popen(para, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.aria2c.wait() except OSError as e: log.warning( '{}.\tAria2c is unavailable, fall back to wget'.format(e)) self._mkdir(output_path) para = ['wget', '-O', full_path, new_url] self.wget = subprocess.Popen(para, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.wget.wait() if self._is_cache_successful(): log.debug(str(song_id) + ' Cache OK') onExit(song_id, full_path) self.download_lock.release()
def test_api(self): ne = NetEase() self.assertIsInstance( ne.songs_detail_new_api([27902910])[0]['url'], str) self.assertIsNone(ne.songs_detail([405079776])[0]['mp3Url']) # old api
# -*- coding: utf-8 -*- from flask import Flask, render_template, request, abort, redirect, Response, url_for import json import requests import base64 import re from flask import stream_with_context from user_agents import parse from werkzeug.contrib.cache import SimpleCache from NEMbox.api import NetEase, geturl_new_api app = Flask(__name__) ne = NetEase() @app.route("/apcloud/") def hello(): return '''<pre>网易云音乐 APlayer 项目地址:https://github.com/vhyme/APCloud 演示效果可以看我的博客(电脑打开):https://heya.myseu.cn/ Usage: /歌单ID 显示指定歌单播放器 参数: autoplay 是否自动播放(1=true/0=false),默认是 showlrc 是否显示歌词(1=true/0=false),默认是 /歌曲ID.mp3 重定向到该歌曲直链,若有版权问题则返回空音频 /歌曲ID.lrc 下载该歌曲歌词 本播放器可以自适应窗口或iframe的高度,嵌入到iframe中不会出现
def __init__(self): self.mysession = NetEase() user = "******" pw = "19900119" pw_ = hashlib.md5(pw.encode('utf-8')).hexdigest() self.mysession.login(user, pw_)
def __init__(self): self.api = NetEase() self.storage = Storage() self.storage.load() self.collection = self.storage.database['collections'] self.autologin()
def process(local_song_path, save_path="/Users/zhangzhenhu/Music/mymusic"): global g_log_file net = NetEase() local_song = taglib.File(local_song_path) print("") print("========本地歌曲=======") # pprint.pprint(local_song.tags) if 'TITLE' not in local_song.tags or 'ARTIST' not in local_song.tags: return print(local_song.tags['TITLE'], local_song.tags['ARTIST'], local_song.tags.get('ALBUM', "")) title = local_song.tags['TITLE'][0] song_result = net.search(keywords=title, stype=1) if song_result is None or 'songs' not in song_result: print("net_song_not_found", local_song_path, file=g_log_file) return net_song = get_match_song(local_song, song_result['songs']) # pprint.pprint(net_song) if net_song is None: print("net_song_not_match", local_song_path, file=g_log_file) return print("----------网易歌曲--------") print(net_song['id'], net_song['name'], net_song['album']['name'], ','.join([x['name'] for x in net_song['artists']])) g_song_db[net_song['id']] = net_song # 歌手id,只选取第一个 artist_id = net_song['artists'][0]['id'] artist_name = net_song['artists'][0]['name'] # 获取歌手信息 artist_json = net.get_artist_desc(artist_id) # print(artist_desc) if artist_json and artist_json['code'] == 200: artist_info = artist_json['artist'] g_artist_db[artist_id] = artist_info artist_img = artist_info['img1v1Url'] artist_pic = artist_info['picUrl'] else: print("artist_not_found", local_song_path, file=g_log_file) return # 歌曲所属专辑 album_info = net_song['album'] # 包括字段 id name size artist album_name = album_info['name'] # print(album) # 获取歌曲信息 # print("========歌曲信息=======") song_info = net.songs_detail([net_song['id']])[0] album_pic = song_info['al']['picUrl'] # 专辑的图片 # print(song_lyric) # 获取专辑信息 album_tracks = net.album(album_info['id']) g_album_db[album_info['id']] = album_tracks # net_tags = { "ALBUM": album_info['name'], } if artist_info['briefDesc']: net_tags['comment'] = artist_info['briefDesc'] # 专辑发布时间 if 'publishTime' in album_info: publish_time = datetime.fromtimestamp(album_info['publishTime'] // 1000) net_tags['date'] = publish_time.strftime("%Y-%m-%d") net_tags['year'] = publish_time.strftime("%Y") album_year = publish_time.strftime("%Y") else: album_year = None # 专辑歌曲数量,以及本歌曲在第几 if len(album_tracks): net_tags['TRACKTOTAL'] = str(len(album_tracks)) track_number = get_track_number_from_album(net_song['id'], album_tracks) if track_number is not None: net_tags['TRACKNUMBER'] = str(track_number) # 获取歌词 song_lyric = net.song_lyric(net_song['id']) net_tags['Lyrics'] = '\n'.join(song_lyric), net_tags['wangyi'] = [ json.dumps({ 'song_id': net_song['id'], 'artist_id': artist_id, 'ablum_id': album_info['id'], }) ] new_artist_path = os.path.join(save_path, artist_name) if album_name is not None: new_album_path = os.path.join(new_artist_path, album_name) else: new_album_path = new_artist_path if album_year is not None: new_album_path = new_album_path # if not os.path.exists(new_album_path): os.makedirs(new_album_path, exist_ok=True) new_song_path = os.path.join(new_album_path, os.path.split(local_song_path)[-1]) # print(new_song_path) # 保存歌词 save_lrc(new_song_path, song_lyric) # 复制音频文件 if not os.path.exists(new_song_path): # copy_file(local_song_path, new_song_path) shutil.move(local_song_path, new_song_path) download_img(artist_pic, new_artist_path, 'folder') download_img(artist_pic, new_artist_path, 'fanart') download_img(album_pic, new_album_path, 'cover') save_tag(new_song_path, net_tags) # 生成nfo文件 album_nfo = { 'title': album_info['name'], 'artistdesc': artist_info['briefDesc'], 'year': album_year, 'tracks': album_tracks } save_album_nfo(new_album_path, album_nfo) # pprint.pprint(net.search(keywords="那英", stype=100)) # pprint.pprint(album_desc[0]) print("")