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

Commit

Permalink
Fix douyutv
Browse files Browse the repository at this point in the history
  • Loading branch information
freaktechnik committed Apr 29, 2016
1 parent 620c3f1 commit f84effb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .jpmignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ node_modules/
!node_modules/istanbul-jpm/
!node_modules/notification-box/
!node_modules/preferences-utils/
!node_modules/md5/
!node_modules/crypt/
!node_modules/charenc/
!node_modules/is-buffer/
node_modules/istanbul-jpm/node_modules/

*CHANGELOG*
Expand All @@ -32,4 +36,4 @@ python-lib/
build/
coverage/reports/
transpiled/
bower_components/
bower_components/r
3 changes: 3 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = function(grunt) {
var dependencies = Object.keys(pkg.dependencies).map(function(d) {
return d + "/**/*";
});
dependencies.push("is-buffer/**/*");
dependencies.push("charenc/**/*");
dependencies.push("crypt/**/*");

grunt.initConfig({
pkg: pkg,
Expand Down
13 changes: 10 additions & 3 deletions lib/providers/douyutv.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const { Class: newClass } = require("sdk/core/heritage");
const { emit } = require("sdk/event/core");
const { Channel } = require('../channel/core');
const { GenericProvider } = require("./generic-provider");
const md5 = require('md5');

const type = "douyutv",
baseURL = "http://www.douyutv.com/api/client/",
baseURL = "http://www.douyutv.com/api/v1/",
roomURL = "http://www.douyutv.com";

const getChannelFromJSON = (json) => {
Expand All @@ -31,13 +32,19 @@ const getChannelFromJSON = (json) => {
return chan;
};

const signAPI = (endpoint, id) => {
const argument = endpoint + id + "?aid=android&client_sys=android&time=" + Date.now();
const sign = md5(argument + '1231');
return argument + "&auth=" + sign;
};

const Douyutv = newClass(
/** @lends module:providers/douyutv~Douyutv */
{
extends: GenericProvider,
authURL: ["http://www.douyutv.com"],
getChannelDetails: function(username) {
return this._qs.queueRequest(baseURL + "room/" + username).then((data) => {
return this._qs.queueRequest(baseURL + signAPI("room/", username)).then((data) => {
if(data.json && data.json.error === 0) {
return getChannelFromJSON(data.json.data);
}
Expand All @@ -47,7 +54,7 @@ const Douyutv = newClass(
});
},
updateRequest: function(channels) {
const urls = channels.map((ch) => baseURL + "room/" + ch.login);
const urls = channels.map((ch) => baseURL + signAPI("room/", ch.login));
this._qs.queueUpdateRequest(urls, this._qs.HIGH_PRIORITY, (data) => {
if(data.json && data.json.error === 0) {
emit(this, "updatedchannels", getChannelFromJSON(data.json.data));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
},
"dependencies": {
"jetpack-homepanel": "^1.0.1",
"md5": "^2.1.0",
"notification-box": "^0.1.1",
"preferences-utils": "0.0.1"
},
Expand Down
4 changes: 4 additions & 0 deletions test/providers/mock-qs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const getRequest = (type, url) => {

url = u.join("?");
}
else if(type == "douyutv") {
url = url.split("?")[0];
}

console.log("Getting", url);
if(type in mockAPIEnpoints && url in mockAPIEnpoints[type]) {
return {
Expand Down
4 changes: 2 additions & 2 deletions test/providers/mockAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
}
},
"douyutv": {
"http://www.douyutv.com/api/client/room/test": {
"http://www.douyutv.com/api/v1/room/test": {
"error": 0,
"data": {
"room_id": "test",
Expand All @@ -383,7 +383,7 @@
"url": "/test"
}
},
"http://www.douyutv.com/api/client/room/live": {
"http://www.douyutv.com/api/v1/room/live": {
"error": 0,
"data": {
"room_id": "live",
Expand Down
1 change: 1 addition & 0 deletions test/test-providers-twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @license MPL-2.0
* @todo test playlist and hosting for all three methods
* @todo test hosting preferred over playlist
* @todo test hosting & playlist testchannels with the things disabled
*/
"use strict";

Expand Down

0 comments on commit f84effb

Please sign in to comment.