Skip to content

Commit 67c61a2

Browse files
committed
fix(sources): Twitch videos work again!
fixes #1
1 parent 4c2d708 commit 67c61a2

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

background/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const checkForUpdates = async () => {
4848
};
4949

5050
const mergeMatch = (source, username, video) => {
51-
return video.source === source && video.user.name === username;
51+
return video.source === source && video.user && video.user.name === username;
5252
};
5353

5454
const updateVideos = () => {

background/sources/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const sources = {
145145
if (!meta) { return false; }
146146
} catch (err) {
147147
console.warn('Failed to get meta for video: ' + video.url);
148-
return;
148+
return false;
149149
}
150150
video.url = meta.url;
151151
video.thumbnail = meta.thumbnail;

background/sources/videos/twitch.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ let twitchToken = null;
55
const getTwitchToken = () => {
66
return new Promise((resolve) => {
77
if (twitchToken) {
8-
return twitchToken;
8+
resolve(twitchToken);
99
} else {
1010
chrome.cookies.get({
11-
url: 'https://www.twitch.tv/directory/following/videos',
12-
name: 'api_token',
11+
url: 'https://www.twitch.tv',
12+
name: 'auth-token',
1313
}, (cookie) => {
1414
twitchToken = cookie && cookie.value;
1515
resolve(twitchToken);
@@ -22,48 +22,46 @@ export default {
2222
patterns: [
2323
'*://*.twitch.tv/*/v/*',
2424
'*://twitch.tv/*/v/*',
25+
'*://*.twitch.tv/videos/*',
26+
'*://twitch.tv/videos/*',
2527
],
2628
getVideo: async (url) => {
2729
const token = await getTwitchToken();
2830
const parsed = new URL(url);
2931
const s = parsed.pathname.split(/\//);
3032
const id = s[s.length - 1];
31-
const meta = await util.ajax('https://api.twitch.tv/kraken/videos/v' + id, {
33+
return util.ajax('https://api.twitch.tv/kraken/videos/' + id, {
3234
cache: {
3335
transform: (response) => ({
36+
url : response.url,
3437
thumbnail : response.preview,
3538
length : response.length,
3639
title : response.title,
3740
game : response.game,
3841
views : response.views,
42+
user : {
43+
url: 'https://www.twitch.tv/' + response.channel.name,
44+
name: response.channel.display_name,
45+
},
3946
}),
4047
ttl: 1800000,
4148
},
42-
headers: { 'Twitch-Api-Token': token },
49+
headers: { 'Authorization': `OAuth ${token}` },
4350
});
44-
const username = /twitch\.tv\/([^/]+)\//.exec(url)[1];
45-
return {
46-
url: 'https://www.twitch.tv/' + username + '/v/' + id,
47-
user: {
48-
url: 'https://www.twitch.tv/' + username,
49-
name: username,
50-
},
51-
...meta,
52-
};
5351
},
5452
getAllVideos: async () => {
5553
const token = await getTwitchToken();
5654
const result = await util.ajax('https://api.twitch.tv/kraken/videos/followed?' +
57-
'limit=40&broadcast_type=highlight&offset=0&on_site=1', {
58-
headers: { 'Twitch-Api-Token': token },
55+
'limit=50&broadcast_type=highlight&offset=0&on_site=1', {
56+
headers: { 'Authorization': `OAuth ${token}` },
5957
});
6058
return result.videos.map((video) => {
6159
return {
6260
user: {
6361
url: 'https://www.twitch.tv/' + video.channel.name,
6462
name: video.channel.display_name,
6563
},
66-
url: video.url.replace(/^https:\/\/secure\./, 'https://www.'),
64+
url: video.url,
6765
thumbnail: video.preview,
6866
length: video.length,
6967
title: video.title,

0 commit comments

Comments
 (0)