Skip to content

Commit

Permalink
fix testing ,playlist and refactorr queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mp3butcher committed Nov 18, 2024
1 parent 99d3c65 commit ba531eb
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 57 deletions.
9 changes: 3 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function scan(msg) {
console.warn(" [x] contentype video!!!!!!!!!!!" + data);
}
//Large Content-Range
if (sizeok || contentlength > 100000) {
if(!contentype.startsWith('image') && (sizeok || contentlength > 1000000)) {
toscandeeply = true;
}
let res = atob(data.response)
Expand All @@ -360,8 +360,7 @@ function scan(msg) {
if (res[0] == "#") { //HLS?
console.log(res);
toscandeeply = true;
}
else if (res.startsWith('<MPD')) { //DASH?
} else if (res.startsWith('<MPD')) { //DASH?
console.log(res);
toscandeeply = true;
}
Expand Down Expand Up @@ -395,7 +394,6 @@ ipcMain.handle("setScannerEnabled", (event, args) => {

console.log(env.settings.paths.mitmproxy);
if (scannerIsOn) {

if (mitmproxyclient) mitmproxyclient.destroy();
console.log(__dirname);
let script = path.join(path.dirname(__dirname), 'binaries', 'send_traffic_to_videodownloader.py');
Expand All @@ -421,8 +419,7 @@ ipcMain.handle("setScannerEnabled", (event, args) => {
mitmwebprocess.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
let msg = 'Proxy running on localhost on port 15930: Configure proxy in your browser to scan network';
dialog.showMessageBox({ message: msg });
dialog.showMessageBox({ message: 'Proxy running on localhost on port 15930: Configure proxy in your browser to scan network' });
createConnection();

} else {
Expand Down
8 changes: 5 additions & 3 deletions modules/QueryManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class QueryManager {
async manage(url, headers) {
let metadataVideo = new Video(url, headers, "metadata", this.environment);
this.addVideo(metadataVideo);
const initialQuery = await new InfoQuery(url, headers,metadataVideo.identifier, this.environment).connect();
const initialQuery = await new InfoQuery(metadataVideo, metadataVideo.identifier).connect();
if(metadataVideo.error) return;
if(Utils.isYouTubeChannel(url)) {
const actualQuery = await new InfoQuery(initialQuery.entries[0].url, metadataVideo.headers, metadataVideo.identifier, this.environment).connect();
let metadataVideo2 = new Video(initialQuery.entries[0].url, metadataVideo.headers, metadataVideo.identifier, this.environment);
const actualQuery = await new InfoQuery(metadataVideo2, metadataVideo.identifier).connect();
if(metadataVideo.error) return;
this.removeVideo(metadataVideo);
if(actualQuery.entries == null || actualQuery.entries.length === 0) this.managePlaylist(initialQuery, url);
Expand Down Expand Up @@ -127,6 +128,7 @@ class QueryManager {
type: video.type,
identifier: video.identifier,
url: video.url,
headers: video.headers,
title: video.title,
duration: video.duration,
audioOnly: video.audioOnly,
Expand Down Expand Up @@ -157,7 +159,7 @@ class QueryManager {
}
downloadVideo.audioQuality = (downloadVideo.audioQuality != null) ? downloadVideo.audioQuality : "best";
let progressBar = new ProgressBar(this, downloadVideo);
downloadVideo.setQuery(new DownloadQuery(downloadVideo.url, downloadVideo.headers, downloadVideo, this.environment, progressBar, this.playlistMetadata));
downloadVideo.setQuery(new DownloadQuery(downloadVideo, progressBar, this.playlistMetadata));
downloadVideo.query.connect().then(() => {
//Backup done call, sometimes it does not trigger automatically from within the downloadQuery.
if(downloadVideo.error) return;
Expand Down
3 changes: 2 additions & 1 deletion modules/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ class Utils {
}
for(const entry of infoQueryResult.entries) {
let url;
entry.headers=[];
if (entry.url == null) url = entry.webpage_url;
else url = entry.url;
if(entry.formats != null && entry.formats.length > 0) {
entry.url = url;
alreadyDone.push(entry);
continue;
}
urls.push({'url':url,'headers':entry.headers});
urls.push({'url':url,'headers':[]});
}
return [urls, alreadyDone]
}
Expand Down
10 changes: 4 additions & 6 deletions modules/download/DownloadQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ const Utils = require("../Utils")
const console = require("console");

class DownloadQuery extends Query {
constructor(url, headers, video, environment, progressBar, playlistMeta) {
super(environment, video.identifier);
constructor(video, progressBar, playlistMeta) {
super(video.environment, video.identifier);
this.playlistMeta = playlistMeta;
this.url = url;
this.video = video;
this.progressBar = progressBar;
this.format = video.formats[video.selected_format_index];
this.headers = headers;
}

cancel() {
Expand Down Expand Up @@ -171,7 +169,7 @@ class DownloadQuery extends Query {
let result = null;
const regexliverec = /size=\s*(\d+\w)iB\s*time=(\d+:\d+:\d+.\d+)\s*bitrate=\s*(\d+.\d+\w)bits\/s\s*speed=\d+.\d+x/;
try {
result = await this.environment.downloadLimiter.schedule(() => this.start(this.url, args, (liveData) => {
result = await this.environment.downloadLimiter.schedule(() => this.start(this.video, args, (liveData) => {
this.environment.logger.log(this.video.identifier, liveData);
this.video.setFilename(liveData);
if(this.video.is_live) {
Expand All @@ -183,7 +181,7 @@ class DownloadQuery extends Query {
try{
const livrec = liveData.match(regexliverec);
if (typeof (`${livrec[1]}`) == "undefined") return;
this.progressBar.updateDownload('livestream', `${livrec[2]}`, `${livrec[3]}bits\/s`, this.video.audioOnly || this.video.downloadingAudio);
this.progressBar.updateDownload('livestream', `${livrec[2]}`, `${livrec[3]}bits/s`, this.video.audioOnly || this.video.downloadingAudio);
} catch(e) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/download/DownloadQueryList.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DownloadQueryList {
return await new Promise(((resolve) => {
for(let video of this.videos) {
let progressBar = new ProgressBar(this.manager, video);
let task = new DownloadQuery(video.webpage_url, video.headers, video, this.environment, progressBar, Utils.getVideoInPlaylistMetadata(video.url, null, this.playlistMetadata));
let task = new DownloadQuery(video, progressBar, Utils.getVideoInPlaylistMetadata(video.url, null, this.playlistMetadata));
if(video.parentID != null && !this.parentProgress.some(e => e.id === video.parentID)) {
const bar = new ProgressBar(this.manager, video.parentID);
this.parentProgress.push({
Expand Down
13 changes: 6 additions & 7 deletions modules/info/InfoQuery.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const Query = require("../types/Query");

class InfoQuery extends Query {
constructor(url, headers, identifier, environment) {
super(environment, identifier);
this.url = url;
this.headers = headers;
this.environment = environment;
constructor(video, identifier) {
super(video.environment, identifier);
this.video = video;
this.environment = video.environment;
this.identifier = identifier;
}

Expand All @@ -16,8 +15,8 @@ class InfoQuery extends Query {
args.push('--file-access-retries');
args.push(this.environment.settings.fileAccessRetries);
}
this.headers.forEach((h) => args.push("--add-headers", h.k + ": " + h.v));
let data = await this.environment.metadataLimiter.schedule(() => this.start(this.url, args));
this.video.headers.forEach((h) => args.push("--add-headers", h.k + ": " + h.v));
let data = await this.environment.metadataLimiter.schedule(() => this.start(this.video, args));
return JSON.parse(data);
} catch (e) {
this.environment.errorHandler.checkError(e.stderr, this.identifier)
Expand Down
8 changes: 5 additions & 3 deletions modules/info/InfoQueryList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ const Video = require('../types/Video');
const Utils = require("../Utils");

class InfoQueryList {
constructor(query, environment, progressBar) {
constructor(query, headers, environment, progressBar) {
this.query = query;
this.environment = environment;
this.progressBar = progressBar;
this.urls = null;
this.length = null;
this.done = 0;
this.headers = headers;
}

async start() {
Expand All @@ -29,10 +30,11 @@ class InfoQueryList {
resolve(null);
}
for (const url of this.urls) {
let task = new InfoQuery(url,this.progressBar.video.headers, this.progressBar.video.identifier, this.environment);
let metadataVideo = new Video(url.url, url.headers, "", this.environment);
let task = new InfoQuery(metadataVideo, "");
task.connect().then((data) => {
if (data.formats != null) {
let video = this.createVideo(data, url, data.headers);
let video = this.createVideo(data, url.url, url.headers);
totalMetadata.push(video);
}
this.done++;
Expand Down
2 changes: 1 addition & 1 deletion modules/size/SizeQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SizeQuery extends Query {
formatArgument = `bestvideo+${this.format}audio/bestvideo+bestaudio/best`;
}

let output = await this.environment.metadataLimiter.schedule(() => this.start(this.video.url, ["-J", "--flat-playlist", "-f", formatArgument]));
let output = await this.environment.metadataLimiter.schedule(() => this.start(this.video, ["-J", "--flat-playlist", "-f", formatArgument]));
let data = JSON.parse(output);
let totalSize = 0;
if(data.requested_formats != null) {
Expand Down
19 changes: 13 additions & 6 deletions modules/types/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ class Query {
this.identifier = identifier
this.process = null;
this.stopped = false;
this.video = null;
}

stop() {
this.stopped = true;
if(this.process != null) {
if (this.progressBar.video.is_live)
process.kill(this.process.pid, 'SIGINT');///Only way to stop ffmpeg lives
else this.process.kill();
if (this.video.is_live) process.kill(this.process.pid, 'SIGINT');///Only way to stop ffmpeg lives
else this.process.cancel();
}
}

async start(url, args, cb) {
async start(video, args, cb) {
this.video = video;
let url = video.url;
if(this.stopped) return "killed";
args.push("--no-cache-dir");
args.push("--ignore-config");
Expand Down Expand Up @@ -82,7 +84,9 @@ class Query {
//Return data while the query is running (live)
//Return "done" when the query has finished
return await new Promise((resolve) => {
this.process = child_process.spawn(command, args);
try {
if(video.is_live) this.process = child_process.spawn(command, args);
else this.process = execa(command, args);
this.process.stdout.setEncoding('utf8');
this.process.stdout.on('data', (data) => {
const lines = data
Expand All @@ -108,7 +112,10 @@ class Query {
resolve("killed");
}
console.error(data.toString())
})
});
} catch(e) {
console.log(e);
}
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion renderer/renderer.css
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ select {

.bi-card-text-strike {
display: block;
background: url(img/card-text-strike.svg);
background: url(img/card-text-strike.svg) center no-repeat;
height: 1em;
width: 1em;
margin-top: 0.2em ;
Expand Down
5 changes: 4 additions & 1 deletion tests/InfoQuery.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const InfoQuery = require("../modules/info/InfoQuery");
const Video = require("../modules/types/Video");

describe('Connect the InfoQuery', () => {
beforeEach(() => {
Expand Down Expand Up @@ -44,6 +45,8 @@ function instanceBuilder() {
},
settings: {}
};
return [env, new InfoQuery("http://url.link", [], "test__id", env)];
let metadataVideo = new Video("http://url.link", [], "test__id", env);

return [env, new InfoQuery(metadataVideo, "test__id")];
}

Loading

0 comments on commit ba531eb

Please sign in to comment.