本文整理汇总了Python中api.NetEase.login方法的典型用法代码示例。如果您正苦于以下问题:Python NetEase.login方法的具体用法?Python NetEase.login怎么用?Python NetEase.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api.NetEase
的用法示例。
在下文中一共展示了NetEase.login方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: User
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
class User(object):
def __init__(self):
self.netease = NetEase()
self.is_login = False
self.uid = str() # ''
def login(self, username, password):
data = self.netease.login(username, password)
code = data['code']
if code is 200:
self.uid = data['profile']['userId']
self.is_login = True
return True
else: # 501
return False
def get_favorite_playlist_id(self):
"""
login required
success: return playlist id
fail: return empty string ''
"""
if self.is_login:
playlist = self.netease.user_playlist(self.uid)
for each in playlist:
if each['specialType'] is 5: # favorite playlist
return each['id'] # the favorite playlist id
return ''
return ''
def get_music_title_and_url(self, pid):
"""
:param pid: playlist id
:return re: return list re
"""
playlist = self.netease.playlist_detail(pid)
re = list()
if playlist is not []:
for music in playlist:
tmp = dict()
tmp['title'] = music['name']
tmp['url'] = music['mp3Url']
re.append(tmp)
return re
示例2: __init__
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
elif stype == 'artists':
artist_name = self.get_param('搜索艺术家:')
try:
data = netease.search(artist_name, stype=100)
if 'artists' in data['result']:
artists = data['result']['artists']
return netease.dig_info(artists, 'artists')
except:
return []
elif stype == 'albums':
artist_name = self.get_param('搜索专辑:')
try:
data = netease.search(artist_name, stype=10)
if 'albums' in data['result']:
albums = data['result']['albums']
return netease.dig_info(albums, 'albums')
except:
return []
elif stype == 'search_playlist':
artist_name = self.get_param('搜索网易精选集:')
try:
data = netease.search(artist_name, stype=1000)
if 'playlists' in data['result']:
playlists = data['result']['playlists']
return netease.dig_info(playlists, 'top_playlists')
except:
return []
return []
def build_login(self):
self.build_login_bar()
local_account = self.get_account()
local_password = hashlib.md5(self.get_password()).hexdigest()
login_info = self.netease.login(local_account, local_password)
account = [local_account,local_password]
if login_info['code'] != 200:
x = self.build_login_error()
if x == ord('1'):
return self.build_login()
else:
return -1
else:
return [login_info, account]
def build_login_bar(self):
curses.noecho()
self.screen.move(4, 1)
self.screen.clrtobot()
self.screen.addstr(5, self.startcol, '请输入登录信息(支持手机登陆)',curses.color_pair(1))
self.screen.addstr(8, self.startcol, "账号:", curses.color_pair(1))
self.screen.addstr(9, self.startcol, "密码:", curses.color_pair(1))
self.screen.move(8,24)
self.screen.refresh()
def build_login_error(self):
self.screen.move(4, 1)
self.screen.clrtobot()
self.screen.addstr(8, self.startcol, '艾玛,登录信息好像不对呢 (O_O)#', curses.color_pair(1))
self.screen.addstr(10, self.startcol, '[1] 再试一次')
self.screen.addstr(11, self.startcol, '[2] 稍后再试')
self.screen.addstr(14, self.startcol, '请键入对应数字:', curses.color_pair(2))
self.screen.refresh()
示例3: __init__
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
song_name = self.get_param('搜索歌曲:')
try:
data = netease.search(song_name, stype=1)
song_ids = []
if 'songs' in data['result']:
if 'mp3Url' in data['result']['songs']:
songs = data['result']['songs']
# if search song result do not has mp3Url
# send ids to get mp3Url
else:
for i in range(0, len(data['result']['songs']) ):
song_ids.append( data['result']['songs'][i]['id'] )
songs = netease.songs_detail(song_ids)
return netease.dig_info(songs, 'songs')
except:
return []
elif stype == 'artists':
artist_name = self.get_param('搜索艺术家:')
try:
data = netease.search(artist_name, stype=100)
if 'artists' in data['result']:
artists = data['result']['artists']
return netease.dig_info(artists, 'artists')
except:
return []
elif stype == 'albums':
artist_name = self.get_param('搜索专辑:')
try:
data = netease.search(artist_name, stype=10)
if 'albums' in data['result']:
albums = data['result']['albums']
return netease.dig_info(albums, 'albums')
except:
return []
elif stype == 'playlists':
artist_name = self.get_param('搜索网易精选集:')
try:
data = netease.search(artist_name, stype=1000)
if 'playlists' in data['result']:
playlists = data['result']['playlists']
return netease.dig_info(playlists, 'playlists')
except:
return []
return []
def build_search_menu(self):
self.screen.move(4,1)
self.screen.clrtobot()
self.screen.addstr(8, 19, '选择搜索类型:', curses.color_pair(1))
self.screen.addstr(10,19, '[1] 歌曲')
self.screen.addstr(11,19, '[2] 艺术家')
self.screen.addstr(12,19, '[3] 专辑')
self.screen.addstr(13,19, '[4] 网易精选集')
self.screen.addstr(16,19, '请键入对应数字:', curses.color_pair(2))
self.screen.refresh()
x = self.screen.getch()
return x
def build_login(self):
info = self.get_param('请输入登录信息, e.g: [email protected] 123456')
account = info.split(' ')
if len(account) != 2:
return self.build_login()
login_info = self.netease.login(account[0], account[1])
if login_info['code'] != 200:
x = self.build_login_error()
if x == ord('1'):
return self.build_login()
else:
return -1
else:
return [login_info, account]
def build_login_error(self):
self.screen.move(4,1)
self.screen.clrtobot()
self.screen.addstr(8, 19, '艾玛,登录信息好像不对呢 (O_O)#', curses.color_pair(1))
self.screen.addstr(10,19, '[1] 再试一次')
self.screen.addstr(11,19, '[2] 稍后再试')
self.screen.addstr(14,19, '请键入对应数字:', curses.color_pair(2))
self.screen.refresh()
x = self.screen.getch()
return x
def get_param(self, prompt_string):
# keep playing info in line 1
self.screen.move(4,1)
self.screen.clrtobot()
self.screen.addstr(5, 19, prompt_string, curses.color_pair(1))
self.screen.refresh()
info = self.screen.getstr(10, 19, 60)
if info.strip() is '':
return self.get_param(prompt_string)
else:
return info
示例4: Ui
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
log.error(e)
return []
elif stype == 'albums':
albums_name = self.get_param('Search Albums :')
if albums_name == '/return':
return []
else:
try:
data = netease.search(albums_name, stype=10)
if 'albums' in data['result']:
albums = data['result']['albums']
return netease.dig_info(albums, 'albums')
except Exception as e:
log.error(e)
return []
elif stype == 'search_playlist':
search_playlist = self.get_param('Search Playlists :')
if search_playlist == '/return':
return []
else:
try:
data = netease.search(search_playlist, stype=1000)
if 'playlists' in data['result']:
playlists = data['result']['playlists']
return netease.dig_info(playlists, 'top_playlists')
except Exception as e:
log.error(e)
return []
return []
def build_login(self):
self.build_login_bar()
local_account = self.get_account()
local_password = hashlib.md5(self.get_password()).hexdigest()
login_info = self.netease.login(local_account, local_password)
account = [local_account, local_password]
if login_info['code'] != 200:
x = self.build_login_error()
if x == ord('1'):
return self.build_login()
else:
return -1
else:
return [login_info, account]
def build_login_bar(self):
curses.noecho()
self.screen.move(4, 1)
self.screen.clrtobot()
self.screen.addstr(5, self.startcol, 'Enter your login information(支持手机登陆)',
curses.color_pair(1))
self.screen.addstr(8, self.startcol, 'Username :', curses.color_pair(1))
self.screen.addstr(9, self.startcol, 'Password :', curses.color_pair(1))
self.screen.move(8, 24)
self.screen.refresh()
def build_login_error(self):
self.screen.move(4, 1)
self.screen.timeout(-1) # disable the screen timeout
self.screen.clrtobot()
self.screen.addstr(8, self.startcol, 'Sorry, the login information was invalid (O_O)#',
curses.color_pair(1))
self.screen.addstr(10, self.startcol, '[1] Try Again')
示例5: __init__
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
artists = data['result']['artists']
return netease.dig_info(artists, 'artists')
except:
return []
elif stype == 'albums':
albums_name = self.get_param('搜索专辑:')
if albums_name == '/return':
return []
else:
try:
data = netease.search(albums_name, stype=10)
if 'albums' in data['result']:
albums = data['result']['albums']
return netease.dig_info(albums, 'albums')
except:
return []
elif stype == 'search_playlist':
search_playlist = self.get_param('搜索网易精选集:')
if search_playlist == '/return':
return []
else:
try:
data = netease.search(search_playlist, stype=1000)
if 'playlists' in data['result']:
playlists = data['result']['playlists']
return netease.dig_info(playlists, 'top_playlists')
except:
return []
return []
def build_login(self):
self.build_login_bar()
local_account = self.get_account()
local_password = hashlib.md5(self.get_password()).hexdigest()
login_info = self.netease.login(local_account, local_password)
account = [local_account, local_password]
if login_info['code'] != 200:
x = self.build_login_error()
if x == ord('1'):
return self.build_login()
else:
return -1
else:
return [login_info, account]
def build_login_bar(self):
curses.noecho()
self.screen.move(4, 1)
self.screen.clrtobot()
self.screen.addstr(5, self.startcol, '请输入登录信息(支持手机登陆)', curses.color_pair(1))
self.screen.addstr(8, self.startcol, "账号:", curses.color_pair(1))
self.screen.addstr(9, self.startcol, "密码:", curses.color_pair(1))
self.screen.move(8, 24)
self.screen.refresh()
def build_login_error(self):
self.screen.move(4, 1)
self.screen.timeout(-1) # disable the screen timeout
self.screen.clrtobot()
self.screen.addstr(8, self.startcol, '艾玛,登录信息好像不对呢 (O_O)#', curses.color_pair(1))
self.screen.addstr(10, self.startcol, '[1] 再试一次')
self.screen.addstr(11, self.startcol, '[2] 稍后再试')
self.screen.addstr(14, self.startcol, '请键入对应数字:', curses.color_pair(2))
示例6: __init__
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
else:
self.player.end_callback = None
self.storage.database['player_info']['idx'] = -1
self.player.play_and_pause(self.index)
self.resume_play = False
def song_changed_callback(self):
if self.at_playing_list:
self.show_playing_song()
def fm_callback(self):
log.debug("FM CallBack.")
data = self.get_new_fm()
self.player.append_songs(data)
if self.datatype == 'fmsongs':
if len(self.storage.database['player_info']['player_list']) == 0:
return
self.datatype = self.storage.database['player_info']['player_list_type']
self.title = self.storage.database['player_info']['player_list_title']
self.datalist = []
for i in self.storage.database['player_info']['player_list']:
self.datalist.append(self.storage.database['songs'][i])
self.index = self.storage.database['player_info']['idx']
self.offset = self.storage.database['player_info']['idx'] / self.step * self.step
def request_api(self, func, *args):
if self.storage.database['user']['user_id'] != "":
result = func(*args)
if result != -1:
return result
log.debug("Re Login.")
user_info = {}
if self.storage.database['user']['username'] != "":
user_info = self.netease.login(self.storage.database['user']['username'],
self.storage.database['user']['password'])
if self.storage.database['user']['username'] == "" or user_info['code'] != 200:
data = self.ui.build_login()
# 取消登录
if data == -1:
return -1
user_info = data[0]
self.storage.database['user']['username'] = data[1][0]
self.storage.database['user']['password'] = data[1][1]
self.storage.database['user']['user_id'] = user_info['account']['id']
self.storage.database['user']['nickname'] = user_info['profile']['nickname']
self.userid = self.storage.database["user"]["user_id"]
self.username = self.storage.database["user"]["nickname"]
return func(*args)
def get_new_fm(self):
myplaylist = []
for count in range(0, 1):
data = self.request_api(self.netease.personal_fm)
if data == -1:
break
myplaylist += data
time.sleep(0.2)
return self.netease.dig_info(myplaylist, "fmsongs")
def choice_channel(self, idx):
# 排行榜
netease = self.netease
if idx == 0:
self.datalist = netease.return_toplists()
self.title += ' > 排行榜'
self.datatype = 'toplists'
示例7: LoginDialog
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
class LoginDialog(QDialog):
"""登录对话框
描述: 弹出登录对话框,用户输入用户名和密码,点击登录按钮调用login函数。
登录成功则发射("loginsuccess")信号,失败则显示相关提示信息
调用: 1. 在用户登录成功时,会发射("loginsuccess")信号
"""
def __init__(self, parent=None):
super(LoginDialog, self).__init__(parent)
self.username_lable = QLabel()
self.password_lable = QLabel()
self.hint_label = QLabel()
self.username_widget = QLineEdit()
self.password_widget = QLineEdit()
self.login_btn = QPushButton()
self.layout = QVBoxLayout()
self.ne = NetEase()
self.__set_signal_binding()
self.__set_widgets_prop()
self.__set_layouts_prop()
self.__set_me()
def __set_signal_binding(self):
self.login_btn.clicked.connect(self.__login)
def __login(self):
"""登录
在用户登录成功时,会发射("loginsuccess")信号
"""
phone_login = False # 0: 网易通行证, 1: 手机号登陆
username = str(self.username_widget.text()) # 包含中文会出错
password = str(self.password_widget.text())
# judget if logining by using phone number
try:
int(username)
phone_login = True
except ValueError:
pass
data = self.ne.login(username, password, phone_login)
# judge if __login successfully
# if not, why
print data['code'], type(data['code'])
if data['code'] == 200:
self.hint_label.setText(u'登陆成功')
self.emit(SIGNAL('loginsuccess'), data)
self.close()
elif data['code'] == 408:
self.hint_label.setText(u'网络连接超时')
elif data['code'] == 501:
self.hint_label.setText(u'用户名错误')
elif data['code'] == 502:
self.hint_label.setText(u'密码错误')
else:
self.hint_label.setText(u'未知错误')
def __set_me(self):
self.setObjectName('login_dialog')
self.setLayout(self.layout)
def __set_widgets_prop(self):
self.login_btn.setText(u'登陆')
self.username_lable.setText(u'网易邮箱或者手机号')
self.password_lable.setText(u'密码')
self.username_widget.setPlaceholderText(u'请输入用户名')
self.password_widget.setPlaceholderText(u'请输入密码')
self.password_widget.setEchoMode(QLineEdit.Password)
def __set_layouts_prop(self):
self.layout.addWidget(self.username_lable)
self.layout.addWidget(self.username_widget)
self.layout.addWidget(self.password_lable)
self.layout.addWidget(self.password_widget)
self.layout.addWidget(self.hint_label)
self.layout.addWidget(self.login_btn)
self.layout.addStretch(1)
示例8: __init__
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
else:
self.player.end_callback = None
self.storage.database["player_info"]["idx"] = -1
self.player.play_and_pause(self.index)
self.resume_play = False
def song_changed_callback(self):
if self.at_playing_list:
self.show_playing_song()
def fm_callback(self):
log.debug("FM CallBack.")
data = self.get_new_fm()
self.player.append_songs(data)
if self.datatype == "fmsongs":
if len(self.storage.database["player_info"]["player_list"]) == 0:
return
self.datatype = self.storage.database["player_info"]["player_list_type"]
self.title = self.storage.database["player_info"]["player_list_title"]
self.datalist = []
for i in self.storage.database["player_info"]["player_list"]:
self.datalist.append(self.storage.database["songs"][i])
self.index = self.storage.database["player_info"]["idx"]
self.offset = self.storage.database["player_info"]["idx"] / self.step * self.step
def request_api(self, func, *args):
if self.storage.database["user"]["user_id"] != "":
result = func(*args)
if result != -1:
return result
log.debug("Re Login.")
user_info = {}
if self.storage.database["user"]["username"] != "":
user_info = self.netease.login(
self.storage.database["user"]["username"], self.storage.database["user"]["password"]
)
if self.storage.database["user"]["username"] == "" or user_info["code"] != 200:
data = self.ui.build_login()
# 取消登录
if data == -1:
return -1
user_info = data[0]
self.storage.database["user"]["username"] = data[1][0]
self.storage.database["user"]["password"] = data[1][1]
self.storage.database["user"]["user_id"] = user_info["account"]["id"]
self.storage.database["user"]["nickname"] = user_info["profile"]["nickname"]
self.userid = self.storage.database["user"]["user_id"]
self.username = self.storage.database["user"]["nickname"]
return func(*args)
def get_new_fm(self):
myplaylist = []
for count in range(0, 1):
data = self.request_api(self.netease.personal_fm)
if data == -1:
break
myplaylist += data
time.sleep(0.2)
return self.netease.dig_info(myplaylist, "fmsongs")
def choice_channel(self, idx):
# 排行榜
netease = self.netease
if idx == 0:
self.datalist = netease.return_toplists()
self.title += " > 排行榜"
示例9: __init__
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
data = netease.search(artist_name, stype=10)
if 'albums' in data['result']:
albums = data['result']['albums']
return netease.dig_info(albums, 'albums')
except:
return []
elif stype == 'search_playlist':
artist_name = self.get_param('搜索网易精选集:')
try:
data = netease.search(artist_name, stype=1000)
if 'playlists' in data['result']:
playlists = data['result']['playlists']
return netease.dig_info(playlists, 'top_playlists')
except:
return []
return []
def build_search_menu(self):
self.screen.move(4, 1)
self.screen.clrtobot()
self.screen.addstr(8, 19, '选择搜索类型:', curses.color_pair(1))
self.screen.addstr(10, 19, '[1] 歌曲')
self.screen.addstr(11, 19, '[2] 艺术家')
self.screen.addstr(12, 19, '[3] 专辑')
self.screen.addstr(13, 19, '[4] 网易精选集')
self.screen.addstr(16, 19, '请键入对应数字:', curses.color_pair(2))
self.screen.refresh()
x = self.screen.getch()
return x
# build login interface and login
def build_login(self):
curses.noecho()
info = self.get_param('请输入登录信息, e.g: [email protected] 123456')
account = info.split(' ')
# if both user-name and password is got.
if len(account) != 2:
return self.build_login()
# login
login_info = self.netease.login(account[0], account[1])
self.screen.refresh()
# if login successfully
if login_info['code'] != 200:
x = self.build_login_error()
if x == ord('1'):
return self.build_login()
else:
return -1
else:
return [login_info, account]
def build_login_error(self):
self.screen.move(4, 1)
self.screen.clrtobot()
self.screen.addstr(8, 19, '艾玛,登录信息好像不对呢 (O_O)#', curses.color_pair(1))
self.screen.addstr(10, 19, '[1] 再试一次')
self.screen.addstr(11, 19, '[2] 稍后再试')
self.screen.addstr(14, 19, '请键入对应数字:', curses.color_pair(2))
self.screen.refresh()
x = self.screen.getch()
return x
def get_param(self, prompt_string):
示例10: __init__
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
self.datalist = ui.build_search('songs')
self.title = '歌曲搜索列表'
elif idx == 2:
self.datatype = 'artists'
self.datalist = ui.build_search('artists')
self.title = '艺术家搜索列表'
elif idx == 3:
self.datatype = 'albums'
self.datalist = ui.build_search('albums')
self.title = '专辑搜索列表'
def fm_callback(self):
log.debug("FM CallBack.")
data = self.get_new_fm()
self.player.append_songs(data)
if self.datatype == 'fmsongs':
if len(self.storage.database['player_info']['player_list']) == 0:
return
self.datatype = self.storage.database['player_info']['player_list_type']
self.title = self.storage.database['player_info']['player_list_title']
self.datalist = []
for i in self.storage.database['player_info']['player_list']:
self.datalist.append(self.storage.database['songs'][i])
self.index = self.storage.database['player_info']['idx']
self.offset = self.storage.database['player_info']['idx'] / self.step * self.step
def get_new_fm(self):
if self.userid is None:
if self.storage.database['user']['user_id'] == "":
# 使用本地存储了账户登录
if self.storage.database['user']['username'] != "":
user_info = self.netease.login(self.storage.database['user']['username'],
self.storage.database['user']['password'])
# 本地没有存储账户,或本地账户失效,则引导录入
if self.storage.database['user']['username'] == "" or user_info['code'] != 200:
data = self.ui.build_login()
# 取消登录
if data == -1:
return
user_info = data[0]
self.storage.database['user']['username'] = data[1][0]
self.storage.database['user']['password'] = data[1][1]
self.storage.database['user']['user_id'] = user_info['account']['id']
self.storage.database['user']['nickname'] = user_info['profile']['nickname']
self.username = user_info['profile']['nickname']
self.userid = user_info['account']['id']
else:
self.userid = self.storage.database['user']['user_id']
myplaylist = []
for count in range(0, 1):
myplaylist += self.netease.personal_fm()
time.sleep(0.2)
return self.netease.dig_info(myplaylist, "fmsongs")
def choice_channel(self, idx):
# 排行榜
netease = self.netease
if idx == 0:
self.datalist = netease.return_toplists()
self.title += ' > 排行榜'
self.datatype = 'toplists'
# 艺术家
示例11: Menu
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
self.player.play_and_pause(self.index)
self.resume_play = False
def song_changed_callback(self):
if self.at_playing_list:
self.show_playing_song()
def fm_callback(self):
log.debug('FM CallBack.')
data = self.get_new_fm()
self.player.append_songs(data)
if self.datatype == 'fmsongs':
if self._is_playlist_empty():
return
self.datatype = self.storage.database['player_info'][
'player_list_type']
self.title = self.storage.database['player_info'][
'player_list_title']
self.datalist = []
for i in self.storage.database['player_info']['player_list']:
self.datalist.append(self.storage.database['songs'][i])
self.index = self.storage.database['player_info']['idx']
self.offset = self.storage.database['player_info'][
'idx'] / self.step * self.step
def request_api(self, func, *args):
if self.storage.database['user']['user_id'] != '':
result = func(*args)
if result != -1:
return result
log.debug('Re Login.')
user_info = {}
if self.storage.database['user']['username'] != '':
user_info = self.netease.login(
self.storage.database['user']['username'],
self.storage.database['user']['password'])
if self.storage.database['user']['username'] == '' or user_info[
'code'] != 200:
data = self.ui.build_login()
# 取消登录
if data == -1:
return -1
user_info = data[0]
self.storage.database['user']['username'] = data[1][0]
self.storage.database['user']['password'] = data[1][1]
self.storage.database['user']['user_id'] = user_info['account'][
'id']
self.storage.database['user']['nickname'] = user_info['profile'][
'nickname']
self.userid = self.storage.database['user']['user_id']
self.username = self.storage.database['user']['nickname']
return func(*args)
def get_new_fm(self):
myplaylist = []
for count in range(0, 1):
data = self.request_api(self.netease.personal_fm)
if data == -1:
break
myplaylist += data
time.sleep(0.2)
return self.netease.dig_info(myplaylist, 'fmsongs')
def choice_channel(self, idx):
# 排行榜
netease = self.netease
示例12: __init__
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
return []
elif stype == 'albums':
artist_name = self.get_param('搜索专辑:')
try:
data = netease.search(artist_name, stype=10)
if 'albums' in data['result']:
albums = data['result']['albums']
return netease.dig_info(albums, 'albums')
except:
return []
elif stype == 'search_playlist':
artist_name = self.get_param('搜索网易精选集:')
try:
data = netease.search(artist_name, stype=1000)
if 'playlists' in data['result']:
playlists = data['result']['playlists']
return netease.dig_info(playlists, 'top_playlists')
except:
return []
return []
def build_search_menu(self):
self.screen.move(4+self.show_begin_line,1)
self.screen.clrtobot()
self.screen.addstr(8+self.show_begin_line, 19, '选择搜索类型:', curses.color_pair(1))
self.screen.addstr(10+self.show_begin_line,19, '[1] 歌曲')
self.screen.addstr(11+self.show_begin_line,19, '[2] 艺术家')
self.screen.addstr(12+self.show_begin_line,19, '[3] 专辑')
self.screen.addstr(13+self.show_begin_line,19, '[4] 网易精选集')
self.screen.addstr(16+self.show_begin_line,19, '请键入对应数字:', curses.color_pair(2))
self.screen.refresh()
x = self.screen.getch()
return x
def build_login(self):
self.screen.move(7+self.show_begin_line,1)
self.screen.clrtobot()
curses.noecho()
info = self.get_param('请输入登录信息(q or Q 退出登陆), e.g: [email protected] 123456')
if str(info) in ('q','Q'):
return -1
account = info.split(' ')
if len(account) != 2:
return self.build_login()
login_info = self.netease.login(account[0], account[1])
if login_info['code'] != 200:
x = self.build_login_error()
if x == ord('1'):
return self.build_login()
else:
return -1
else:
return [login_info, account]
def build_login_error(self):
self.screen.move(4+self.show_begin_line,1)
self.screen.clrtobot()
self.screen.addstr(8+self.show_begin_line, 19, '艾玛,登录信息好像不对呢 (O_O)#', curses.color_pair(1))
self.screen.addstr(10+self.show_begin_line,19, '[1] 再试一次')
self.screen.addstr(11+self.show_begin_line,19, '[2] 稍后再试')
self.screen.addstr(14+self.show_begin_line,19, '请键入对应数字:', curses.color_pair(2))
self.screen.refresh()
x = self.screen.getch()
return x
def get_param(self, prompt_string):
# keep playing info in line 1
curses.echo()
self.screen.move(4+self.show_begin_line,1)
self.screen.clrtobot()
self.screen.addstr(5+self.show_begin_line, 3, prompt_string, curses.color_pair(1))
self.screen.refresh()
info = self.screen.getstr(10, 19, 60)
if info.strip() is '':
return self.get_param(prompt_string)
else:
return info
def progress_bar(self,time_now,length): #进度条
cols=int(self.COLS)-18
time_now=int(ceil(float(time_now)))
length=int(ceil(float(length)))
if time_now>length:
time_now=length
surplus=length-time_now
if length!=0 and length!=0:
t_now="%2d:%02d" % (int(time_now//60),int(time_now%60))
t_surplus="%2d:%02d" % (int(surplus//60),int(surplus%60))
dutyfactor_1=int(ceil(float(time_now)/length*cols))
line=t_now+' '+'*'*dutyfactor_1+'>'+'-'*(cols-dutyfactor_1)+' '+t_surplus
self.screen.addstr(20+self.show_begin_line,2,line,curses.color_pair(3))
self.screen.refresh()
def notifySend(self,name,artist,other=''): #发送桌面通知
s=other+name+' -- <'+artist+'>'
subprocess.call(['notify-send',s])
示例13: __init__
# 需要导入模块: from api import NetEase [as 别名]
# 或者: from api.NetEase import login [as 别名]
#.........这里部分代码省略.........
try:
data = netease.search(song_name, stype=1)
song_ids = []
if 'songs' in data['result']:
if 'mp3Url' in data['result']['songs']:
songs = data['result']['songs']
# if search song result do not has mp3Url
# send ids to get mp3Url
else:
for i in range(0, len(data['result']['songs'])):
song_ids.append(data['result']['songs'][i]['id'])
songs = netease.songs_detail(song_ids)
return netease.dig_info(songs, 'songs')
except:
return []
elif stype == 'artists':
artist_name = self.get_param('Search by Artists:')
try:
data = netease.search(artist_name, stype=100)
if 'artists' in data['result']:
artists = data['result']['artists']
return netease.dig_info(artists, 'artists')
except:
return []
elif stype == 'albums':
artist_name = self.get_param('Search by Artists:')
try:
data = netease.search(artist_name, stype=10)
if 'albums' in data['result']:
albums = data['result']['albums']
return netease.dig_info(albums, 'albums')
except:
return []
elif stype == 'playlists':
artist_name = self.get_param('Search by Playlists:')
try:
data = netease.search(artist_name, stype=1000)
if 'playlists' in data['result']:
playlists = data['result']['playlists']
return netease.dig_info(playlists, 'playlists')
except:
return []
return []
def build_search_menu(self):
self.screen.move(4, 1)
self.screen.clrtobot()
self.screen.addstr(8, 19, 'Search Type:', curses.color_pair(1))
self.screen.addstr(10, 19, '[1] Songs')
self.screen.addstr(11, 19, '[2] Artists')
self.screen.addstr(12, 19, '[3] Albums')
self.screen.addstr(13, 19, '[4] Playist')
self.screen.addstr(16, 19, 'Please input the option:', curses.color_pair(2))
self.screen.refresh()
x = self.screen.getch()
return x
def build_login(self):
info = self.get_param('Log In, e.g: [email protected] 123456')
account = info.split(' ')
if len(account) != 2:
return self.build_login()
login_info = self.netease.login(account[0], account[1])
if login_info['code'] != 200:
x = self.build_login_error()
if x == ord('1'):
return self.build_login()
else:
return -1
else:
return [login_info, account]
def build_login_error(self):
self.screen.move(4, 1)
self.screen.clrtobot()
self.screen.addstr(8, 19, 'Something wrong(O_O)#', curses.color_pair(1))
self.screen.addstr(10, 19, '[1] Try Again')
self.screen.addstr(11, 19, '[2] Later')
self.screen.addstr(14, 19, 'Please input the option', curses.color_pair(2))
self.screen.refresh()
x = self.screen.getch()
return x
def get_param(self, prompt_string):
# keep playing info in line 1
self.screen.move(4, 1)
self.screen.clrtobot()
self.screen.addstr(5, 19, prompt_string, curses.color_pair(1))
self.screen.refresh()
info = self.screen.getstr(10, 19, 60)
if info.strip() is '':
return self.get_param(prompt_string)
else:
return info