Skip to content

Instantly share code, notes, and snippets.

@iKlotho
Last active December 25, 2015 22:07
Show Gist options
  • Save iKlotho/c74fd3d9648c71740823 to your computer and use it in GitHub Desktop.
Save iKlotho/c74fd3d9648c71740823 to your computer and use it in GitHub Desktop.
watTv Video Urls
// ==UserScript==
// @name watVideos
// @namespace http://www.wat.tv/video/*
// @description get videos
// @include http://www.wat.tv/video/*
// @exclude http://www.wat.tv/video/*
// @version 1
// @grant none
// ==/UserScript==
var script = document.createElement('script');
script.src = '//cdn.rawgit.com/satazor/SparkMD5/master/spark-md5.min.js';
document.body.appendChild(script);
var req = new XMLHttpRequest;
fmts = [
{
'SD': 'web'
}
];
var interval = setInterval(function () {
if (document.readyState === 'complete') {
clearInterval(interval);
done();
}
}, 100);
function requests(url) {
req.open('GET', url, false);
req.send(null);
if (req.status == 200) {
return req.response;
}
}
function download_video_info(real_id) {
var info = requests('http://www.wat.tv/interface/contentv3/' + real_id);
var myArr = JSON.parse(info);
return myArr['media'];
}
function compute_token(param) {
var timestamp = parseInt(requests('http://www.wat.tv/servertime?').split('|') [0]).toString(16);
var magic = '9b673b13fa4682ed14c3cfa5af5310274b514c4133e9b3a81e6e3aba009l2564';
//return '%s/%s' % (hashlib.md5((magic + param + timestamp).encode('ascii')).hexdigest(), timestamp)
var r = SparkMD5.hash(magic + param + timestamp) + '/' + timestamp
return r
}
function done() {
//console.log('wors');
//var hash = SparkMD5.hash('hello');
//console.log(hash);
var real_id = $('link') [7].href.split('/')[4];
var video_info = download_video_info(real_id);
var geo_list = video_info['geoList'];
var country = '';
if (geo_list) country = geo_list[0];
else country = '';
var chapters = video_info['chapters'];
var first_chapter = chapters[0];
var files = video_info['files'];
var first_file = files[0];
var formats = [
{
'url': 'http://wat.tv/get/android5/' + real_id + '.mp4',
'format_id': 'Mobile',
}
];
if (first_file['hasHD']) fmts.push({
'HD': 'webhd'
});
for (var i = 0; i < fmts.length; i++) {
var key = Object.keys(fmts[i]) [0];
var webid = '/' + fmts[i][key] + '/' + real_id.toString();
var video_url = 'http://www.wat.tv/get' + webid + '?token=' + compute_token(webid) + '&getURL=1&country=' + country;
console.log(video_url);
var real_video = requests(video_url);
formats.push({
url:real_video,
ext:'mp4',
format_id:key
});
}
//console.log(formats);
var ek =document.getElementsByClassName('borderColorCHover sharable')[0]
ek.insertAdjacentHTML('beforeBegin','<li style="visibility: visible;" class="borderColorCHover sharable"><a href='+formats[1].url+' target="_blank">SD</a></li> ');
ek.insertAdjacentHTML('beforeBegin','<li style="visibility: visible;" class="borderColorCHover sharable"><a href='+formats[2].url+' target="_blank">HD</a></li> ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment