1.3.2.2
Offline watch
This commit is contained in:
parent
44042f5d5e
commit
acab4b1908
@ -1,68 +1,93 @@
|
||||
$(function(){
|
||||
$(function() {
|
||||
var download_progress = $('#download-progress');
|
||||
var out = $('#output');
|
||||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
const request = require('request');
|
||||
const {dialog} = require('electron').remote;
|
||||
const {
|
||||
dialog
|
||||
} = require('electron').remote;
|
||||
|
||||
var cache = {};
|
||||
var path = "";
|
||||
ipcRenderer.on('download-progress', function(event, arg) {
|
||||
console.log(arg); // prints "pong"
|
||||
$('#download-progress-'+arg.id).css("width",arg.percent);
|
||||
$('#download-progress-'+arg.id).html(arg.percent);
|
||||
console.log(arg); // prints "pong"
|
||||
$('#download-progress-' + arg.id).css("width", arg.percent);
|
||||
$('#download-progress-' + arg.id).html(arg.percent);
|
||||
});
|
||||
ipcRenderer.on('process-fin', function(event, arg) {
|
||||
console.log(arg); // prints "pong"
|
||||
$('#download-progress-'+arg.id).css("width",arg.percent);
|
||||
$('#download-progress-'+arg.id).html("CONVERTED");
|
||||
console.log(arg); // prints "pong"
|
||||
$('#download-progress-' + arg.id).css("width", arg.percent);
|
||||
$('#download-progress-' + arg.id).html("CONVERTED");
|
||||
});
|
||||
ipcRenderer.on('file', function(event, arg) {
|
||||
console.log(arg); // prints "pong"
|
||||
$('#body-'+arg.id).append('<audio src="file://'+path+'/'+cache[arg.id]+'.mp3" controls="true"/>');
|
||||
console.log(arg); // prints "pong"
|
||||
$('#body-' + arg.id).append('<audio src="file://' + path + '/' + cache[arg.id] + '.mp3" controls="true"/>');
|
||||
});
|
||||
document.getElementById('party').addEventListener('click', _ => {
|
||||
path = dialog.showOpenDialog({
|
||||
properties: ['openDirectory']
|
||||
})[0];
|
||||
console.log(path)
|
||||
ipcRenderer.send('setPath', {path:path});
|
||||
path = dialog.showOpenDialog({
|
||||
properties: ['openDirectory']
|
||||
})[0];
|
||||
console.log(path)
|
||||
ipcRenderer.send('setPath', {
|
||||
path: path
|
||||
});
|
||||
})
|
||||
$('body').delegate('.format','click',function(e){
|
||||
ipcRenderer.send('set-format', {format:e.currentTarget.dataset.format});
|
||||
$('body').delegate('.format', 'click', function(e) {
|
||||
ipcRenderer.send('set-format', {
|
||||
format: e.currentTarget.dataset.format
|
||||
});
|
||||
console.log(e.currentTarget.dataset.format);
|
||||
})
|
||||
$('#start-download').click(function(){
|
||||
var video_id = $('#url').val().split('v=')[1];
|
||||
var ampersandPosition = video_id.indexOf('&');
|
||||
if(ampersandPosition != -1) {
|
||||
video_id = video_id.substring(0, ampersandPosition);
|
||||
}
|
||||
var playlist_id = $('#url').val().split('list=')[1];
|
||||
if(typeof playlist_id !== 'undefined'){
|
||||
var playlist_idPOS = playlist_id.indexOf('&');
|
||||
if(playlist_idPOS != -1) {
|
||||
playlist_id = playlist_id.substring(0, playlist_idPOS);
|
||||
$('#start-download').click(function() {
|
||||
var url = $('#url').val();
|
||||
|
||||
if (url.match('crunchyroll')) {
|
||||
var video_id = Math.floor(Date.now() / 1000);
|
||||
$('<div class="media" ><div class="media-left"><a href="#"><img id="img-' + video_id + '" width="128" class="media-object" src="' + '" alt="..."></a></div><div class="media-body" id="body-' + video_id + '"><h4 class="media-heading">' + url + '</h4> Author: ' + '<div class="progress"><div class="progress-bar" id="download-progress-' + video_id + '" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">0%</div></div></div></div>').prependTo('#output');
|
||||
ipcRenderer.send('start-download', {
|
||||
url: $('#url').val(),
|
||||
id: video_id
|
||||
});
|
||||
} else {
|
||||
|
||||
var video_id = $('#url').val().split('v=')[1];
|
||||
var ampersandPosition = video_id.indexOf('&');
|
||||
if (ampersandPosition != -1) {
|
||||
video_id = video_id.substring(0, ampersandPosition);
|
||||
}
|
||||
var playlist_id = $('#url').val().split('list=')[1];
|
||||
if (typeof playlist_id !== 'undefined') {
|
||||
var playlist_idPOS = playlist_id.indexOf('&');
|
||||
if (playlist_idPOS != -1) {
|
||||
playlist_id = playlist_id.substring(0, playlist_idPOS);
|
||||
}
|
||||
|
||||
request
|
||||
.get('https://www.youtube.com/oembed?url=https://www.youtube.com/playlist?list=' + playlist_id + '&format=json', function(err, httpResponse, body) {
|
||||
var YT = JSON.parse(body);
|
||||
$('<div class="media" ><div class="media-left"><a href="#"><img id="img-' + video_id + '" width="128" class="media-object" src="' + YT.thumbnail_url + '" alt="..."></a></div><div class="media-body" id="body-' + video_id + '"><h4 class="media-heading">' + YT.title + '</h4> Playlistauthor: ' + YT.author_name + '<div class="progress"><div class="progress-bar" id="download-progress-' + video_id + '" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">0%</div></div></div></div>').prependTo('#output');
|
||||
cache[video_id] = YT.title;
|
||||
ipcRenderer.send('start-download-pl', {
|
||||
url: $('#url').val(),
|
||||
id: video_id,
|
||||
folder: YT.author_name + '-' + YT.title
|
||||
});
|
||||
})
|
||||
} else {
|
||||
request
|
||||
.get('https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=' + video_id + '&format=json', function(err, httpResponse, body) {
|
||||
var YT = JSON.parse(body);
|
||||
$('<div class="media" ><div class="media-left"><a href="#"><img id="img-' + video_id + '" width="128" class="media-object" src="' + YT.thumbnail_url + '" alt="..."></a></div><div class="media-body" id="body-' + video_id + '"><h4 class="media-heading">' + YT.title + '</h4> Author: ' + YT.author_name + '<div class="progress"><div class="progress-bar" id="download-progress-' + video_id + '" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">0%</div></div></div></div>').prependTo('#output');
|
||||
cache[video_id] = YT.title;
|
||||
ipcRenderer.send('start-download', {
|
||||
url: $('#url').val(),
|
||||
id: video_id
|
||||
});
|
||||
})
|
||||
}
|
||||
console.log(playlist_id + ' id:' + video_id)
|
||||
|
||||
request
|
||||
.get('https://www.youtube.com/oembed?url=https://www.youtube.com/playlist?list='+ playlist_id+'&format=json', function(err,httpResponse,body){
|
||||
var YT = JSON.parse(body);
|
||||
$( '<div class="media" ><div class="media-left"><a href="#"><img id="img-'+video_id+'" width="128" class="media-object" src="'+YT.thumbnail_url +'" alt="..."></a></div><div class="media-body" id="body-'+video_id+'"><h4 class="media-heading">'+YT.title+'</h4> Playlistauthor: '+YT.author_name+'<div class="progress"><div class="progress-bar" id="download-progress-'+video_id+'" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">0%</div></div></div></div>').prependTo('#output');
|
||||
cache[video_id] = YT.title;
|
||||
ipcRenderer.send('start-download-pl', {url:$('#url').val(),id:video_id,folder:YT.author_name+'-'+YT.title});
|
||||
})
|
||||
}else{
|
||||
request
|
||||
.get('https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v='+ video_id+'&format=json', function(err,httpResponse,body){
|
||||
var YT = JSON.parse(body);
|
||||
$( '<div class="media" ><div class="media-left"><a href="#"><img id="img-'+video_id+'" width="128" class="media-object" src="'+YT.thumbnail_url +'" alt="..."></a></div><div class="media-body" id="body-'+video_id+'"><h4 class="media-heading">'+YT.title+'</h4> Author: '+YT.author_name+'<div class="progress"><div class="progress-bar" id="download-progress-'+video_id+'" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">0%</div></div></div></div>').prependTo('#output');
|
||||
cache[video_id] = YT.title;
|
||||
ipcRenderer.send('start-download', {url:$('#url').val(),id:video_id});
|
||||
})
|
||||
}
|
||||
console.log(playlist_id+' id:'+video_id)
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
|
34
src/controller/crunchyroll.js
Normal file
34
src/controller/crunchyroll.js
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
JUST TO WATCH OFFLINE
|
||||
|
||||
|
||||
*/
|
||||
const fs = require('fs');
|
||||
|
||||
var crunch = {};
|
||||
|
||||
crunch.session_save = (session)=>{
|
||||
var net = `# Netscape HTTP Cookie File\n
|
||||
# http://curl.haxx.se/rfc/cookie_spec.html\n
|
||||
# This is a generated file! Do not edit.\n\n`;
|
||||
var old_exp = 0;
|
||||
for(var i = 0;i<session.length;i++){
|
||||
|
||||
if(typeof session[i].expirationDate == 'undefined'){
|
||||
session[i].expirationDate = old_exp;
|
||||
}
|
||||
if(session[i].expirationDate>old_exp){
|
||||
old_exp = session[i].expirationDate;
|
||||
}
|
||||
net += session[i].domain+' '+session[i].httpOnly.toString().toUpperCase()+' '+session[i].path+' '+session[i].secure.toString().toUpperCase()+' '+Math.ceil(session[i].expirationDate)+' '+session[i].name+' '+session[i].value+'\n';
|
||||
}
|
||||
console.log(net);
|
||||
fs.writeFile(global.dir+"/tmp/c", net, function(err) {
|
||||
if(err) {
|
||||
return console.log(err);
|
||||
}
|
||||
console.log("T!");
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = crunch;
|
@ -5,6 +5,8 @@ const {
|
||||
session
|
||||
} = require('electron');
|
||||
|
||||
const crunch = require('./../crunchyroll')
|
||||
|
||||
class browser {
|
||||
constructor(url){
|
||||
console.log("TEST")
|
||||
@ -17,7 +19,8 @@ class browser {
|
||||
})
|
||||
setInterval(function(){
|
||||
session.defaultSession.cookies.get({url:'http://crunchyroll.com'}, (error, cookies) => {
|
||||
console.log(error, cookies)
|
||||
//console.log(error, cookies)
|
||||
crunch.session_save(cookies);
|
||||
})
|
||||
},3000)
|
||||
var window = this.window
|
||||
|
@ -1,5 +1,6 @@
|
||||
const { spawn } = require('child_process');
|
||||
const ipcMain = require('electron').ipcMain;
|
||||
const dl_routine = require('./youtube-dl.routine')
|
||||
console.log(global.dir);
|
||||
|
||||
var orig_path = "";
|
||||
@ -54,16 +55,9 @@ var yt_dl = class{
|
||||
var log = [];
|
||||
var me = this;
|
||||
var ls;
|
||||
switch (format) {
|
||||
case "mp3":
|
||||
ls = spawn(global.dir+'/lib/youtube-dl', ['-x','--audio-format','mp3','-i',this.url,'-o',path+'/%(title)s.%(ext)s']);
|
||||
break;
|
||||
case "mp4":
|
||||
ls = spawn(global.dir+'/lib/youtube-dl', ['-f','bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4',this.url,'-o',path+'/%(title)s.%(ext)s']);
|
||||
break;
|
||||
default:
|
||||
|
||||
}
|
||||
var m = dl_routine(path,this.url,format);
|
||||
ls = spawn(m[0],m[1]);
|
||||
if(path == ''){
|
||||
//ls = spawn(global.dir+'/lib/youtube-dl', ['-x','--audio-format','mp3','-i',this.url]);
|
||||
}else{
|
||||
|
31
src/controller/youtube-dl.routine.js
Normal file
31
src/controller/youtube-dl.routine.js
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
|
||||
|
||||
module.exports = (path,url,format)=>{
|
||||
var command = global.dir+'/lib/youtube-dl';
|
||||
var param = [];
|
||||
console.log(url);
|
||||
if(url.match('youtube')){
|
||||
console.log('youtube')
|
||||
switch (format) {
|
||||
case "mp3":
|
||||
param = ['-x','--audio-format','mp3','-i',url,'-o',path+'/%(title)s.%(ext)s'];
|
||||
break;
|
||||
case "mp4":
|
||||
param = ['-f','bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4',url,'-o',path+'/%(title)s.%(ext)s'];
|
||||
break;
|
||||
default:
|
||||
|
||||
}
|
||||
}
|
||||
else if(url.match('crunchyroll')){
|
||||
console.log('crunchyroll')
|
||||
param = ['--cookie', global.dir+'/tmp/c', '--all-subs', '--sub-format', 'srt', '--write-sub', '--embed-subs',url,'-o',path+'/%(title)s.%(ext)s'];
|
||||
}
|
||||
|
||||
|
||||
return [command,param];
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user