This repository was archived by the owner on Apr 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplayify-transfer.py
More file actions
100 lines (90 loc) · 2.38 KB
/
playify-transfer.py
File metadata and controls
100 lines (90 loc) · 2.38 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import json
import os.path
import sys
# thanks to these awesome open source projects! ♥
from gmusicapi import Mobileclient
from websocket_server import WebsocketServer
sp_playlist_uri = ""
sp_playlist_name = ""
if not os.path.isfile("password.txt"):
sys.exit()
else:
password = open("password.txt", "r").read()
def receiveWS(c, s, msg):
data = json.loads(msg.encode("latin-1"))
print(data)
try:
auth = data["auth"]
except NameError:
auth = False
if auth == password:
if data["q"] == "transfer_playlist":
api = Mobileclient(False)
if api.login(data["email"], data["password"], Mobileclient.FROM_MAC_ADDRESS):
if data["new_playlist"] is True:
playlist = api.create_playlist(data["playlist"], "tranfered with Playify")
else:
playlist = data["playlist"]
for track in data["tracks"]:
print(track)
result = api.search(track)
try:
res = result["song_hits"][0]["track"]["storeId"]
except NameError:
res = False
except IndexError:
res = False
if res:
pres = api.add_songs_to_playlist(playlist, res)
server.send_message_to_all(json.dumps({
"q": "progress",
"error": False,
"track": track,
"id": res
}))
else:
server.send_message_to_all(json.dumps({
"q": "progress",
"error": True,
"track": track
}))
else:
server.send_message_to_all(json.dumps({
"q": "auth",
"error": True,
"google": True
}))
elif data["q"] == "get_playlists":
api = Mobileclient(False)
if api.login(data["email"], data["password"], Mobileclient.FROM_MAC_ADDRESS):
playlists = api.get_all_playlists()
array = []
for playlist in playlists:
array.append({
"name": playlist["name"],
"id": playlist["id"]
})
server.send_message_to_all(json.dumps({
"q": "playlists",
"lists": array
}))
else:
server.send_message_to_all(json.dumps({
"q": "auth",
"error": True,
"google": True
}))
else:
server.send_message_to_all(json.dumps({
"q": "auth",
"error": False
}))
else:
server.send_message_to_all(json.dumps({
"q": "auth",
"error": True
}))
PORT=5673
server = WebsocketServer(PORT)
server.set_fn_message_received(receiveWS)
server.run_forever()