Skip to content

Commit d7f4619

Browse files
committed
Merge pull request #76 from blha303/patch-2
Fix twitch.py to show online status properly
2 parents 0de0a5b + fad6a26 commit d7f4619

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

plugins/twitch.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,19 @@ def twitch_lookup(location):
9393
views = views + "s" if not views[0:2] == "1 " else views
9494
return html.unescape(fmt.format(title, channel, playing, views))
9595
else:
96-
data = http.get_json("https://api.twitch.tv/kraken/channels/" + channel)
97-
if data and len(data) >= 1:
96+
data = http.get_json("https://api.twitch.tv/kraken/streams?channel=" + channel)
97+
if data["streams"]:
98+
title = data["streams"][0]["channel"]["status"]
99+
playing = data["streams"][0]["game"]
100+
v = data["streams"][0]["viewers"]
101+
viewers = "\x033\x02Online now!\x02\x0f " + str(v) + " viewer" + ("s" if v != 1 else "")
102+
return html.unescape(fmt.format(title, channel, playing, viewers))
103+
else:
104+
try:
105+
data = http.get_json("https://api.twitch.tv/kraken/channels/" + channel)
106+
except:
107+
return "Unable to get channel data. Maybe channel is on justin.tv instead of twitch.tv?"
98108
title = data['status']
99109
playing = data['game']
100110
viewers = "\x034\x02Offline\x02\x0f"
101111
return html.unescape(fmt.format(title, channel, playing, viewers))
102-
else:
103-
return

0 commit comments

Comments
 (0)