Fixed broken file size and better direct link detection
This commit is contained in:
parent
3a633d9794
commit
78f5fe5dc4
18
links.ts
18
links.ts
|
@ -36,22 +36,18 @@ export class Links {
|
||||||
return match![group] ? match![group] : undefined;
|
return match![group] ? match![group] : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async direct_link(id: string): Promise<string | undefined> {
|
|
||||||
|
|
||||||
let download_link = "https://uloz.to/download-dialog/free/download?fileSlug="+id;
|
|
||||||
let redirect = await this.inst.get(download_link, {maxRedirects: 0, validateStatus: null});
|
|
||||||
if(redirect.status !== 302) throw new Error(`Status code: ${redirect.status}`);
|
|
||||||
this.tor.torNewSession();
|
|
||||||
if(redirect.headers.location && redirect.headers.location.startsWith("https://download.uloz.to"))
|
|
||||||
return redirect.headers.location;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async captcha_link(id: string): Promise<string | undefined> {
|
async captcha_link(id: string): Promise<string | undefined> {
|
||||||
|
|
||||||
let download_link = "https://uloz.to/download-dialog/free/download?fileSlug="+id;
|
let download_link = "https://uloz.to/download-dialog/free/download?fileSlug="+id;
|
||||||
let captcha_page = await this.inst.get(download_link, {maxRedirects: 0, validateStatus: null});
|
let captcha_page = await this.inst.get(download_link, {maxRedirects: 0, validateStatus: null});
|
||||||
|
|
||||||
|
// Direct link detection
|
||||||
|
if(captcha_page.status == 302) {
|
||||||
|
this.tor.torNewSession();
|
||||||
|
if(captcha_page.headers.location && captcha_page.headers.location.startsWith("https://download"))
|
||||||
|
return captcha_page.headers.location;
|
||||||
|
}
|
||||||
|
|
||||||
if(captcha_page.status !== 200) throw new Error(`Status code: ${captcha_page.status}`);
|
if(captcha_page.status !== 200) throw new Error(`Status code: ${captcha_page.status}`);
|
||||||
let cookies = this.parse_cookie(captcha_page.headers["set-cookie"]);
|
let cookies = this.parse_cookie(captcha_page.headers["set-cookie"]);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ export class UrlPool {
|
||||||
|
|
||||||
file_name?: string;
|
file_name?: string;
|
||||||
total_size: number = 0;
|
total_size: number = 0;
|
||||||
is_direct = false;
|
|
||||||
|
|
||||||
constructor(storage: UrlPoolStorage, id: string) {
|
constructor(storage: UrlPoolStorage, id: string) {
|
||||||
this.valid_to = new Date();
|
this.valid_to = new Date();
|
||||||
|
@ -42,7 +41,6 @@ export class UrlPool {
|
||||||
let dom = new JSDOM(page.data);
|
let dom = new JSDOM(page.data);
|
||||||
// TODO: Add quick download support
|
// TODO: Add quick download support
|
||||||
// let quick_dl_url = links.regex_parse(new RegExp('href="(/quickDownload/[^"]*)"'), page.data, 1);
|
// let quick_dl_url = links.regex_parse(new RegExp('href="(/quickDownload/[^"]*)"'), page.data, 1);
|
||||||
this.is_direct = 'js-free-download-button-direct' == links.regex_parse(new RegExp('data-href="/download-dialog/free/[^"]+" +class=".+(js-free-download-button-direct).+"'), page.data, 1);
|
|
||||||
let filename = dom.window.document.querySelector(".jsFileTitle");
|
let filename = dom.window.document.querySelector(".jsFileTitle");
|
||||||
|
|
||||||
if(filename && filename.textContent) {
|
if(filename && filename.textContent) {
|
||||||
|
@ -117,7 +115,7 @@ export class UrlPool {
|
||||||
async generate(): Promise<string | undefined> {
|
async generate(): Promise<string | undefined> {
|
||||||
this.last_generated = unixtime();
|
this.last_generated = unixtime();
|
||||||
try {
|
try {
|
||||||
let link = await (this.is_direct ? links.direct_link(this.id) : links.captcha_link(this.id));
|
let link = await links.captcha_link(this.id);
|
||||||
if(link) this.add(link);
|
if(link) this.add(link);
|
||||||
return link;
|
return link;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
|
@ -57,10 +57,10 @@ export class Webserver {
|
||||||
|
|
||||||
let d = p.get_downloader(range.from);
|
let d = p.get_downloader(range.from);
|
||||||
|
|
||||||
let contentLength = p.total_size-1-range.from;
|
let contentLength = p.total_size-range.from;
|
||||||
let headers = {
|
let headers = {
|
||||||
"Content-Range": `bytes ${range.from}-${p.total_size-1}/${p.total_size-1}`,
|
"Content-Range": `bytes ${range.from}-${p.total_size-1}/${p.total_size}`,
|
||||||
"Range": `bytes=${range.from}-${p.total_size-1}/${p.total_size-1}`,
|
"Range": `bytes=${range.from}-${p.total_size-1}/${p.total_size}`,
|
||||||
"Accept-Ranges": "bytes",
|
"Accept-Ranges": "bytes",
|
||||||
"Content-Length": contentLength,
|
"Content-Length": contentLength,
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
|
|
Reference in a new issue