Skip to content

Instantly share code, notes, and snippets.

@dreygur
Created August 26, 2019 04:47
Show Gist options
  • Select an option

  • Save dreygur/744fcc4b06a54fead1bcb8e85ab07010 to your computer and use it in GitHub Desktop.

Select an option

Save dreygur/744fcc4b06a54fead1bcb8e85ab07010 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @icon https://cdn1.iconfinder.com/data/icons/ninja-things-1/1772/ninja-simple-512.png
// @name Hoichoi
// @namespace http://rakibul.me
// @version 0.0.2
// @description Hoichoi TV Downloader
//
// @author Rakibul Yeasin
// @downloadURL https://github.com/dreygur/Hoichoi/raw/master/hoichoi.user.js
//
// @license GPLv3 - http://www.gnu.org/licenses/gpl-3.0.txt
// @copyright Copyright (C) 2019, by 'Rakibul Yeasin'
// @match https://www.hoichoi.tv/*
// @grant none
// @require http://code.jquery.com/jquery-1.12.4.min.js
// @updateURL https://github.com/dreygur/Hoichoi/raw/master/hoichoi.user.js
// ==/UserScript==
(function () {
'use strict';
var Hoichoi = {
path: 'https://prod-api.viewlift.com/content/videos/',
note: `<span style="font-size:12px;">Chose quality to Download</span>`,
// Counter for Retry
// Hghest Value: 20
retryCount: 1,
// Load & Run the Downloader
attach() {
// Keep Current instance to ttl
// Some more `this` keywords are used
var ttl = this;
var XHR = XMLHttpRequest.prototype;
// Remember references to original methods
var open = XHR.open;
var send = XHR.send;
// Overwrite native methods
// Collect data:
XHR.open = function (method, url) {
this._method = method;
this._url = url;
return open.apply(this, arguments);
};
// Implement "ajaxSuccess" functionality
XHR.send = function (postData) {
this.addEventListener('load', function () {
ttl.loaded(this);
});
return send.apply(this, arguments);
};
$(document).on('click', 'a.video-tray-item', function (e) {
e.stopPropagation();
window.open($(this).attr('href'), '_blank');
});
},
// Parse the response
parse(content) {
var details = { title: content.gist.title, image: content.gist.videoImageUrl, videos: [] };
if (content.streamingInfo.videoAssets.mpeg.length > 0) {
content.streamingInfo.videoAssets.mpeg.forEach(function (item) {
var quality = item.renditionValue;
details.videos.push({
quality: quality.substr(1, quality.length),
url: item.url
});
});
}
return details;
},
loaded(xhr) {
if (xhr._url.includes(this.path)) {
var episode = this.parse(JSON.parse(xhr.responseText));
this.render(episode);
}
},
// Inject Download Buttons
render(info) {
var ttl = this;
setTimeout(function () {
var $prompt = $('.subscription-prompt .overlay');
if ($prompt.length <= 0) {
if (ttl.retryCount > 20) {
return;
}
console.log('Trying to find hoichoi stream');
ttl.retryCount += 1;
return ttl.render(info);
}
// Remove Subscription Button and Inject Download Button
$prompt.find('p').html(`${info.title} <br> ${ttl.note}`);
$prompt.find('.button-container').html(ttl.links(info.videos));
}, 200);
},
links(videos) {
var html = '';
videos.forEach(function (video) {
html += `<a href="${video.url}" target="_blank" class="cta button" style="margin-right:10px;">
${video.quality}
</a>`;
});
return html;
},
find() {
var state = window.initialStoreState.page;
if (state === undefined) {
return;
}
if (state.data.title.toLowerCase() != 'video page') {
return;
}
var modules = state.data.modules.filter(function (item) {
return item.moduleType == 'VideoDetailModule';
});
if (modules.length <= 0) {
return;
}
if (modules[0].contentData.length <= 0) {
return;
}
var movie = this.parse(modules[0].contentData[0]);
this.render(movie);
},
init() {
this.attach();
this.find();
}
};
Hoichoi.init();
})();
@amadersoto
Copy link
Copy Markdown

hi bro,
this script is not working. please update the script as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment