-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (47 loc) · 1.6 KB
/
main.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python3
import tidalapi
from getpass import getpass as getpass
from sys import exit
from multiprocessing import Process, Queue
from os import system as system
def login(session: tidalapi.Session):
try:
session.login(input("Username: "), getpass())
except:
print("password or username is incorrect",end="")
print(" try again")
login(session)
def query(session: tidalapi.Session) -> tidalapi.models.SearchResult:
out = input("Search for a track by name: ")
if out.lower() == "quit":
exit(0)
search_result = session.search('track', out)
return search_result
def print_result(search_result: tidalapi.models.SearchResult):
i = 1
for track in search_result.tracks:
print(str(i)+" Artist: "+track.artist.name)
print(str(i)+" Album: " +track.album.name)
print(str(i)+" track: " +track.name)
i+=1
def server(RTMP: Queue):
while True:
system("ffplay -bufsize 160000 -nodisp -loglevel quiet -autoexit \""+RTMP.get()+"\"")
def main():
session = tidalapi.Session()
login(session)
track_queue = Queue()
print("enter number based off of wanted track ",end="")
print("append A if you want to append to end of ",end="")
print("playlist, or P to play single time")
if __name__ == '__main__':
p = Process(target=server,args=(track_queue,))
p.start()
while True:
search_result = query(session)
print_result(search_result)
selection = input("Selection requested")
selection = selection.lower().strip("abcdefghijklmnopqrstuvwxyz.,;'[] ")
num = int(selection) - 1
track_queue.put("rtmp://"+session.get_media_url(search_result.tracks[num].id))
main()