Merge pull request #33 from kokarare1212/deepsource-transform-957c827d

Format code with yapf
This commit is contained in:
こうから 2021-05-21 12:51:55 +09:00 committed by GitHub
commit 31e0e08239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 23 deletions

View File

@ -1,13 +1,15 @@
import os
import platform
import re
import subprocess
import time
import requests
from librespot.audio.decoders import AudioQuality
from librespot.core import Session
from librespot.metadata import TrackId
from librespot.player.codecs import VorbisOnlyAudioQuality
import os
import platform
import re
import requests
import subprocess
import time
quality: AudioQuality = AudioQuality.VERY_HIGH
session: Session = None
@ -30,10 +32,16 @@ def client():
if args[0] == "exit" or args[0] == "quit":
return
if (args[0] == "p" or args[0] == "play") and len(args) == 2:
track_uri_search = re.search(r"^spotify:track:(?P<TrackID>[0-9a-zA-Z]{22})$", args[1])
track_url_search = re.search(r"^(https?://)?open.spotify.com/track/(?P<TrackID>[0-9a-zA-Z]{22})(\?si=.+?)?$", args[1])
track_uri_search = re.search(
r"^spotify:track:(?P<TrackID>[0-9a-zA-Z]{22})$", args[1])
track_url_search = re.search(
r"^(https?://)?open.spotify.com/track/(?P<TrackID>[0-9a-zA-Z]{22})(\?si=.+?)?$",
args[1],
)
if track_uri_search is not None or track_url_search is not None:
track_id_str = (track_uri_search if track_uri_search is not None else track_url_search).group("TrackID")
track_id_str = (track_uri_search
if track_uri_search is not None else
track_url_search).group("TrackID")
play(track_id_str)
wait()
if args[0] == "q" or args[0] == "quality":
@ -51,11 +59,24 @@ def client():
wait()
if (args[0] == "s" or args[0] == "search") and len(args) >= 2:
token = session.tokens().get("user-read-email")
resp = requests.get("https://api.spotify.com/v1/search", {"limit": "5", "offset": "0", "q": cmd[2:], "type": "track"}, headers={"Authorization": "Bearer %s" % token})
resp = requests.get(
"https://api.spotify.com/v1/search",
{
"limit": "5",
"offset": "0",
"q": cmd[2:],
"type": "track"
},
headers={"Authorization": "Bearer %s" % token},
)
i = 1
tracks = resp.json()["tracks"]["items"]
for track in tracks:
print("%d, %s | %s" % (i, track["name"], ",".join([artist["name"] for artist in track["artists"]])))
print("%d, %s | %s" % (
i,
track["name"],
",".join([artist["name"] for artist in track["artists"]]),
))
i += 1
position = -1
while True:
@ -92,12 +113,14 @@ def login():
def play(track_id_str: str):
track_id = TrackId.from_base62(track_id_str)
stream = session.content_feeder().load(track_id,
VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH),
False,
None)
ffplay = subprocess.Popen(["ffplay", "-"], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
stream = session.content_feeder().load(
track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None)
ffplay = subprocess.Popen(
["ffplay", "-"],
stdin=subprocess.PIPE,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
while True:
byte = stream.input_stream.stream().read()
if byte == -1:
@ -106,12 +129,11 @@ def play(track_id_str: str):
def splash():
print(
"=================================\n"
"| Librespot-Python Player |\n"
"| |\n"
"| by kokarare1212 |\n"
"=================================\n\n\n")
print("=================================\n"
"| Librespot-Python Player |\n"
"| |\n"
"| by kokarare1212 |\n"
"=================================\n\n\n")
def main():