Convert to python3

This commit is contained in:
Paweł Płazieński 2023-06-24 23:49:22 +02:00
parent dd857db598
commit aeddbd3e22

22
napi
View file

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# reversed napi 0.16.3.1
# by gim,krzynio,dosiu,hash 2oo8.
@ -7,6 +7,8 @@
import hashlib
import sys
import urllib
from urllib.parse import urlencode
from urllib.request import urlopen
import os
import argparse
import base64
@ -31,10 +33,10 @@ for movie_filename in args.movies:
digest = hashlib.md5()
try:
with open(movie_filename, "r") as movie_file:
with open(movie_filename, "rb") as movie_file:
digest.update(movie_file.read(10 * 1024 * 1024))
except IOError:
print "%s: No such file" % movie_filename
print("%s: No such file" % movie_filename)
continue
movie_digest = digest.hexdigest()
@ -46,14 +48,14 @@ for movie_filename in args.movies:
"downloaded_subtitles_lang" : args.language
}
request_data = urllib.urlencode(request_data)
response = urllib.urlopen(base_url, request_data)
request_data = urlencode(request_data).encode()
response = urlopen(base_url, request_data)
response_data = response.read()
response_xml = XML(response_data)
response_status = response_xml.find('status')
if response_status is None or response_status.text != 'success':
print "%s: No subtitles found for language %s" % (movie_filename, args.language)
print("%s: No subtitles found for language %s" % (movie_filename, args.language))
continue
subtitle_xml = response_xml.find("subtitles")
@ -64,7 +66,7 @@ for movie_filename in args.movies:
content = subtitle_xml.find("content").text
decoded_content = base64.b64decode(content)
with open(input_filename, "w") as input_file:
with open(input_filename, "wb") as input_file:
input_file.write(decoded_content)
subtitle_filename = movie_filename[:-4] + ".srt"
@ -83,10 +85,10 @@ for movie_filename in args.movies:
result = process.wait()
if result != 0:
print "%s: 7zip returned non-zero code: %s" % (movie_filename, subtitle_filename)
print("%s: 7zip returned non-zero code: %s" % (movie_filename, subtitle_filename))
os.remove(subtitle_filename)
continue
print "%s: downloaded subtitles: language '%s', uploader '%s', author '%s', date '%s'" % (movie_filename,
args.language, subtitle_uploader, subtitle_author, subtitle_date)
print("%s: downloaded subtitles: language '%s', uploader '%s', author '%s', date '%s'" % (movie_filename,
args.language, subtitle_uploader, subtitle_author, subtitle_date))
os.remove(input_filename)