#!/usr/bin/python # reversed napi 0.16.3.1 # # by gim,krzynio,dosiu,hash 2oo8. # # # # last modified: 6-I-2oo8 # # 4pc0h f0rc3 # # do dzialania potrzebny jest p7zip-full (tak sie nazywa paczka w debianie) # # POZDRAWIAMY NASZYCH FANOW! import hashlib import sys import urllib import os import xml.etree.ElementTree as ET import base64 import subprocess base_url = "http://napiprojekt.pl/api/api-napiprojekt3.php" password = "iBlm8NTigvru0Jr0" input_filename = '/tmp/napi-temp-file' from getopt import getopt opts, args = getopt(sys.argv[1:], '', ['language=']) language = "PL" for optname, optvalue in opts: if optname == '--language': language = optvalue if len(args) < 1: print "usage: %s " % (sys.argv[0],) sys.exit(0) for movie_filename in args: digest = hashlib.md5() try: with open(movie_filename, "r") as movie_file: digest.update(movie_file.read(10 * 1024 * 1024)) except IOError: print "%s: No such file" % movie_filename continue movie_digest = digest.hexdigest() request_data = { "downloaded_subtitles_id" : movie_digest, "mode" : "31", "client" : "NapiProjekt", "downloaded_subtitles_lang" : language } try: request_data = urllib.urlencode(request_data) response = urllib.urlopen(base_url, request_data) response_xml = ET.XML(response.read()) content = response_xml.find("subtitles").find("content").text except: print "%s: No subtitles" % (movie_filename,) sys.exit(2) decoded_content = base64.b64decode(content) with open(input_filename, "w") as input_file: input_file.write(decoded_content) subtitle_filename = movie_filename[:-4] + ".srt" executed = [ '/usr/bin/7z', # executable 'x', # command: extract '-p' + password, # use password '-y', # assume yes on all queries '-so', # into standard out input_filename, # input file ] with open(subtitle_filename, "w") as subtitle_file: process = subprocess.Popen(executed, stdout=subtitle_file) result = process.wait() if result != 0: print "%s: 7zip returned non-zero code: %s" % (movie_filename, subtitle_filename) os.remove(subtitle_filename) sys.exit(3) print "%s: Subtitles fetched successfully to %s" % (movie_filename, subtitle_filename) os.remove(input_filename)