Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F186381
get_track_info.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
get_track_info.py
View Options
#!/usr/bin/env python3
import
sys
import
json
import
tekore
as
tk
import
libmusicleague
import
pyml_config
as
config
# Set up Spotify connection using client token
conf
=
(
config
.
client_id
,
config
.
client_secret
)
token
=
tk
.
request_client_token
(
*
conf
)
spotify
=
tk
.
Spotify
(
token
)
# Get track ID from first argument
trackarg
=
sys
.
argv
[
1
]
print
(
trackarg
)
# Determine the type of whatever was
t
=
libmusicleague
.
ur_type
(
trackarg
)
try
:
match
t
:
case
"uri"
:
track
=
spotify
.
track
(
trackarg
)
case
"url"
:
track
=
spotify
.
track
(
tk
.
from_url
(
trackarg
)[
1
])
case
"new"
:
n
=
libmusicleague
.
newurl_expand
(
trackarg
)
track
=
spotify
.
track
(
tk
.
from_url
(
n
))
case
_
:
sys
.
exit
(
"Not a valid Spotify URL or URI?"
)
except
Exception
as
e
:
print
(
"Something unexpected went wrong, check that you're using a valid Spotify link? Detailed error message follows in case that's not the and you need to bug Keith to fix something:"
)
print
(
e
)
#trackid = tk.from_url(trackarg)[1]
#track = spotify.track(trackid)
#print(track.asbuiltin())
json_object
=
json
.
loads
(
track
.
json
())
#json_pretty = json.dumps(json_object, indent="\t", separators=(',', ':'))
json_pretty
=
json
.
dumps
(
json_object
,
cls
=
libmusicleague
.
CompactJSONEncoder
)
# json_pretty = json.dumps(json_object, indent=0)
print
(
json_pretty
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Fri, Jan 24, 4:15 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
131198
Default Alt Text
get_track_info.py (1 KB)
Attached To
Mode
rPYMUSICLEAGUE PyMusicLeague
Attached
Detach File
Event Timeline
Log In to Comment