forked from vipintom/gpm2spotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpm.py
37 lines (25 loc) · 995 Bytes
/
gpm.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
from gmusicapi import Mobileclient
import codecs
api = Mobileclient()
trackEntryStart = "sj#track"
trackPrefix = "'title'"
artistPrefix = "'artist'"
delim = ","
if not api.oauth_login(api.FROM_MAC_ADDRESS) :
api.perform_oauth()
response = str(api.get_all_songs())
index = 0
f = codecs.open("GPMLibraryParsed.txt", mode="w", encoding = "utf-8")
result = ""
while index < len(response) :
if response.find(trackEntryStart, index) != -1 :
index = response.index(trackEntryStart, index)
titleIndex = response.index(trackPrefix, index) + 10
titleDelimIndex = response.index(delim, titleIndex) - 1
artistIndex = response.index(artistPrefix, index) + 11
artistDelimIndex = response.index(delim, artistIndex) - 1
result = result + response[artistIndex : artistDelimIndex] + " " + response[titleIndex : titleDelimIndex] + "\n"
index = index + 1
print(result)
f.write(result)
f.close()