1 回答
TA贡献1815条经验 获得超10个赞
我建议logindetails()返回登录会话,然后您可以将其传递给其他功能。(另一种选择是将其设为全局变量。)
我还冒昧地添加了 enumerate()用于打印曲目索引的用法。
import tidalapi
def logindetails():
"""
Ask for login details and return a logged-in session.
"""
username = input("What is your Tidal username? ")
password = input("What is your Tidal password? ")
session = tidalapi.Session()
session.login(username, password)
return session
def gettingalbum(session):
album_id = input("What is the album ID? ")
tracks = session.get_album_tracks(album_id)
print("Tracks in this album are:")
for x, track in enumerate(tracks, 1):
print(x, track.name)
session = logindetails()
gettingalbum(session)
添加回答
举报