diff --git a/src/app/js/app.js b/src/app/js/app.js index 686f356..61d458c 100644 --- a/src/app/js/app.js +++ b/src/app/js/app.js @@ -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(''); + console.log(arg); // prints "pong" + $('#body-' + arg.id).append(''); }); 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); + $('
').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); + $('').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); + $('').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); - $( '').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); - $( '').prependTo('#output'); - cache[video_id] = YT.title; - ipcRenderer.send('start-download', {url:$('#url').val(),id:video_id}); - }) } - console.log(playlist_id+' id:'+video_id) - }) }) diff --git a/src/controller/crunchyroll.js b/src/controller/crunchyroll.js new file mode 100644 index 0000000..c8e071d --- /dev/null +++ b/src/controller/crunchyroll.js @@ -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