Merge pull request #31 from kokarare1212/restyled/deepsource-transform-c10e84f1
Restyle Format code with yapf
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
from librespot.audio.decoders import AudioQuality
|
from librespot.audio.decoders import AudioQuality
|
||||||
from librespot.core import Session
|
from librespot.core import Session
|
||||||
from librespot.metadata import TrackId
|
from librespot.metadata import TrackId
|
||||||
from librespot.player.codecs import VorbisOnlyAudioQuality
|
from librespot.player.codecs import VorbisOnlyAudioQuality
|
||||||
import os
|
|
||||||
import platform
|
|
||||||
import re
|
|
||||||
import requests
|
|
||||||
import subprocess
|
|
||||||
import time
|
|
||||||
|
|
||||||
quality: AudioQuality = AudioQuality.VERY_HIGH
|
quality: AudioQuality = AudioQuality.VERY_HIGH
|
||||||
session: Session = None
|
session: Session = None
|
||||||
@@ -34,7 +36,8 @@ def client():
|
|||||||
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_uri_search
|
track_id_str = (track_uri_search
|
||||||
if track_uri_search is not None else
|
if track_uri_search is not None else
|
||||||
@@ -56,18 +59,24 @@ def client():
|
|||||||
wait()
|
wait()
|
||||||
if (args[0] == "s" or args[0] == "search") and len(args) >= 2:
|
if (args[0] == "s" or args[0] == "search") and len(args) >= 2:
|
||||||
token = session.tokens().get("user-read-email")
|
token = session.tokens().get("user-read-email")
|
||||||
resp = requests.get("https://api.spotify.com/v1/search", {
|
resp = requests.get(
|
||||||
"limit": "5",
|
"https://api.spotify.com/v1/search",
|
||||||
"offset": "0",
|
{
|
||||||
"q": cmd[2:],
|
"limit": "5",
|
||||||
"type": "track"
|
"offset": "0",
|
||||||
},
|
"q": cmd[2:],
|
||||||
headers={"Authorization": "Bearer %s" % token})
|
"type": "track"
|
||||||
|
},
|
||||||
|
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("%d, %s | %s" % (i, track["name"], ",".join(
|
print("%d, %s | %s" % (
|
||||||
[artist["name"] for artist in track["artists"]])))
|
i,
|
||||||
|
track["name"],
|
||||||
|
",".join([artist["name"] for artist in track["artists"]]),
|
||||||
|
))
|
||||||
i += 1
|
i += 1
|
||||||
position = -1
|
position = -1
|
||||||
while True:
|
while True:
|
||||||
@@ -106,10 +115,12 @@ 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", "-"],
|
ffplay = subprocess.Popen(
|
||||||
stdin=subprocess.PIPE,
|
["ffplay", "-"],
|
||||||
stdout=subprocess.DEVNULL,
|
stdin=subprocess.PIPE,
|
||||||
stderr=subprocess.DEVNULL)
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
while True:
|
while True:
|
||||||
byte = stream.input_stream.stream().read()
|
byte = stream.input_stream.stream().read()
|
||||||
if byte == -1:
|
if byte == -1:
|
||||||
|
|||||||
Reference in New Issue
Block a user