Skip to content

Instantly share code, notes, and snippets.

@mysteriouss
Last active September 29, 2017 02:21
Show Gist options
  • Save mysteriouss/78cc0bf2388cd9d27eeea9e21633c494 to your computer and use it in GitHub Desktop.
Save mysteriouss/78cc0bf2388cd9d27eeea9e21633c494 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name douyu.com
// @namespace http://tampermonkey.net/
// @version 1.0
// @description try to take over the world!
// @author You
// @match *://www.douyu.com/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
// Use at your own risk
function IsNum(s){
if (s!==null && s!==""){
return !isNaN(s);
}
return false;
}
var room_id = document.title.match(/直播间(\d+(.\d+)?)/g)[0].split('直播间')[1];
if(room_id < 10 || !IsNum(room_id)) return;
console.log(room_id);
var roomId = room_id;
var tt = (new Date()).getTime().toString().substr(0, 10);
var apikey = 'Y237pxTx2In5ayGz';
var authstr = "room/"+roomId+"?aid=androidhd1&cdn=ws&client_sys=android&time="+tt;
var authstr1 = authstr+apikey;
var sign = CryptoJS.MD5(authstr1).toString();
var apiurl = "https://capi.douyucdn.cn/api/v1/"+authstr+"&auth="+sign;
console.log(apiurl);
GM_xmlhttpRequest ( {
method: "GET",
url: apiurl,
headers: {
},
onload: function (response) {
//console.log(response.responseText);
var data = JSON.parse(response.responseText);
if(!data.error){
if(data.data.online || data.data.show_status == 1){
if(data.data && data.data.hls_url && false){
window.location = data.data.hls_url.replace('http://','https://');
}else if(data.data && data.data.rtmp_url && data.data.rtmp_live){
var flv = data.data.rtmp_url + '/' + data.data.rtmp_live;
//console.log(flv);
//window.location="open://?url=" + encodeURIComponent(flv) + "&with=" + "/Applications/VLC.app/Contents/MacOS/VLC";
window.location = 'iina://weblink?url=' + encodeURIComponent(flv); // + '&mode=fullscreen' //{fullscreen|pip|windowed}
}
else{
alert('No URL');
}
}else{
//alert('Not Online');
}
}else{
alert('Error');
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment