-
Notifications
You must be signed in to change notification settings - Fork 3
/
GPMDPJson.lua
65 lines (59 loc) · 5.16 KB
/
GPMDPJson.lua
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
function Initialize()
sJSONParser = SELF:GetOption('JSONParser')
sFileToRead = SELF:GetOption('FileToRead')
--load the external JSON library
JSON = assert(loadfile(sJSONParser))()
JSON.strictTypes = true
end
function Update()
--Create oldSongInfo if it doesn't exist
if oldSongInfo == nill then
local oldSongInfo
end
local File = io.open(sFileToRead)
-- HANDLE ERROR OPENING FILE.
if not File then
print('ReadFile: unable to open file at ' .. sFileToRead)
return
end
-- READ FILE CONTENTS AND CLOSE.
local FileContents = File:read("*all")
File:close()
--Convert JSON to lua table and set meters
nowPlaying_info = JSON:decode(FileContents)
if nowPlaying_info ~= nill then
if nowPlaying_info.playing then
if oldSongInfo == nil or oldSongInfo.title ~= nowPlaying_info.song.title then
if SKIN:GetMeter(SKIN:GetVariable("MeterTitleName")) ~= nil then
SKIN:GetMeter(SKIN:GetVariable("MeterTitleName")):SetText(nowPlaying_info.song.title)
end
if SKIN:GetMeter(SKIN:GetVariable("MeterArtistName")) ~= nil then
SKIN:GetMeter(SKIN:GetVariable("MeterArtistName")):SetText(nowPlaying_info.song.artist)
end
if SKIN:GetMeter(SKIN:GetVariable("MeterAlbumName")) ~= nil then
SKIN:GetMeter(SKIN:GetVariable("MeterAlbumName")):SetText(nowPlaying_info.song.album)
end
SKIN:Bang('!SetVariable', 'CoverUrl', nowPlaying_info.song.albumArt)
SKIN:Bang('!CommandMeasure', 'MeasureImageDownload', "Update")
end
local seconds = nowPlaying_info.time.total/1000
if SKIN:GetMeter(SKIN:GetVariable("MeterTotalTime")) ~= nil then
if math.floor(seconds/(60*60)) ~= 0 then
SKIN:GetMeter(SKIN:GetVariable("MeterTotalTime")):SetText(string.format("%.2d:%.2d:%.2d", seconds/(60*60), seconds/60%60, seconds%60))
else
SKIN:GetMeter(SKIN:GetVariable("MeterTotalTime")):SetText(string.format("%.2d:%.2d", seconds/60%60, seconds%60))
end
end
local currentSeconds = nowPlaying_info.time.current/1000
if SKIN:GetMeter(SKIN:GetVariable("MeterCurrentTime")) ~= nil then
if math.floor(currentSeconds/(60*60)) ~= 0 then
SKIN:GetMeter(SKIN:GetVariable("MeterCurrentTime")):SetText(string.format("%.2d:%.2d:%.2d", currentSeconds/(60*60), currentSeconds/60%60, currentSeconds%60))
else
SKIN:GetMeter(SKIN:GetVariable("MeterCurrentTime")):SetText(string.format("%.2d:%.2d", currentSeconds/60%60, currentSeconds%60))
end
end
SKIN:Bang('!SetVariable', 'Length', nowPlaying_info.time.current / nowPlaying_info.time.total)
oldSongInfo = nowPlaying_info.song
end
end
end