-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathyamusic.py
More file actions
55 lines (41 loc) · 1.35 KB
/
yamusic.py
File metadata and controls
55 lines (41 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import config
from http import client
from unicodedata import name
from yandex_music import Client
client = Client(config.YAM_TOKEN).init()
def search(query):
r = client.search(query, type_="track")
if not r.tracks:
return None
result = []
for track in r.tracks.results[0:20]:
if track.available:
name = track.title
id = f"{track.id}:{track.albums[0].id}"
artists = []
for artist in track.artists:
artists.append(artist.name)
artists = ", ".join(artists)
result.append({'artist': artists, 'caption': f"{name}", "id": id})
return result
def get_link(track_id):
track = client.tracks([track_id])
return track[0].get_download_info()[0].get_direct_link()
def get_track_data(track_id):
track = client.tracks([track_id])[0]
title = track.title
artists = []
for artist in track.artists:
artists.append(artist.name)
artists = ", ".join(artists)
link = track.get_download_info()[0].get_direct_link()
cover = track.cover_uri.replace("%%", "400x400")
# track.download(f"temp/{track_id}.mp3")
return {
"title": title,
"artists": artists,
"link": link,
"cover_url": "https://" + cover
}
if __name__ == "__main__":
print(get_link("70562908:11931354"))