Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
Fix #167: Updating single twitch channel streaming a playlist makes i…
Browse files Browse the repository at this point in the history
…t offline
  • Loading branch information
freaktechnik committed Jul 5, 2016
1 parent c6be272 commit bf0ca57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/providers/generic-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ProviderError extends Error {
case 2: message = "Could not access the requested resource"; break;
case 3: message = "Could not find any result for the given username"; break;
default: message = "Could not load the requested resource"; break;
}
super(message);
this.code = code;
this.name = "ProviderError";
Expand Down
13 changes: 7 additions & 6 deletions lib/providers/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ function getChannelFromJSON(jsonChannel) {
return ret;
}

function getStreamTypeParam() {
function getStreamTypeParam(delim = "&") {
if(prefs.twitch_showPlaylist)
return "&stream_type=all";
return delim+"stream_type=all";
else
return "&stream_type=live";
return delim+"&stream_type=live";
}

class Twitch extends GenericProvider {
Expand Down Expand Up @@ -227,14 +227,15 @@ class Twitch extends GenericProvider {
}
});
}
async updateChannel(channelname, ignoreHosted) {
async updateChannel(channelname, ignoreHosted = false) {
console.log("twitch.updateChannel:",channelname, ignoreHosted);
const [ data, channel ] = await Promise.all([
this._qs.queueRequest(baseURL+'/streams/'+channelname, headers),
this._qs.queueRequest(baseURL+'/streams/'+channelname+getStreamTypeParam("?"), headers),
this.getChannelDetails(channelname)
]);

if(data.json && data.json.stream !== null &&
((prefs.twitch_showPlaylist && !ignoreHosted) || !data.json.stream.is_playlist)) {
(!ignoreHosted || !data.json.stream.is_playlist)) {
channel.viewers = data.json.stream.viewers;
channel.thumbnail = data.json.stream.preview.medium;
if(data.json.stream.is_playlist) {
Expand Down
12 changes: 6 additions & 6 deletions test/providers/mockAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -881,10 +881,10 @@
}
]
},
"https://api.twitch.tv/kraken/streams/test": {
"https://api.twitch.tv/kraken/streams/test?stream_type=all": {
"stream": null
},
"https://api.twitch.tv/kraken/streams/live": {
"https://api.twitch.tv/kraken/streams/live?stream_type=all": {
"stream": {
"viewers": 0,
"preview": {
Expand Down Expand Up @@ -936,7 +936,7 @@
}
]
},
"https://api.twitch.tv/kraken/streams/mlg_live": {
"https://api.twitch.tv/kraken/streams/mlg_live?stream_type=all": {
"stream": null
},
"https://api.twitch.tv/kraken/channels/mlg_live": {
Expand Down Expand Up @@ -1169,7 +1169,7 @@
"views": 15,
"followers": 5
},
"https://api.twitch.tv/kraken/streams/freaktechnik": {
"https://api.twitch.tv/kraken/streams/freaktechnik?stream_type=all": {
"stream": null
},
"https://api.twitch.tv/kraken/streams?channel=freaktechnik&stream_type=live&limit=100&offset=0": {
Expand Down Expand Up @@ -1270,7 +1270,7 @@
"videos": "https://api.twitch.tv/kraken/channels/totalbiscuit/videos"
}
},
"https://api.twitch.tv/kraken/streams/totalbiscuit": {
"https://api.twitch.tv/kraken/streams/totalbiscuit?stream_type=all": {
"stream": {
"game": "Super Smash Bros. Melee",
"viewers": 16667,
Expand Down Expand Up @@ -1486,7 +1486,7 @@
}
]
},
"https://api.twitch.tv/kraken/streams/nvidia": {
"https://api.twitch.tv/kraken/streams/nvidia?stream_type=all": {
"stream": {
"_id": 20929063952,
"game": "Rust",
Expand Down

0 comments on commit bf0ca57

Please sign in to comment.