Skip to content

Instantly share code, notes, and snippets.

@mkaflowski
Last active February 27, 2021 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkaflowski/f9bb66a6b412f3d1eb65ac3e6e1d7de2 to your computer and use it in GitHub Desktop.
Save mkaflowski/f9bb66a6b412f3d1eb65ac3e6e1d7de2 to your computer and use it in GitHub Desktop.
pobieranie napisów z napiprojekt
import base64
import hashlib
import os
import sys
import urllib.request
from xml.dom import minidom
import requests
def download(movieFile, md5hash, language="PL"):
url = "http://napiprojekt.pl/api/api-napiprojekt3.php"
values = {
"mode": "1",
# "client":"NapiTux",
"client": "NapiProjektPython",
"client_ver": "0.1",
"downloaded_subtitles_id": md5hash,
"downloaded_subtitles_txt": "1",
"downloaded_subtitles_lang": language
}
try:
# data = parse.urlencode(values).encode()
response = requests.post(url, data=values).text
DOMTree = minidom.parseString(response)
cNodes = DOMTree.childNodes
if cNodes[0].getElementsByTagName("status"):
text = base64.b64decode(
cNodes[0].getElementsByTagName("subtitles")[0].getElementsByTagName("content")[0].childNodes[
0].data)
filename = os.path.splitext(movieFile)[0] + ".txt"
open(filename, "wb").write(text)
return filename
except Exception as e:
print(e)
pass
return None
def f(z):
idx = [0xe, 0x3, 0x6, 0x8, 0x2]
mul = [2, 2, 5, 4, 3]
add = [0, 0xd, 0x10, 0xb, 0x5]
b = []
for i in range(len(idx)):
a = add[i]
m = mul[i]
i = idx[i]
t = a + int(z[i], 16)
v = int(z[t:t + 2], 16)
b.append(("%x" % (v * m))[-1])
return ''.join(b)
if len(sys.argv) == 1:
print("nie podano pliku")
sys.exit(2)
d = hashlib.md5()
print(sys.argv[1])
d.update(open(sys.argv[1], 'rb').read(10485760))
searchUrl = "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f=" + d.hexdigest() + "&t=" + f(
d.hexdigest()) + "&v=other&kolejka=false&nick=&pass=&napios=" + os.name
subs = urllib.request.urlopen(searchUrl).read()
if subs[0:3] == b'NPc':
print("Nie znaleziono napisów")
sys.exit(2)
download(sys.argv[1], d.hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment