From 0eda7a506ddc85808f5bb6294e4d899007068d49 Mon Sep 17 00:00:00 2001 From: Filip Znachor Date: Mon, 14 Mar 2022 20:18:08 +0100 Subject: [PATCH] Added auto captcha and link generating --- README.md | 35 +++++ captcha.py | 53 ++++++++ index.html | 31 ++++- index.ts | 31 +---- links.ts | 84 ++++++++++++ model.tflite | Bin 0 -> 14140796 bytes package.json | 4 +- pnpm-lock.yaml | 355 +++++++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 100 ++++++++++++++ urlpool.ts | 60 ++++++++- webserver.ts | 43 +++--- 11 files changed, 741 insertions(+), 55 deletions(-) create mode 100644 README.md create mode 100644 captcha.py create mode 100644 links.ts create mode 100644 model.tflite create mode 100644 tsconfig.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..8268089 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Ulož.to streamer + +Stream ulož.to video content without downloading + +## Instalation + +### Python libraries + +Install all python libraries for `captcha.py`: + +``` +numpy, requests, tensorflow, PIL +``` + +### Install node modules + +``` +npm i --save +``` + +### Setup Tor proxy + +Set `ControlPort`, `SocksPort` and `HashedControlPassword` in /etc/tor/torrc: + +``` +SocksPort 9050 +ControlPort 9051 +HashedControlPassword 16:872230D6EA809D4760AD5894ADB7A5A07191882EBCD188378544794F8F +``` + +Password can be generated with: + +``` +tor --hash-password giraffe +``` \ No newline at end of file diff --git a/captcha.py b/captcha.py new file mode 100644 index 0000000..217cfcc --- /dev/null +++ b/captcha.py @@ -0,0 +1,53 @@ +import numpy +import requests +import string +import sys +import tensorflow +from io import BytesIO +from PIL import Image + + +def decode(li) -> string: + available_chars = "abcdefghijklmnopqrstuvwxyz" + result = [] + for char in li: + result.append(available_chars[char]) + return "".join(result) + + +def solve(url: string) -> string: + interpreter = tensorflow.lite.Interpreter( + model_content=open("./model.tflite", "rb").read()) + u = requests.get(url) + raw_data = u.content + img = Image.open(BytesIO(raw_data)) + img = numpy.asarray(img) + # normalize to [0...1] + img = (img / 255).astype(numpy.float32) + # convert to grayscale + r, g, b = img[:, :, 0], img[:, :, 1], img[:, :, 2] + gray = 0.299 * r + 0.587 * g + 0.114 * b + # input has nowof shape (70, 175) + # we modify dimensions to match model's input + gray = numpy.expand_dims(gray, 0) + gray = numpy.expand_dims(gray, -1) + # input is now of shape (batch_size, 70, 175, 1) + # output will have shape (batch_size, 4, 26) + interpreter.allocate_tensors() + input_details = interpreter.get_input_details() + output_details = interpreter.get_output_details() + interpreter.set_tensor(input_details[0]['index'], gray) + interpreter.invoke() + # predict and get the output + output = interpreter.get_tensor(output_details[0]['index']) + # now get labels + labels_indices = numpy.argmax(output, axis=2) + decoded_label = [decode(x) for x in labels_indices][0] + return decoded_label + + +try: + result = solve(sys.argv[1]) + print(result, end = "") +except: + pass \ No newline at end of file diff --git a/index.html b/index.html index 6604917..662692d 100644 --- a/index.html +++ b/index.html @@ -1 +1,30 @@ -