diff --git a/README.md b/README.md index 8268089..9db36a4 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,34 @@ -# Ulož.to streamer +# Ulož.to Rychle -Stream ulož.to video content without downloading +Program na streamování a stahování obsahu z Ulož.to vysokou rychlostí. -## Instalation +## Instalace -### Python libraries +### Captcha solver -Install all python libraries for `captcha.py`: +Pro automatické řešení captchi používáme script `captcha.py`, pro nějž je potřeba nainstalovat Python a následující knihovny. -``` -numpy, requests, tensorflow, PIL +```sh +pip install requests tflite_runtime Pillow ``` -### Install node modules +Může se stát, že v nejnovější verzi Pythonu není **tflite_runtime** dostupný. Doporučujeme proto nainstalovat např. Python 3.9 a vytvořit spustitelný soubor pomocí programu **pyinstaller**. +```sh +pyinstaller captcha.py --onefile ``` + +### Instalce node modulů + +Pro spuštění projektu je potřeba nainstalovat **Node.js** a následně potřebné knihovny pomocí tohoto příkazu. + +```sh npm i --save ``` -### Setup Tor proxy +### Nastavení Tor proxy -Set `ControlPort`, `SocksPort` and `HashedControlPassword` in /etc/tor/torrc: +V konfiguračním souboru `/etc/tor/torrc` nastavte hodnoty `ControlPort`, `SocksPort` a `HashedControlPassword`. ``` SocksPort 9050 @@ -28,7 +36,7 @@ ControlPort 9051 HashedControlPassword 16:872230D6EA809D4760AD5894ADB7A5A07191882EBCD188378544794F8F ``` -Password can be generated with: +Hesla ke control portu je možno generovat následovně. ``` tor --hash-password giraffe diff --git a/captcha.py b/captcha.py index 217cfcc..bde2aa2 100644 --- a/captcha.py +++ b/captcha.py @@ -2,7 +2,8 @@ import numpy import requests import string import sys -import tensorflow +#import tensorflow +import tflite_runtime.interpreter as tflite from io import BytesIO from PIL import Image @@ -16,7 +17,8 @@ def decode(li) -> string: def solve(url: string) -> string: - interpreter = tensorflow.lite.Interpreter( + # for tensorflow tensorflow.lite.Interpreter + interpreter = tflite.Interpreter( model_content=open("./model.tflite", "rb").read()) u = requests.get(url) raw_data = u.content @@ -48,6 +50,6 @@ def solve(url: string) -> string: try: result = solve(sys.argv[1]) - print(result, end = "") + print(result, end="") except: - pass \ No newline at end of file + pass \ No newline at end of file diff --git a/links.ts b/links.ts index 1fd7780..7486b71 100644 --- a/links.ts +++ b/links.ts @@ -92,7 +92,7 @@ export class Links { async captcha(url: string): Promise { return new Promise((resolve) => { - exec("python3 captcha.py "+url, (e, o) => { + exec("./captcha "+url, (e, o) => { resolve(o); }); }); diff --git a/urlpool.ts b/urlpool.ts index 5cf170f..cb754d6 100644 --- a/urlpool.ts +++ b/urlpool.ts @@ -5,9 +5,9 @@ import { random_int } from "./tools"; let links = new Links; -function sleep(ms: number) { - return new Promise(resolve => setTimeout(resolve, ms)); -} +let unixtime = () => { + return new Date().getTime()/1000; +}; export class UrlPool { @@ -20,11 +20,11 @@ export class UrlPool { valid_to: Date; generating = false; + last_generated: number = unixtime(); downloaders: Downloader[] = []; total_size: number = 0; is_direct = false; - ready = false; constructor(storage: UrlPoolStorage, id: string) { this.valid_to = new Date(); @@ -53,7 +53,7 @@ export class UrlPool { this.total_size = parseInt(r.headers["content-range"].split("/")[1]); this.return(url[0]); - this.ready = true; + this.generating = true; return true; } @@ -75,6 +75,8 @@ export class UrlPool { if(url) { clearInterval(check); complete(url); + } else { + this.request_generation(); } }, 100); }); @@ -99,16 +101,13 @@ export class UrlPool { return count ? available.slice(0, count) : available; } - async start_generation() { - this.generating = true; - while(this.urls.length < 15 && this.generating) { - console.log(this.id, "| new link:", (await this.generate()) ? true : false); - await sleep(2000); - } - this.generating = false; + async request_generation() { + if(!this.generating || this.last_generated+10 > unixtime()) return; + console.log(this.id, "| new link:", (await this.generate()) ? true : false); } async generate(): Promise { + this.last_generated = unixtime(); try { let link = await (this.is_direct ? links.direct_link(this.id) : links.captcha_link(this.id)); if(link) this.add(link); @@ -159,7 +158,7 @@ export class UrlPoolStorage { let pool = new UrlPool(this, id); let check = await pool.init(); if(!check) return undefined; - pool.start_generation(); + pool.request_generation(); this.pools[id] = pool; return pool; } diff --git a/webserver.ts b/webserver.ts index ed2b198..21c2385 100644 --- a/webserver.ts +++ b/webserver.ts @@ -30,9 +30,9 @@ export class Webserver { total: p.urls.length, available: p.available().length, generating: p.generating, - urls: p.urls, total_size: p.total_size, - downloaders: p.downloaders.length + downloaders: p.downloaders.length, + urls: p.urls } })); res.end();