Restyled by yapf
This commit is contained in:
parent
fbad354052
commit
b20b09938b
|
@ -33,18 +33,15 @@ def client():
|
||||||
return
|
return
|
||||||
if (args[0] == "p" or args[0] == "play") and len(args) == 2:
|
if (args[0] == "p" or args[0] == "play") and len(args) == 2:
|
||||||
track_uri_search = re.search(
|
track_uri_search = re.search(
|
||||||
r"^spotify:track:(?P<TrackID>[0-9a-zA-Z]{22})$", args[1]
|
r"^spotify:track:(?P<TrackID>[0-9a-zA-Z]{22})$", args[1])
|
||||||
)
|
|
||||||
track_url_search = re.search(
|
track_url_search = re.search(
|
||||||
r"^(https?://)?open.spotify.com/track/(?P<TrackID>[0-9a-zA-Z]{22})(\?si=.+?)?$",
|
r"^(https?://)?open.spotify.com/track/(?P<TrackID>[0-9a-zA-Z]{22})(\?si=.+?)?$",
|
||||||
args[1],
|
args[1],
|
||||||
)
|
)
|
||||||
if track_uri_search is not None or track_url_search is not None:
|
if track_uri_search is not None or track_url_search is not None:
|
||||||
track_id_str = (
|
track_id_str = (track_uri_search
|
||||||
track_uri_search
|
if track_uri_search is not None else
|
||||||
if track_uri_search is not None
|
track_url_search).group("TrackID")
|
||||||
else track_url_search
|
|
||||||
).group("TrackID")
|
|
||||||
play(track_id_str)
|
play(track_id_str)
|
||||||
wait()
|
wait()
|
||||||
if args[0] == "q" or args[0] == "quality":
|
if args[0] == "q" or args[0] == "quality":
|
||||||
|
@ -64,20 +61,22 @@ def client():
|
||||||
token = session.tokens().get("user-read-email")
|
token = session.tokens().get("user-read-email")
|
||||||
resp = requests.get(
|
resp = requests.get(
|
||||||
"https://api.spotify.com/v1/search",
|
"https://api.spotify.com/v1/search",
|
||||||
{"limit": "5", "offset": "0", "q": cmd[2:], "type": "track"},
|
{
|
||||||
|
"limit": "5",
|
||||||
|
"offset": "0",
|
||||||
|
"q": cmd[2:],
|
||||||
|
"type": "track"
|
||||||
|
},
|
||||||
headers={"Authorization": "Bearer %s" % token},
|
headers={"Authorization": "Bearer %s" % token},
|
||||||
)
|
)
|
||||||
i = 1
|
i = 1
|
||||||
tracks = resp.json()["tracks"]["items"]
|
tracks = resp.json()["tracks"]["items"]
|
||||||
for track in tracks:
|
for track in tracks:
|
||||||
print(
|
print("%d, %s | %s" % (
|
||||||
"%d, %s | %s"
|
i,
|
||||||
% (
|
track["name"],
|
||||||
i,
|
",".join([artist["name"] for artist in track["artists"]]),
|
||||||
track["name"],
|
))
|
||||||
",".join([artist["name"] for artist in track["artists"]]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
i += 1
|
i += 1
|
||||||
position = -1
|
position = -1
|
||||||
while True:
|
while True:
|
||||||
|
@ -115,8 +114,7 @@ def login():
|
||||||
def play(track_id_str: str):
|
def play(track_id_str: str):
|
||||||
track_id = TrackId.from_base62(track_id_str)
|
track_id = TrackId.from_base62(track_id_str)
|
||||||
stream = session.content_feeder().load(
|
stream = session.content_feeder().load(
|
||||||
track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None
|
track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None)
|
||||||
)
|
|
||||||
ffplay = subprocess.Popen(
|
ffplay = subprocess.Popen(
|
||||||
["ffplay", "-"],
|
["ffplay", "-"],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
|
@ -131,13 +129,11 @@ def play(track_id_str: str):
|
||||||
|
|
||||||
|
|
||||||
def splash():
|
def splash():
|
||||||
print(
|
print("=================================\n"
|
||||||
"=================================\n"
|
"| Librespot-Python Player |\n"
|
||||||
"| Librespot-Python Player |\n"
|
"| |\n"
|
||||||
"| |\n"
|
"| by kokarare1212 |\n"
|
||||||
"| by kokarare1212 |\n"
|
"=================================\n\n\n")
|
||||||
"=================================\n\n\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in New Issue