@@ -5,11 +5,11 @@ let twitchToken = null;
55const 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 = / t w i t c h \. t v \/ ( [ ^ / ] + ) \/ / . 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 ( / ^ h t t p s : \/ \/ s e c u r e \. / , 'https://www.' ) ,
64+ url : video . url ,
6765 thumbnail : video . preview ,
6866 length : video . length ,
6967 title : video . title ,
0 commit comments