From 791a1b50e877c6187356324d0e7d4da7189f8e6e Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 12 Aug 2018 17:55:00 +0200 Subject: [PATCH 01/77] ported script to python 3, corrected tab/spaces and formatting to match PEP rules --- napiprojekt.py | 62 +++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/napiprojekt.py b/napiprojekt.py index e72e86c..1c93159 100755 --- a/napiprojekt.py +++ b/napiprojekt.py @@ -1,44 +1,48 @@ -#!/usr/bin/python +#!/usr/bin/python3 + # # Script downloads subtitles from napiprojekt # # based on older script # by gim,krzynio,dosiu,hash 2oo8. -# last modified: 6-I-2oo8 +# last modified: 2018-08-12 # 4pc0h f0rc3 -import md5, sys, urllib, os +import sys +from urllib import request +import os +import hashlib from tempfile import NamedTemporaryFile from subprocess import Popen, PIPE def f(z): - idx = [ 0xe, 0x3, 0x6, 0x8, 0x2 ] - mul = [ 2, 2, 5, 4, 3 ] - add = [ 0, 0xd, 0x10, 0xb, 0x5 ] + idx = [0xe, 0x3, 0x6, 0x8, 0x2] + mul = [2, 2, 5, 4, 3] + add = [0, 0xd, 0x10, 0xb, 0x5] - b = [] - for i in xrange(len(idx)): - a = add[i] - m = mul[i] - i = idx[i] + 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] ) + t = a + int(z[i], 16) + v = int(z[t:t + 2], 16) + b.append(("%x" % (v * m))[-1]) - return "".join(b) + return "".join(b) def napiurl(path): - d = md5.new(); - d.update(open(path).read(10485760)) + d = hashlib.md5() + d.update(open(path, mode='rb').read(10485760)) h = d.hexdigest() return "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&" + \ - "f=" + h + "&t=" + f(h) + \ - "&v=other&kolejka=false&nick=&pass=&napios=" + os.name + "f=" + h + "&t=" + f(h) + \ + "&v=other&kolejka=false&nick=&pass=&napios=" + os.name class Un7ZipError(Exception): @@ -56,13 +60,13 @@ def un7zip(archive, password=None, tmpfileprefix="un7zip", tmpfilesuffix=".7z"): cmd += [tmpfile.name] sp = Popen(cmd, stdout=PIPE, stderr=PIPE) - + content = sp.communicate()[0] if sp.wait() != 0: raise Un7ZipError("Invalid archive") - tmpfile.close() # deletes the file + tmpfile.close() # deletes the file return content @@ -77,7 +81,7 @@ class NoMatchingSubtitle(Exception): def download_subtitle(filename): url = napiurl(filename) - content_7z = urllib.urlopen(url).read() + content_7z = request.urlopen(url).read() try: content = un7zip(content_7z, password="iBlm8NTigvru0Jr0") except Un7ZipError: @@ -85,17 +89,17 @@ def download_subtitle(filename): # Don't override the same subtitles try: - same = open(subtitlepath(filename), "r").read() == content + same = open(subtitlepath(filename), "rb").read() == content except IOError: same = False if not same: - open(subtitlepath(filename), "w").write(content) + open(subtitlepath(filename), "wb").write(content) def main(): if len(sys.argv) < 2: - sys.stderr.write("\nUSAGE:\n\t" + sys.argv[0] + " moviefile [moviefile, ...]\n\n") + print("\nUSAGE:\n\t" + sys.argv[0] + " moviefile [moviefile, ...]\n\n") exit(1) failed = False @@ -103,15 +107,15 @@ def main(): for arg in sys.argv[1:]: try: download_subtitle(arg) - print "OK " + arg + print("OK " + arg) except NoMatchingSubtitle: failed = True - print "NOSUBS " + arg + print("NOSUBS " + arg) except IOError: - sys.stderr.write("Cannot read file " + arg + "\n") + print("Cannot read file " + arg + "\n") exit(2) except OSError: - print "OS error. Is 7z in PATH?" + print("OS error. Is 7z in PATH?") exit(4) if failed: From 7b73e21e4ac2bde4fd3535b905b1ea1f28150ffd Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 12 Aug 2018 18:04:18 +0200 Subject: [PATCH 02/77] few more renames and method extractions to increase readability --- napiprojekt.py | 58 ++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/napiprojekt.py b/napiprojekt.py index 1c93159..8e03d49 100755 --- a/napiprojekt.py +++ b/napiprojekt.py @@ -16,6 +16,9 @@ from tempfile import NamedTemporaryFile from subprocess import Popen, PIPE +SIZE_10_MBs_IN_BYTES = 10485760 +NAPI_ARCHIVE_PASSWORD = "iBlm8NTigvru0Jr0" + def f(z): idx = [0xe, 0x3, 0x6, 0x8, 0x2] @@ -35,29 +38,32 @@ def f(z): return "".join(b) -def napiurl(path): - d = hashlib.md5() - d.update(open(path, mode='rb').read(10485760)) - h = d.hexdigest() +def build_url(movie_path): + movie_hash = calc_movie_hash_as_hex(movie_path) + url = "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f={}&t={}&v=other&kolejka=false&nick=&pass=&napios={}".format( + movie_hash, f(movie_hash), os.name) + return url + - return "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&" + \ - "f=" + h + "&t=" + f(h) + \ - "&v=other&kolejka=false&nick=&pass=&napios=" + os.name +def calc_movie_hash_as_hex(movie_path): + md5_hash_gen = hashlib.md5() + md5_hash_gen.update(open(movie_path, mode='rb').read(SIZE_10_MBs_IN_BYTES)) + return md5_hash_gen.hexdigest() class Un7ZipError(Exception): pass -def un7zip(archive, password=None, tmpfileprefix="un7zip", tmpfilesuffix=".7z"): - tmpfile = NamedTemporaryFile(prefix=tmpfileprefix, suffix=tmpfilesuffix) - tmpfile.write(archive) - tmpfile.flush() +def un7zip(archive, password=None, tmp_file_prefix="un7zip", tmp_file_suffix=".7z"): + tmp_file = NamedTemporaryFile(prefix=tmp_file_prefix, suffix=tmp_file_suffix) + tmp_file.write(archive) + tmp_file.flush() cmd = ["7z", "x", "-y", "-so"] if password is not None: cmd += ["-p" + password] - cmd += [tmpfile.name] + cmd += [tmp_file.name] sp = Popen(cmd, stdout=PIPE, stderr=PIPE) @@ -66,12 +72,12 @@ def un7zip(archive, password=None, tmpfileprefix="un7zip", tmpfilesuffix=".7z"): if sp.wait() != 0: raise Un7ZipError("Invalid archive") - tmpfile.close() # deletes the file + tmp_file.close() # deletes the file return content -def subtitlepath(moviepath): - filename, fileext = os.path.splitext(moviepath) +def get_path_for_subtitle(movie_path): + filename, extension = os.path.splitext(movie_path) return filename + ".txt" @@ -79,22 +85,22 @@ class NoMatchingSubtitle(Exception): pass -def download_subtitle(filename): - url = napiurl(filename) - content_7z = request.urlopen(url).read() +def download_subtitle(movie_path): + napi_url = build_url(movie_path) + content_7z = request.urlopen(napi_url).read() try: - content = un7zip(content_7z, password="iBlm8NTigvru0Jr0") + content = un7zip(content_7z, password=NAPI_ARCHIVE_PASSWORD) except Un7ZipError: raise NoMatchingSubtitle("No matching subtitle") # Don't override the same subtitles try: - same = open(subtitlepath(filename), "rb").read() == content + same = open(get_path_for_subtitle(movie_path), "rb").read() == content except IOError: same = False if not same: - open(subtitlepath(filename), "wb").write(content) + open(get_path_for_subtitle(movie_path), "wb").write(content) def main(): @@ -104,15 +110,15 @@ def main(): failed = False try: - for arg in sys.argv[1:]: + for movie_path in sys.argv[1:]: try: - download_subtitle(arg) - print("OK " + arg) + download_subtitle(movie_path) + print("OK " + movie_path) except NoMatchingSubtitle: failed = True - print("NOSUBS " + arg) + print("No subtitles for: " + movie_path) except IOError: - print("Cannot read file " + arg + "\n") + print("Cannot read file " + movie_path + "\n") exit(2) except OSError: print("OS error. Is 7z in PATH?") From cc0f2c4a7b531284658e47ad95cf1c7f7dd5f54d Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 12 Aug 2018 18:15:55 +0200 Subject: [PATCH 03/77] changed main loop strategy to best-effort, extracted exit codes as constants, few more renames, omitted checking if subtitle is already downloaded - what's the point if new subtitle is already in memory? --- napiprojekt.py | 55 ++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/napiprojekt.py b/napiprojekt.py index 8e03d49..a3ba3da 100755 --- a/napiprojekt.py +++ b/napiprojekt.py @@ -16,6 +16,12 @@ from tempfile import NamedTemporaryFile from subprocess import Popen, PIPE +EXIT_CODE_WRONG_ARG_NUMBER = 1 +EXIT_CODE_LACK_OF_7Z_ON_PATH = 4 +EXIT_CODE_FAILED = 8 + +TMP_FILE_SUFFIX = ".7z" +TMP_FILE_PREFIX = "un7zip" SIZE_10_MBs_IN_BYTES = 10485760 NAPI_ARCHIVE_PASSWORD = "iBlm8NTigvru0Jr0" @@ -38,8 +44,7 @@ def f(z): return "".join(b) -def build_url(movie_path): - movie_hash = calc_movie_hash_as_hex(movie_path) +def build_url(movie_hash): url = "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f={}&t={}&v=other&kolejka=false&nick=&pass=&napios={}".format( movie_hash, f(movie_hash), os.name) return url @@ -55,8 +60,8 @@ class Un7ZipError(Exception): pass -def un7zip(archive, password=None, tmp_file_prefix="un7zip", tmp_file_suffix=".7z"): - tmp_file = NamedTemporaryFile(prefix=tmp_file_prefix, suffix=tmp_file_suffix) +def un7zip(archive, password=None): + tmp_file = NamedTemporaryFile(prefix=TMP_FILE_PREFIX, suffix=TMP_FILE_SUFFIX) tmp_file.write(archive) tmp_file.flush() @@ -76,7 +81,7 @@ def un7zip(archive, password=None, tmp_file_prefix="un7zip", tmp_file_suffix=".7 return content -def get_path_for_subtitle(movie_path): +def get_target_path_for_subtitle(movie_path): filename, extension = os.path.splitext(movie_path) return filename + ".txt" @@ -85,47 +90,45 @@ class NoMatchingSubtitle(Exception): pass -def download_subtitle(movie_path): - napi_url = build_url(movie_path) - content_7z = request.urlopen(napi_url).read() +def un7zip_api_response(content_7z): try: content = un7zip(content_7z, password=NAPI_ARCHIVE_PASSWORD) except Un7ZipError: raise NoMatchingSubtitle("No matching subtitle") + return content - # Don't override the same subtitles - try: - same = open(get_path_for_subtitle(movie_path), "rb").read() == content - except IOError: - same = False - if not same: - open(get_path_for_subtitle(movie_path), "wb").write(content) +def download_subtitle(movie_path): + movie_hash = calc_movie_hash_as_hex(movie_path) + napi_subs_dl_url = build_url(movie_hash) + content_7z = request.urlopen(napi_subs_dl_url).read() + sub_content = un7zip_api_response(content_7z) + open(get_target_path_for_subtitle(movie_path), "wb").write(sub_content) def main(): if len(sys.argv) < 2: print("\nUSAGE:\n\t" + sys.argv[0] + " moviefile [moviefile, ...]\n\n") - exit(1) + exit(EXIT_CODE_WRONG_ARG_NUMBER) - failed = False + any_failure = False try: - for movie_path in sys.argv[1:]: + for index, movie_path in enumerate(sys.argv[1:]): + print("{} / {} | Downloading subtitles for {} ...".format(index + 1, len(sys.argv[1:]), movie_path)) try: download_subtitle(movie_path) - print("OK " + movie_path) + print("Success!") except NoMatchingSubtitle: - failed = True - print("No subtitles for: " + movie_path) + any_failure = True + print("No subtitles found!") except IOError: - print("Cannot read file " + movie_path + "\n") - exit(2) + print("Cannot read movie file!") except OSError: print("OS error. Is 7z in PATH?") - exit(4) + exit(EXIT_CODE_LACK_OF_7Z_ON_PATH) - if failed: - exit(8) + if any_failure: + exit(EXIT_CODE_FAILED) if __name__ == "__main__": From 583f3df84958dc1d65ace8991d440f755ca65796 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 12 Aug 2018 18:31:21 +0200 Subject: [PATCH 04/77] added basic unit tests for generating hashes and for unpacking 7zipped content returned from NapiProjektApi --- napiprojekt.py | 23 +++++++++++------------ test.py | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 test.py diff --git a/napiprojekt.py b/napiprojekt.py index a3ba3da..9f2e7e2 100755 --- a/napiprojekt.py +++ b/napiprojekt.py @@ -45,9 +45,8 @@ def f(z): def build_url(movie_hash): - url = "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f={}&t={}&v=other&kolejka=false&nick=&pass=&napios={}".format( + return "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f={}&t={}&v=other&kolejka=false&nick=&pass=&napios={}".format( movie_hash, f(movie_hash), os.name) - return url def calc_movie_hash_as_hex(movie_path): @@ -106,30 +105,30 @@ def download_subtitle(movie_path): open(get_target_path_for_subtitle(movie_path), "wb").write(sub_content) -def main(): - if len(sys.argv) < 2: - print("\nUSAGE:\n\t" + sys.argv[0] + " moviefile [moviefile, ...]\n\n") +def main(args): + if len(args) < 1: + print("\nUSAGE:\n\tnapiprojekt.py moviefile [moviefile, ...]\n\n") exit(EXIT_CODE_WRONG_ARG_NUMBER) any_failure = False try: - for index, movie_path in enumerate(sys.argv[1:]): - print("{} / {} | Downloading subtitles for {} ...".format(index + 1, len(sys.argv[1:]), movie_path)) + for index, movie_path in enumerate(args): + print("{}/{} | Downloading subtitles for {} ...".format(index + 1, len(args), movie_path)) try: download_subtitle(movie_path) - print("Success!") + print("{}/{} | Success!".format(index + 1, len(args))) except NoMatchingSubtitle: any_failure = True - print("No subtitles found!") + print("{}/{} | No subtitles found!".format(index + 1, len(args))) except IOError: - print("Cannot read movie file!") + print("{}/{} | Cannot read movie file!".format(index + 1, len(args))) except OSError: print("OS error. Is 7z in PATH?") exit(EXIT_CODE_LACK_OF_7Z_ON_PATH) - if any_failure: exit(EXIT_CODE_FAILED) if __name__ == "__main__": - main() + program_args = sys.argv[1:] + main(program_args) diff --git a/test.py b/test.py new file mode 100644 index 0000000..a86c123 --- /dev/null +++ b/test.py @@ -0,0 +1,21 @@ +import os +import unittest + +from napiprojekt import build_url, un7zip_api_response + + +class NapiPyTest(unittest.TestCase): + def test_should_generate_correct_url(self): + movie_hash = '6e7d92a7c0f40706067248d50d3b1d5a' + expected_url = 'http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f=6e7d92a7c0f40706067248d50d3b1d5a&t=c6705&v=other&kolejka=false&nick=&pass=&napios={}'.format( + os.name) + actual_url = build_url(movie_hash) + self.assertEqual(expected_url, actual_url) + + def test_should_unpack_downloaded_7zip(self): + compressed_subtitles_file_name = 'DunkirkSubtitles.7zip' + with open(compressed_subtitles_file_name, 'rb') as input_file: + compressed_content = input_file.read() + content = un7zip_api_response(compressed_content) + self.assertIn(b"GrupaHatak.pl", content) + print(content) From c4000e2b4abac15e4ee95be3142b8a3b1c18d55c Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 12 Aug 2018 18:41:16 +0200 Subject: [PATCH 05/77] added 7zipped subtitles for unit-testing purposes, implemented encoding of subtitles so they're proper unicodes, added test for the encoding --- DunkirkSubtitles.7zip | Bin 0 -> 9929 bytes napiprojekt.py | 11 ++++++++--- test.py | 22 ++++++++++++++++------ 3 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 DunkirkSubtitles.7zip diff --git a/DunkirkSubtitles.7zip b/DunkirkSubtitles.7zip new file mode 100644 index 0000000000000000000000000000000000000000..71328d7f6236588876e25031ac317c3544a58d90 GIT binary patch literal 9929 zcmV;)CN|kOdc3bE8~_7PSPJbBCIA2c0001)000000002IKijjK5+!g$Sr+$}J^YF) zX2M7CpHIPr=%j^bOQ`9;C>*SrpBS^mBaw8 zSrUr+AqcPO9S*hrF@m=)QCs2>cdV{u6eU*EPr0cCmZ0ram#DqNl4YDkNCt)*{;8A- zTUOEuIkKBod@4wNr%_IjZ6ppV>CoA3f{2-M!WfpwC>iP}{c^{SV_-4fDx25GlEr%% z9>n2N@0A@tQE&HlNR{vWZCoQnRlfzzq&o4EL-0~2)-}4B&G}N$_f@#ei!}}a2R$@G z@nu5a$XV8NJEjF?PqadcaZG@e0 zLCe4la##d6kI(8EKlfq!LH8*Dkc_uR;TY8=j%_bnhVwe?p#p2WK&yUW=o%7V3Lq)T{Z*^biJx%F+aC%9E2V(}WJ@0IEC1t_}_krBW{)K@CmYWKt z2~I(TrrlK8#1D5^J{f;f&-co=q0H?58R_gVXzAJ~!xK!c41;m0@fSg{=+d-E{aZ_U z-khdUWEf%;8)PV!z_>Vp{Foc|#Bda3a-i#&p|39kJUAMj7A(b*zL!T9(c!o}J8M>5 z26AvtE75zvBG?lvDnWat$j1i$P$8!np-2DEEl;Ni3L+(R12Fan+*9nl2-9l4h#Bwo zyDEa(yH^BOmH8r4SWSVwVz@mkH#6g_ymRP?qz~FhJOqw zRDGf&dCGBAV0Nck+}Grf;Ol+`qZ^31J)#>YsNHBy3B=P4xxtZ^%;k+ev*N=JP%09hE+25&g#gNc3#lRq4*m2jmTETH*H_yC;?xpt7P|GwoP*KAiTBEc=U?DxN)|Cx zV%b1ThMhT##fd_r5z=%%u_l?E;ZM2Y=JKKOAabTzz%s`@ zE74<5VM}jIe#g_7?aP}ZzCnMF58yb*EmENm!Eaf8-x8OG0yP3CeS!(cQVt4aY>INY zj;Fr1MG{8%*ehL3inhJFLt&sL9U4qOjdKzEiLTYE@0h+DwCeJAbus4y2RJP7+wQg` zkn)-Zg4!iM@!!gyIu$>|=8#*&*_6A*0YQHaNuhOxT)(G{NT8?TpQg1~;J0m%o^I|<_7jzsdM=f6P_DHa+)OAtZ^+b0))%U}f#O5vlS*rW%Z z1O+IlMH2E;@xu7ppk&U!C7A}HxJ>(YFwg5pW-50H7r+GOyXoXWyq7J zWVl?$t$K7@lH%MoZKcBI9_Q?(M;OyQ@v4cjA9m$u`l}h`M-A`PjxVfOjNT zdGLok9kAP`OnA)9ja|_k5;FNq$d6y*GX`2ZDxt=8aSd0qV>&<`7s*sC`n3fsK&T*x zhP(LuBVmdF(92H2EXc$@A4N+=Pd8jTXw195=o-|fIua0{XUl!3Aw4aL(8UBX1N`tg z$P>rFU~tuYTAS==xPSsUJw@1HfNSk?QD9TqaGCUo4xc{lNiR+Hx&`QaR_?}6mY$tE z90D}&Xqk9aV>>qmWXfs7tMZUebL~@=P*`uh8zEr~rOHY$SL`pa{^izH5+7H$s7&#` zqVWuDmEMK@d|!=3uUzjIGdJs%ORm*gs}XJvD!|01yRgB8QR`mQmz&_{W$Ql~qF@qR zJ6)tf`m(5H2m$1o;MLG*sc+zf!s$N3F$mo!9t`UU-|iQXy41iuY4G=*0z^j^q=qpN z)?5YwJ0RSv319g0YA>#tSu`!=a>F%sC0x;9hFWQ;*gw}pGw|I6161>Q*?eAce_x@N z^3kQ6(fc92b&htOP)4`FT*1bl@=I=jLy#9+%Tv69VX}%h2fBetNnc=+jYf7?Ja>?n zdm*PSn9!(;=?j`S5Thf_n1X}MQqVPDuy1vgru;JGGs8kpFNC~am=C&3aZ+TN-*nES z<)2(TuN-9s|NF4l(#dGZQX4t!~Jy< zq73;0)(~7+YUdnAZ@kGY%oROvd^ zHr-k}M|{s&mHtjD0-*h7TgO4mu=lI?5y0EY-NUv1TtwDQtkc^@3HKYV#_~|GRkcAQ z ztFIFF2FLH@*&EM*5s|@pS0WmRc>VLMnR(~E{TO4!0q#h|o74%wQ__r!D@}8nqctWI zywjxzWrnylwmK%1m0XuUuQjiwgVmh+dRG?QM1css2*OP~yiy zxOGmFD|(^(Uo#7>Q4&;x02|{6yX|+3Kh7W_=WC7$!)=?=@Ib2kg|=gSJ@7lS`L}2p z{7qD#E+{o~LO@o%>4jdM_qlUifA7?y3ObxVd2F~FM2V*rOC2lHE7ZIU9YU1%bzzby zfSjyuk7%0y8DGtnM!cGIT)R>@HGm7+8@r_sv2JFUhcq{0i@0nr zyeZ++YeKo5jwb(B0!*`vIq(gK7S-D32P$H1QXHH&n`5taaJvm7LePY@z;I9@H%)v1 z(FjRAKJ_-RcbjAy&J{`r%-3#*=J6SgX4zFiB{LX10KQllM=NT1Pd6n{kwe4MUzKTU z|G{{x>(#FAtleoHMETxL!^Y=)k4}E)D2-$1(Gv+<3b3Y94f-ybj-fehhnh6D`S#(5 zBbm}*e&Sp&@6irvN~nsq+$qDYfhg2x5e3}ey^}v;cUvmdO{e9nL39EcR0@@3E9#FT zq2h+ne1!T(VN92|0NfBaY9BSyr$2LXtA=q-S$=qLuS#bhc_C59bhi+`{*JPsGwK7T zRDZXEkoit;P{MFki0Q>3qPL=AoGbMpK~?O)%*A%5O)&x@xbw+SzK-``Z<^F(Bd_?v ztcT;k8$9oG*P{eWCXfFZn$%NR-m}{D>+}Iz>(s~4RgB!qqHL|-ZeY7_Zd7W{he>}T z`{Pf14J#iu#jLpkmvP_iOVYj08BYF?j2^|lU&epB6Trrhc7eyLmvU5YRZw>t>8OE$ z!r=VLYB1v)tTG{$ow9ap{i_s@Si`Fb(P%S2mqR@`yaEZDH>xfxM-Cit^Og)Sy`*cW zfgs%)0EiLlNem+vuF;YDW#$^)h*`Tmq;9H-<$;r(brH8I%ODP_BF*eUuo8@#Rj*)JQbQy{FC2=`?s-hl)^8Q89kK1t$y%+x%ATiia{ML^Bx&w z$t00+qgp*zT2NVAd$vnx@vbE{2VMe8*#1@sUan0?A^VsIV|wV?Qhfuzi;}u2?tJ~b zp@`INFyKB?Wk4cXi`$K5Zf)uKMcvwetA=7riqn=@^oXA)+(EA|

56@)|<>-%0N|TVpNXGePL|(@WJGw_UH~f2I%i3 zIu~*Bm%J&70vRS8X5Gs}eKp-ROr~Phk%>X-JmHXHxvD!_2OLVJte+(5O*KS$HLYQz z%&|5IU7ws~f72tG^zd@Zrwz_hX&Hp`@>xv21>gcQa60+%V|rMxZZfM9_);5p&EdW`VEkQ~FXa{QW6t_M>%-oU^RAn#M&XEFygf!- z{k_KONso-DYphb|S1n^)yXlLG+0?FlET~8oKN@#$%mJ7bX{=l-CQ_3B@ZWuGj zxL2cs>elNaffdsE6nd?x%+Q$bH;UjJ8mC{+rfDoR=ZZSF*BI3iJOYlwe2+?F%g~yC zrsnHv&y6ZWPDV|+HpjY!V+mv*m|Ey+P}sz$C};-dy__7Q08 z3gN-5P>7#>-2HM(C8zq^6%BJBTc#O`Mg_!4z*O)%VV&~>hTiSXTLYy}J;bg`1xc2! z#an+-kdlh8nb?{loE^^wsR_?{Y3&4!46vmQ@!WTn>W1?GDTEA>^ESNH6t?310`Nt{ zr)ZB*WawWO7KF+Kr3*#JXj!e&H%bMecBw{zT`fV71qC{wb$;GG$^5Cz(eRL&FYo-V zo$VhE%~9v}%Yc%C*&jeXo+APYtbf|0 zzv#QTK?|+xRlo5hjHZB7OR1)x)wC)fv;l(KjZ5o zLeZIg!P|K859M|RO+qf}RhjpQbK9}^%@uFZ?G=S1?56Ylm}3TPz7T|jB(s)8MwA>5 zE|7kFK|&&$JA933_wvTx5YW}VtWF3ZTN39wxlY)Hwb->6J2OAP-mAwoe*_p^sc0l& zJHnDt{~z9CCf;QITv?tZh==QLbrEhHL9x<{8d{Tn#+Z*fa(cjP#+;Yprd+QRj#TCe zXZ-s{F4=I@&OoqV$W-I^ljMpmacZ0(ot9pj)*bMm`En<}e+9yLpjFvGb+&tDyCu%$ z3Sv7*y}pYHXdu9&U`O=Wv?=%y^2YjtPyYPGO{-8l+4xDn$rPt8bjQ({sl*7w)B}g8 zeUY#pN{cpRIn7|(`6GAuSQOL{E?3!6G?t*9K=z*>vNtQm&qdBRPxYNqBH4Q&`sHpL zYK@ferHlvNXy#b1wQwuIv#K8awv1mQ z{F8k4(xP91ua$FNtVAdUm9fbJBixwJk(yOhs1@?1#quo7 zSPL)wXg8FRb!$~9T!i_QJUYKArbRGu;QBPfORqd|xB{Ve{;-Opy>QBn$tWlVxatYPjWh<#p*YKZMC z)|<^qTFiqnX10<5R}0X7!iD})s|f_0V`fji39+aY*3=lEM^;NQQYv`<2qeHoHJS)~ z%XKuPSb=$0)Bqrsua?OqPRL7xH2Bp-W5&lZdc>aMx)+D+suNIW>ONc9znb@g1eyes z?aV2B+a9s{Tw&?Z2NwNsjOiys-)v%nDPPkYhp`LG7pW0r3|cWRm@xwqVPyomKzk-_ z0#M!XhPe;2;w~x1b|JNMq2qlhJan;$Ql!O0N_bqiG!6W}WnaNo4cv-H9OVgYWR|w2B|tNB6G` zcoSv$O+fO~V#qOsO*`Pu0qW1F{c(VikOkaC)L3b_s2QO|odfG19A9bNW8$Qq6J#Px z0%Mghu(G}(+JN}=JHfbOFSrZk@2AE>-b%e$`m~Xe2iXVWbtu`*b0Fg4`nZNT zDP24)&ity~XnEra7xrE1v=d_g)%jmqz!Ale+i|-tBxqFUEX#(or~uX8BD^%qtUT`S zUeOW1w8=@{0&prTYhA$=(Q#Zdq-y$J(dPSjTCY^DdwC+bvd|{p47EV?v`b}SmD*Rn z2vaj8_bxmQ>esmo6Rp@;D=ohVznehYPwTq3lVCdjKSFyKm53{Mu2si^Dr&C81ds^F z3a1=Esba@NLVtS9p_$zF{tqc?|A^v#I}Es4*_v0*4m`*TbF}*;fu4DEcP_JgT)|WC z%+GYckWJpQ^{`u1bZ^LsN3Eq#a)`sl*;RCCJr|W zo>f-*87~lCs z4iH-SJ<@rKoBysjff2gW&{(4TR1>nlwk){xy*#BDxKUR~Bh2!v!=~=eZQv)zsB~b4 zPqw43^<=G8<=dARv92Fi-;+Y?qC+!a!`>Kf2E~UPp+i@W{6mQvH~dpF=cA!d3yEti zeH)`gtVj0L)|NG<*?1cB`|XFRe*zSdaeNFae?hkB)uRsrz5k5QTJKb<0SY1thVTqZ zKbdP>hO2=K$|(MAW2TC-(md%;?Ww+(ZI;8s_bpXV>U-BSWpLzp&2e~Len?B%oxv66 zm+i0ByQ%`A6pMMN+k#zLN7#9UJ5M+ul`SR5a9hnuO3z)zQZd^w5(cuUV5e7GtT3|b zqMk_VOPQJ@mC0}~`LYZ`zVTxFU)Lu(ZAMjyn7|B5)gE9Q%6X2i8w=-+wJl8}ZEi0d z5VY1RRG*{@#=aSGdVz0g9WMhXoO7NC62%Tg8QT^GCo$VUNJO)}tizy@VmDt70BRcNcp&29d>-e-qlU(7nSo|W9`_R#O>52y zosDdRd;~cV1$nLz3gH_J90Pc2K}Oi9%u92YGn3)3lyY2vd+KB^K`>_Wkjf)`*; zR$Yq_f6GqD-3V4ayddY`I=Sq{0u3-4GD?3N5RA8GJ=&b%$3G_ zQY{7SM#C~or!wq1yivK*jQUl9ma&S^$B$RA0ami3<tatVOCKaeVaN2^j91aW! zy6`8T>);~4YWTN7op*G(3?U5u?LiXcl~vkZifeNH8W~E9A*mUMUP8HTqybBO!-c@LW)Z-Y6H3r`JRhoOY%#HN3$NQLzWK@fA{mx)ZFK<3@F< zqvdvP0IKPXK9l@!%2Wc3s#FWWi^Z9=)3+*({yRD;HV{_F)7#=f6eZ!S>w&4)(|D+3*;gvKdo+fBl?wT!6uDPT^Dl@Bi<BezGVTA50@DmQWZ9IOl9ff~0bP(zz9EMN@<2jN05B#=xx|3Sp? z4ri&Sz{ZY8%C)+1}#4*0E^>M8|CmOa_o;{}~e28PgqnyE=x;m{8_b<54A+J>g=1p5S%*WS)BL6 z7e1KjZcTNITq)t%BLZzRsA)l)hAX=Dj3e%pjQKW6?Y5JKAcHwUOX@l4E_UHIzgdXm zyP%MGPBKR*!Yw_0eZ3f1IK&qX?L8j=H(+f-eB+unkDi!MZy$l+-897WO0Xa#Gb`pe zI($I0D{OOOCO*t2Sz zs9ybtN1E>V?m`z8l-a=Q&n{CM1hlP?zmEm=bAdL?Z8ouE%{4CH0T|LpC}QkjAY#}P zpY`!}2Xcro{0!Eek>a^5&!wDwaH6BS{UsZZoOG~QZiKKlg~5r<4?#q76L&ukqtR`a_Tuu?KETkNc*#j~v{jp7`87PI|*O0j_Cs-`D4ehN&^@xue;55=M;h-wK^qE>s+a?Nr0Sn zpoYt$KW()Om@N9Z4iI1_r<@IL365f~aXZWUG=9l7&%DK{h0spP*R(Ybi`Fl$ZE$Gu zE)?~Vm}?xon(L|)n~gyTIhr&c*&Ok1w!4vSq&x(Q0refUqwh#7EwJiEJ>-U-${%X5 zC3H0Ie*1}QA-(pyB}l$i3aM-kF-k6>2vvtH)69ULH?TK6=9s8}Zd(JJs(cp5tNgUZ zu#wReq^K}-MKWLX6inw92WnLtgw{AKufnVoRmIDNLhA%&LqkvzS{u0i|CIWU$CPf^ z8dNwRtj+6z2Na?B)~@;N{Aal9Z+i{+=#8-D+0OeG|35t8=YdL<6`1D*${z3bYclhn zNgoqzh_a}P0KYA>YW9-@D-dEH*k(yq_6e7vjcE-vXINF-ya)lUtTM%zlRCC+foq`= zfE-;v44b%m)X%_R;kN*}-O$vpp&L`?-f-Lj1|b$sXn~iC`Tc247TsZb-Eyl1^MIme z2R{B~%_RUOVdZN1x=zxAGV`KB&LtMgXgH#m!)RcnZa=v_GINwB!WGl<$RqJ0vM!Ca zfEnU7j!KKFthnl0u5i9Ef~&Y}EK(($?ltrEvpONu=lX7>c%>*o&#+kPw%WzEPSXFD z{^$9Z?L%b7zIpny-S}1@o`IbmqqSU)=C1589#yx~fwkY;yc0>RMw%O$-m4{9ZVjx6#iK)mu~CuH{mJVrOEmm1L6b3vB~G8 zPaBZqvs2>rl@9tJ_T?cz9m_p%ZD3C>-vAi%xY;e1yq`}pYZXgR?qv&DG}{Px5g6Q; zSjsbi$H|q$PAPSKOiD|4iYvpePvd^*MoCT)y{k=gzRO*h8NS82&}4dvW=|rty$CPz z@w;(IFbm-JGq+hXkzmISX|MSvOA(_=TmeDuJP)D}okXhy zS3DyUcoM-U0v;`?$!cl~q4rv>jd|v?gy;GFIWPbxmt_Sq1jxpFLkx^fG4gX74aYJS z7L}Kts{$0wxB__!uF4BmG8CLKz@91P=x8qn)Z#*dBJaenT<|aG(1?DqD(McXf!@eL zJd@+-XLlPDDA}>gnyY2cKC_QF3#1`!z_r`61SvKM6F%QK9HFh%l1J(1bNWQYZ<37DAfRuCOFMdS z8uw^{|M$a_ujxw@RJ#P<(beo!z4|Kwj2VAxjRi?7=&5_gSz6Gpo6LFe1T5@huRyo? z^uVSJ(rbBx2BOwZOK$g62VTW)&B33M-@?+WKMK-@u4@fc1#M z8X1w=ky!yWZkxv4voHDD@>VW+4lolST$azUd^LT4JMSJ3lQVCqb6PU%l(uDJmM;xf<0K##az5dGNnA6&2`J>#-%v(Q@0f6Q+;2Cm}VilsM?d?apCC zu>%QnrvL`kWXp4`X>;fx);by@{2Nx>e(>X&WulYS4(DZJSOO#qI5;)g$2MG@slXsl zQWg}9Jrp44QyB)h{BJ=l>qEc}Q@+ejE0|fyGEQ^A`%T&O8hI<&)L9=3ORPlXQQUKb z$BDq${#0I|%)+JTaU^VKOTQYR@1+j4VC2%&Ia`>};l#s_iVW}eE8fF2zi+=NW=*yc zCq@}|i!qzPZEHVqiY?3Scc4vmi?P z5jOEb#MTG18R(?!SZLGaC5^b5Zja=&h(!+}){c0dQuQ5zcQ-vxENKskP^>RO&{sh% zD$n2o7%@V7JkRO*%!>|Q4D7BhS?=|_yn<|q$U%nOxa7XhVzf_)v6b7KE(}?gMlwd1 zcK?j+(Wlq8+zu8tQ7~Z%(RsgV)!WdI+vGA_lt)SNWs{h~*<6d|g$hvf|L9)V)nd*P zqI5kFj@7V9&nv!m`PMAO3%S(32>;uX1w|*hJmQ=Deq9J+@JD}%wocX6^6F7KH&(p^ zL$+eU(Zq%U1O@;B38oML2MYlJ0wf0U2LTFG2WhQ2OZ6L^Jp%*+0s#OFrUAeWS^x+N z0S!rR=l}o(0TD|8HUMP+HvnV+IRG*MVE{J(V*oG!W&kt*FaS3IFaS0HFaS0HHvlpK zGypgNWB@e)FaTr#GXP=$F#u!$H2`4%E&y}@cmQ+&000yU0RRBnJ(#F%(*YF*0RVsi H000007q=07 literal 0 HcmV?d00001 diff --git a/napiprojekt.py b/napiprojekt.py index 9f2e7e2..0e2449b 100755 --- a/napiprojekt.py +++ b/napiprojekt.py @@ -89,7 +89,7 @@ class NoMatchingSubtitle(Exception): pass -def un7zip_api_response(content_7z): +def un7zip_api_response(content_7z: bytes) -> bytes: try: content = un7zip(content_7z, password=NAPI_ARCHIVE_PASSWORD) except Un7ZipError: @@ -101,8 +101,13 @@ def download_subtitle(movie_path): movie_hash = calc_movie_hash_as_hex(movie_path) napi_subs_dl_url = build_url(movie_hash) content_7z = request.urlopen(napi_subs_dl_url).read() - sub_content = un7zip_api_response(content_7z) - open(get_target_path_for_subtitle(movie_path), "wb").write(sub_content) + binary_content = un7zip_api_response(content_7z) + encoded_content = encode_to_unicode(binary_content) + open(get_target_path_for_subtitle(movie_path), "w").write(encoded_content) + + +def encode_to_unicode(binary_content: bytes) -> str: + return binary_content.decode("windows-1250") def main(args): diff --git a/test.py b/test.py index a86c123..4705e75 100644 --- a/test.py +++ b/test.py @@ -1,7 +1,9 @@ import os import unittest -from napiprojekt import build_url, un7zip_api_response +from napiprojekt import build_url, un7zip_api_response, encode_to_unicode + +COMPRESSED_SUBTITLES_FILE_NAME = 'DunkirkSubtitles.7zip' class NapiPyTest(unittest.TestCase): @@ -13,9 +15,17 @@ def test_should_generate_correct_url(self): self.assertEqual(expected_url, actual_url) def test_should_unpack_downloaded_7zip(self): - compressed_subtitles_file_name = 'DunkirkSubtitles.7zip' - with open(compressed_subtitles_file_name, 'rb') as input_file: + with open(COMPRESSED_SUBTITLES_FILE_NAME, 'rb') as input_file: + compressed_content = input_file.read() + sub_bin_content = un7zip_api_response(compressed_content) + expected_phrase = b"GrupaHatak.pl" + self.assertIn(expected_phrase, sub_bin_content) + + def test_should_encode_subtitles_correctly(self): + with open(COMPRESSED_SUBTITLES_FILE_NAME, 'rb') as input_file: compressed_content = input_file.read() - content = un7zip_api_response(compressed_content) - self.assertIn(b"GrupaHatak.pl", content) - print(content) + sub_bin_content = un7zip_api_response(compressed_content) + sub_utf8_content = encode_to_unicode(sub_bin_content) + expected_phrases = ['Tłumaczenie', 'Dunkierką', 'Francuzów', 'Uwięzieni'] + for expected_phrase in expected_phrases: + self.assertIn(expected_phrase, sub_utf8_content) From 28c0356fb6902e04606b23550d2a6a6b49378006 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 12 Aug 2018 18:51:18 +0200 Subject: [PATCH 06/77] wrapped opening files in with-clause for safety, moved exceptions to top --- napiprojekt.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/napiprojekt.py b/napiprojekt.py index 0e2449b..be2a056 100755 --- a/napiprojekt.py +++ b/napiprojekt.py @@ -26,6 +26,14 @@ NAPI_ARCHIVE_PASSWORD = "iBlm8NTigvru0Jr0" +class Un7ZipError(Exception): + pass + + +class NoMatchingSubtitle(Exception): + pass + + def f(z): idx = [0xe, 0x3, 0x6, 0x8, 0x2] mul = [2, 2, 5, 4, 3] @@ -51,14 +59,12 @@ def build_url(movie_hash): def calc_movie_hash_as_hex(movie_path): md5_hash_gen = hashlib.md5() - md5_hash_gen.update(open(movie_path, mode='rb').read(SIZE_10_MBs_IN_BYTES)) + with open(movie_path, mode='rb') as movie_file: + content_of_first_10mbs = movie_file.read(SIZE_10_MBs_IN_BYTES) + md5_hash_gen.update(content_of_first_10mbs) return md5_hash_gen.hexdigest() -class Un7ZipError(Exception): - pass - - def un7zip(archive, password=None): tmp_file = NamedTemporaryFile(prefix=TMP_FILE_PREFIX, suffix=TMP_FILE_SUFFIX) tmp_file.write(archive) @@ -74,7 +80,7 @@ def un7zip(archive, password=None): content = sp.communicate()[0] if sp.wait() != 0: - raise Un7ZipError("Invalid archive") + raise Un7ZipError("Downloaded archive with subtitles is broken!") tmp_file.close() # deletes the file return content @@ -85,10 +91,6 @@ def get_target_path_for_subtitle(movie_path): return filename + ".txt" -class NoMatchingSubtitle(Exception): - pass - - def un7zip_api_response(content_7z: bytes) -> bytes: try: content = un7zip(content_7z, password=NAPI_ARCHIVE_PASSWORD) @@ -103,7 +105,8 @@ def download_subtitle(movie_path): content_7z = request.urlopen(napi_subs_dl_url).read() binary_content = un7zip_api_response(content_7z) encoded_content = encode_to_unicode(binary_content) - open(get_target_path_for_subtitle(movie_path), "w").write(encoded_content) + with open(get_target_path_for_subtitle(movie_path), "w") as subtitles_file: + subtitles_file.write(encoded_content) def encode_to_unicode(binary_content: bytes) -> str: From d100caf90cf3c701d53bd238309962b35f2d8e34 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 12 Aug 2018 18:54:54 +0200 Subject: [PATCH 07/77] expanded readme, added gitignore --- .gitignore | 2 ++ README.md | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4b0c5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.iml +.idea \ No newline at end of file diff --git a/README.md b/README.md index 08373ac..82389a7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,14 @@ -napi.py +### napi.py ======= - CLI script to download subtitles from napiprojekt.pl + +#### Requirements +- Python 3 +- 7-zip +- Internet connection + +#### Usage +Execute `napiprojekt.py /path/to/movie` + +#### Notices +- implemented encoding from windows-1250 to unicode correctly, so english Windows and Linux should display diacritics (ś, ę, ł, ó etc.) in subtitles correctly \ No newline at end of file From 6cc3cff1694382172e7c8982947e150fff52adba Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 12 Aug 2018 18:54:54 +0200 Subject: [PATCH 08/77] corrected markdown styling in readme, expanded readme --- .gitignore | 2 ++ README.md | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4b0c5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.iml +.idea \ No newline at end of file diff --git a/README.md b/README.md index 08373ac..82389a7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,14 @@ -napi.py +### napi.py ======= - CLI script to download subtitles from napiprojekt.pl + +#### Requirements +- Python 3 +- 7-zip +- Internet connection + +#### Usage +Execute `napiprojekt.py /path/to/movie` + +#### Notices +- implemented encoding from windows-1250 to unicode correctly, so english Windows and Linux should display diacritics (ś, ę, ł, ó etc.) in subtitles correctly \ No newline at end of file From b5e6b016945e177b128e324f41aad719377ab814 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 20 Jan 2019 18:44:20 +0100 Subject: [PATCH 09/77] added exception info on failed read from movie file --- napiprojekt.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/napiprojekt.py b/napiprojekt.py index be2a056..f3db550 100755 --- a/napiprojekt.py +++ b/napiprojekt.py @@ -128,8 +128,8 @@ def main(args): except NoMatchingSubtitle: any_failure = True print("{}/{} | No subtitles found!".format(index + 1, len(args))) - except IOError: - print("{}/{} | Cannot read movie file!".format(index + 1, len(args))) + except IOError as e: + print("{}/{} | Cannot read movie file: {}".format(index + 1, len(args), e)) except OSError: print("OS error. Is 7z in PATH?") exit(EXIT_CODE_LACK_OF_7Z_ON_PATH) @@ -138,5 +138,15 @@ def main(args): if __name__ == "__main__": - program_args = sys.argv[1:] - main(program_args) + # program_args = sys.argv[1:] + # main(program_args) + movie_hash = "e51029cc7d1d5b7e1cd443221bd4d1bc" + path = "/home/mat/Downloads/Come.And.See.1985.1080p.BluRay.x264.EAC3-SARTRE/pl.txt" + + napi_subs_dl_url = build_url(movie_hash) + content_7z = request.urlopen(napi_subs_dl_url).read() + binary_content = un7zip_api_response(content_7z) + encoded_content = encode_to_unicode(binary_content) + with open(get_target_path_for_subtitle(path), "w") as subtitles_file: + subtitles_file.write(encoded_content) + From b87f9494c2eaea5e8d554e9e455901b3fe6feb99 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 20 Jan 2019 18:50:07 +0100 Subject: [PATCH 10/77] removed accidentally copied script part --- napiprojekt.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/napiprojekt.py b/napiprojekt.py index f3db550..bf69cf3 100755 --- a/napiprojekt.py +++ b/napiprojekt.py @@ -138,15 +138,6 @@ def main(args): if __name__ == "__main__": - # program_args = sys.argv[1:] - # main(program_args) - movie_hash = "e51029cc7d1d5b7e1cd443221bd4d1bc" - path = "/home/mat/Downloads/Come.And.See.1985.1080p.BluRay.x264.EAC3-SARTRE/pl.txt" - - napi_subs_dl_url = build_url(movie_hash) - content_7z = request.urlopen(napi_subs_dl_url).read() - binary_content = un7zip_api_response(content_7z) - encoded_content = encode_to_unicode(binary_content) - with open(get_target_path_for_subtitle(path), "w") as subtitles_file: - subtitles_file.write(encoded_content) + program_args = sys.argv[1:] + main(program_args) From 32be276a6a53fed231f81500591018b4f9b2e016 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 21 Jan 2019 20:06:51 +0100 Subject: [PATCH 11/77] split script into separate files --- napi/__init__.py | 0 napi/api.py | 30 ++++++++++ napi/hash.py | 11 ++++ napi/main.py | 64 +++++++++++++++++++++ napi/read_7z.py | 35 ++++++++++++ napiprojekt.py | 143 ----------------------------------------------- 6 files changed, 140 insertions(+), 143 deletions(-) create mode 100644 napi/__init__.py create mode 100644 napi/api.py create mode 100644 napi/hash.py create mode 100755 napi/main.py create mode 100644 napi/read_7z.py delete mode 100755 napiprojekt.py diff --git a/napi/__init__.py b/napi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/napi/api.py b/napi/api.py new file mode 100644 index 0000000..b204ac4 --- /dev/null +++ b/napi/api.py @@ -0,0 +1,30 @@ +import os +from urllib import request + + +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) + + +def build_url(movie_hash): + return "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f={}&t={}&v=other&kolejka=false&nick=&pass=&napios={}".format( + movie_hash, f(movie_hash), os.name) + + +def download(movie_hash: str) -> bytes: + the_url = build_url(movie_hash) + return request.urlopen(the_url).read() diff --git a/napi/hash.py b/napi/hash.py new file mode 100644 index 0000000..f504f92 --- /dev/null +++ b/napi/hash.py @@ -0,0 +1,11 @@ +import hashlib + +SIZE_10_MBs_IN_BYTES = 10485760 + + +def calc_movie_hash_as_hex(movie_path: str) -> str: + md5_hash_gen = hashlib.md5() + with open(movie_path, mode='rb') as movie_file: + content_of_first_10mbs = movie_file.read(SIZE_10_MBs_IN_BYTES) + md5_hash_gen.update(content_of_first_10mbs) + return md5_hash_gen.hexdigest() diff --git a/napi/main.py b/napi/main.py new file mode 100755 index 0000000..d30de69 --- /dev/null +++ b/napi/main.py @@ -0,0 +1,64 @@ +#!/usr/bin/python3 + +import os +import sys + +from napi.api import build_url, download +from napi.hash import calc_movie_hash_as_hex +from napi.read_7z import un7zip_api_response + +EXIT_CODE_WRONG_ARG_NUMBER = 1 +EXIT_CODE_LACK_OF_7Z_ON_PATH = 4 +EXIT_CODE_FAILED = 8 + + +class NoMatchingSubtitle(Exception): + pass + + +def get_target_path_for_subtitle(movie_path): + filename, extension = os.path.splitext(movie_path) + return filename + ".txt" + + +def download_subtitle(movie_path): + movie_hash = calc_movie_hash_as_hex(movie_path) + napi_subs_dl_url = build_url(movie_hash) + content_7z = download(napi_subs_dl_url) + binary_content = un7zip_api_response(content_7z) + encoded_content = encode_to_unicode(binary_content) + with open(get_target_path_for_subtitle(movie_path), "w") as subtitles_file: + subtitles_file.write(encoded_content) + + +def encode_to_unicode(binary_content: bytes) -> str: + return binary_content.decode("windows-1250") + + +def main(args): + if len(args) < 1: + print("\nUSAGE:\n\tmain.py moviefile [moviefile, ...]\n\n") + exit(EXIT_CODE_WRONG_ARG_NUMBER) + + any_failure = False + try: + for index, movie_path in enumerate(args): + print("{}/{} | Downloading subtitles for {} ...".format(index + 1, len(args), movie_path)) + try: + download_subtitle(movie_path) + print("{}/{} | Success!".format(index + 1, len(args))) + except NoMatchingSubtitle: + any_failure = True + print("{}/{} | No subtitles found!".format(index + 1, len(args))) + except IOError as e: + print("{}/{} | Cannot read movie file: {}".format(index + 1, len(args), e)) + except OSError: + print("OS error. Is 7z in PATH?") + exit(EXIT_CODE_LACK_OF_7Z_ON_PATH) + if any_failure: + exit(EXIT_CODE_FAILED) + + +if __name__ == "__main__": + program_args = sys.argv[1:] + main(program_args) diff --git a/napi/read_7z.py b/napi/read_7z.py new file mode 100644 index 0000000..1888519 --- /dev/null +++ b/napi/read_7z.py @@ -0,0 +1,35 @@ +from subprocess import Popen, PIPE +from tempfile import NamedTemporaryFile + +TMP_FILE_SUFFIX = ".7z" +TMP_FILE_PREFIX = "un7zip" +NAPI_ARCHIVE_PASSWORD = "iBlm8NTigvru0Jr0" + + +class Un7ZipError(Exception): + pass + + +def un7zip(archive, password=None): + tmp_file = NamedTemporaryFile(prefix=TMP_FILE_PREFIX, suffix=TMP_FILE_SUFFIX) + tmp_file.write(archive) + tmp_file.flush() + + cmd = ["7z", "x", "-y", "-so"] + if password is not None: + cmd += ["-p" + password] + cmd += [tmp_file.name] + + sp = Popen(cmd, stdout=PIPE, stderr=PIPE) + + content = sp.communicate()[0] + + if sp.wait() != 0: + raise Un7ZipError("Downloaded archive with subtitles is broken!") + + tmp_file.close() # deletes the file + return content + + +def un7zip_api_response(content_7z: bytes) -> bytes: + return un7zip(content_7z, password=NAPI_ARCHIVE_PASSWORD) diff --git a/napiprojekt.py b/napiprojekt.py deleted file mode 100755 index bf69cf3..0000000 --- a/napiprojekt.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/python3 - -# -# Script downloads subtitles from napiprojekt -# -# based on older script -# by gim,krzynio,dosiu,hash 2oo8. -# last modified: 2018-08-12 -# 4pc0h f0rc3 - -import sys -from urllib import request -import os -import hashlib - -from tempfile import NamedTemporaryFile -from subprocess import Popen, PIPE - -EXIT_CODE_WRONG_ARG_NUMBER = 1 -EXIT_CODE_LACK_OF_7Z_ON_PATH = 4 -EXIT_CODE_FAILED = 8 - -TMP_FILE_SUFFIX = ".7z" -TMP_FILE_PREFIX = "un7zip" -SIZE_10_MBs_IN_BYTES = 10485760 -NAPI_ARCHIVE_PASSWORD = "iBlm8NTigvru0Jr0" - - -class Un7ZipError(Exception): - pass - - -class NoMatchingSubtitle(Exception): - pass - - -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) - - -def build_url(movie_hash): - return "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f={}&t={}&v=other&kolejka=false&nick=&pass=&napios={}".format( - movie_hash, f(movie_hash), os.name) - - -def calc_movie_hash_as_hex(movie_path): - md5_hash_gen = hashlib.md5() - with open(movie_path, mode='rb') as movie_file: - content_of_first_10mbs = movie_file.read(SIZE_10_MBs_IN_BYTES) - md5_hash_gen.update(content_of_first_10mbs) - return md5_hash_gen.hexdigest() - - -def un7zip(archive, password=None): - tmp_file = NamedTemporaryFile(prefix=TMP_FILE_PREFIX, suffix=TMP_FILE_SUFFIX) - tmp_file.write(archive) - tmp_file.flush() - - cmd = ["7z", "x", "-y", "-so"] - if password is not None: - cmd += ["-p" + password] - cmd += [tmp_file.name] - - sp = Popen(cmd, stdout=PIPE, stderr=PIPE) - - content = sp.communicate()[0] - - if sp.wait() != 0: - raise Un7ZipError("Downloaded archive with subtitles is broken!") - - tmp_file.close() # deletes the file - return content - - -def get_target_path_for_subtitle(movie_path): - filename, extension = os.path.splitext(movie_path) - return filename + ".txt" - - -def un7zip_api_response(content_7z: bytes) -> bytes: - try: - content = un7zip(content_7z, password=NAPI_ARCHIVE_PASSWORD) - except Un7ZipError: - raise NoMatchingSubtitle("No matching subtitle") - return content - - -def download_subtitle(movie_path): - movie_hash = calc_movie_hash_as_hex(movie_path) - napi_subs_dl_url = build_url(movie_hash) - content_7z = request.urlopen(napi_subs_dl_url).read() - binary_content = un7zip_api_response(content_7z) - encoded_content = encode_to_unicode(binary_content) - with open(get_target_path_for_subtitle(movie_path), "w") as subtitles_file: - subtitles_file.write(encoded_content) - - -def encode_to_unicode(binary_content: bytes) -> str: - return binary_content.decode("windows-1250") - - -def main(args): - if len(args) < 1: - print("\nUSAGE:\n\tnapiprojekt.py moviefile [moviefile, ...]\n\n") - exit(EXIT_CODE_WRONG_ARG_NUMBER) - - any_failure = False - try: - for index, movie_path in enumerate(args): - print("{}/{} | Downloading subtitles for {} ...".format(index + 1, len(args), movie_path)) - try: - download_subtitle(movie_path) - print("{}/{} | Success!".format(index + 1, len(args))) - except NoMatchingSubtitle: - any_failure = True - print("{}/{} | No subtitles found!".format(index + 1, len(args))) - except IOError as e: - print("{}/{} | Cannot read movie file: {}".format(index + 1, len(args), e)) - except OSError: - print("OS error. Is 7z in PATH?") - exit(EXIT_CODE_LACK_OF_7Z_ON_PATH) - if any_failure: - exit(EXIT_CODE_FAILED) - - -if __name__ == "__main__": - program_args = sys.argv[1:] - main(program_args) - From 5bbda9f518b992ee155ec7b7de98d54213d74d33 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 21 Jan 2019 20:46:28 +0100 Subject: [PATCH 12/77] refactored implementation, implemented detecting source encoding, implemented taking preferred target encoding instead of hard-coded utf-8 --- napi/api.py | 10 ++--- napi/encoding.py | 14 +++++++ napi/main.py | 98 +++++++++++++++++++++++----------------------- napi/store_subs.py | 13 ++++++ 4 files changed, 81 insertions(+), 54 deletions(-) create mode 100644 napi/encoding.py create mode 100644 napi/store_subs.py diff --git a/napi/api.py b/napi/api.py index b204ac4..1c21423 100644 --- a/napi/api.py +++ b/napi/api.py @@ -2,7 +2,7 @@ from urllib import request -def f(z): +def _cipher(z): idx = [0xe, 0x3, 0x6, 0x8, 0x2] mul = [2, 2, 5, 4, 3] add = [0, 0xd, 0x10, 0xb, 0x5] @@ -20,11 +20,11 @@ def f(z): return "".join(b) -def build_url(movie_hash): +def _build_url(movie_hash): return "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f={}&t={}&v=other&kolejka=false&nick=&pass=&napios={}".format( - movie_hash, f(movie_hash), os.name) + movie_hash, _cipher(movie_hash), os.name) -def download(movie_hash: str) -> bytes: - the_url = build_url(movie_hash) +def download_for(movie_hash: str) -> bytes: + the_url = _build_url(movie_hash) return request.urlopen(the_url).read() diff --git a/napi/encoding.py b/napi/encoding.py new file mode 100644 index 0000000..b1e48ad --- /dev/null +++ b/napi/encoding.py @@ -0,0 +1,14 @@ +import locale +from typing import Optional + +import chardet + + +def _guess_encoding(binary: bytes) -> Optional[str]: + return chardet.detect(binary).get("encoding") + + +def convert_subtitles_encoding(subtitles_binary: bytes) -> bytes: + source_encoding = _guess_encoding(subtitles_binary) or "windows-1250" + target_encoding = locale.getpreferredencoding() + return subtitles_binary.decode(source_encoding).encode(target_encoding) diff --git a/napi/main.py b/napi/main.py index d30de69..03d4ab8 100755 --- a/napi/main.py +++ b/napi/main.py @@ -1,64 +1,64 @@ -#!/usr/bin/python3 +import argparse +import shutil +import traceback +from os import path -import os -import sys - -from napi.api import build_url, download +from napi.api import download_for +from napi.encoding import convert_subtitles_encoding from napi.hash import calc_movie_hash_as_hex from napi.read_7z import un7zip_api_response +from napi.store_subs import store_subtitles -EXIT_CODE_WRONG_ARG_NUMBER = 1 -EXIT_CODE_LACK_OF_7Z_ON_PATH = 4 -EXIT_CODE_FAILED = 8 +EXIT_CODE_OK = 0 +EXIT_CODE_WRONG_ARGS = 1 +EXIT_CODE_NO_SUCH_MOVIE = 2 +EXIT_CODE_LACK_OF_7Z_ON_PATH = 3 +EXIT_CODE_FAILED = 4 class NoMatchingSubtitle(Exception): pass -def get_target_path_for_subtitle(movie_path): - filename, extension = os.path.splitext(movie_path) - return filename + ".txt" - - -def download_subtitle(movie_path): - movie_hash = calc_movie_hash_as_hex(movie_path) - napi_subs_dl_url = build_url(movie_hash) - content_7z = download(napi_subs_dl_url) - binary_content = un7zip_api_response(content_7z) - encoded_content = encode_to_unicode(binary_content) - with open(get_target_path_for_subtitle(movie_path), "w") as subtitles_file: - subtitles_file.write(encoded_content) - +def _parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser(prog="napi-py", description='CLI for downloading subtitles from napiprojekt.pl') + parser.add_argument('movie_path', type=str, required=True, help='Path to movie file') + return parser.parse_args() -def encode_to_unicode(binary_content: bytes) -> str: - return binary_content.decode("windows-1250") +def _is_7z_on_path(command: str = "7z") -> bool: + return shutil.which(command) is not None -def main(args): - if len(args) < 1: - print("\nUSAGE:\n\tmain.py moviefile [moviefile, ...]\n\n") - exit(EXIT_CODE_WRONG_ARG_NUMBER) - any_failure = False - try: - for index, movie_path in enumerate(args): - print("{}/{} | Downloading subtitles for {} ...".format(index + 1, len(args), movie_path)) +def main(movie_path: str) -> None: + movie_path = path.abspath(movie_path) + if path.exists(movie_path): + if _is_7z_on_path(): try: - download_subtitle(movie_path) - print("{}/{} | Success!".format(index + 1, len(args))) - except NoMatchingSubtitle: - any_failure = True - print("{}/{} | No subtitles found!".format(index + 1, len(args))) - except IOError as e: - print("{}/{} | Cannot read movie file: {}".format(index + 1, len(args), e)) - except OSError: - print("OS error. Is 7z in PATH?") - exit(EXIT_CODE_LACK_OF_7Z_ON_PATH) - if any_failure: - exit(EXIT_CODE_FAILED) - - -if __name__ == "__main__": - program_args = sys.argv[1:] - main(program_args) + movie_hash = calc_movie_hash_as_hex(movie_path) + print("Downloading subtitles for movie: {} (hash: {})".format(path.basename(movie_path), movie_hash)) + content_7z = download_for(movie_hash) + subtitles_as_bytes = un7zip_api_response(content_7z) + subtitles_as_target_bytes = convert_subtitles_encoding(subtitles_as_bytes) + subtitles_path = store_subtitles(subtitles_as_target_bytes, movie_path) + print("Success: stored subtitles at: {}".format(subtitles_path)) + except Exception as e: + traceback.print_exc() + print("Error: ".format(e)) + exit(EXIT_CODE_FAILED) + else: + print("Error: 7z seems to be unavailable on PATH!") + exit(EXIT_CODE_LACK_OF_7Z_ON_PATH) + else: + print("Error: no such file: {}".format(movie_path)) + exit(EXIT_CODE_NO_SUCH_MOVIE) + + +def cli_main(): + try: + args = _parse_args() + main(args.movie_path) + except Exception as e: + print("Parameters error: {}".format(e)) + exit(EXIT_CODE_WRONG_ARGS) + exit(EXIT_CODE_OK) diff --git a/napi/store_subs.py b/napi/store_subs.py new file mode 100644 index 0000000..98a93fe --- /dev/null +++ b/napi/store_subs.py @@ -0,0 +1,13 @@ +import os + + +def _get_target_path_for_subtitle(movie_path: str) -> str: + filename, extension = os.path.splitext(movie_path) + return filename + ".txt" + + +def store_subtitles(binary_subs: bytes, movie_path: str) -> str: + store_path = _get_target_path_for_subtitle(movie_path) + with open(store_path, "wb") as subtitles_file: + subtitles_file.write(binary_subs) + return store_path From 02ec789ff0136ad96d24fc9bc5e7bfa54c5ebbc6 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 21 Jan 2019 21:19:38 +0100 Subject: [PATCH 13/77] chardet seems to be too erratic; reverted to hardcoded windows-1250 with fallbacks --- napi/encoding.py | 22 +++++++++++++++------- napi/main.py | 17 ++++++++++------- napi/store_subs.py | 9 ++++----- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/napi/encoding.py b/napi/encoding.py index b1e48ad..24a31bb 100644 --- a/napi/encoding.py +++ b/napi/encoding.py @@ -1,14 +1,22 @@ import locale -from typing import Optional +from typing import Tuple -import chardet +DECODING_ORDER = ["windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "utf-8"] -def _guess_encoding(binary: bytes) -> Optional[str]: - return chardet.detect(binary).get("encoding") +def _try_decode(binary: bytes) -> Tuple[str, str]: + for i, enc in enumerate(DECODING_ORDER): + try: + text = binary.decode(enc) + return enc, text + except UnicodeDecodeError as e: + if i == len(DECODING_ORDER) - 1: + raise e + else: + pass -def convert_subtitles_encoding(subtitles_binary: bytes) -> bytes: - source_encoding = _guess_encoding(subtitles_binary) or "windows-1250" +def convert_subtitles_encoding(subtitles_binary: bytes) -> Tuple[str, str, bytes]: target_encoding = locale.getpreferredencoding() - return subtitles_binary.decode(source_encoding).encode(target_encoding) + source_encoding, subs = _try_decode(subtitles_binary) + return source_encoding, target_encoding, subs.encode(target_encoding) diff --git a/napi/main.py b/napi/main.py index 03d4ab8..7767159 100755 --- a/napi/main.py +++ b/napi/main.py @@ -2,12 +2,13 @@ import shutil import traceback from os import path +from typing import Optional from napi.api import download_for from napi.encoding import convert_subtitles_encoding from napi.hash import calc_movie_hash_as_hex from napi.read_7z import un7zip_api_response -from napi.store_subs import store_subtitles +from napi.store_subs import store_subtitles, get_target_path_for_subtitle EXIT_CODE_OK = 0 EXIT_CODE_WRONG_ARGS = 1 @@ -22,7 +23,8 @@ class NoMatchingSubtitle(Exception): def _parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(prog="napi-py", description='CLI for downloading subtitles from napiprojekt.pl') - parser.add_argument('movie_path', type=str, required=True, help='Path to movie file') + parser.add_argument('movie_path', type=str, help='Path to movie file') + parser.add_argument('--target', type=str, required=False, default=None, help='Path to store the subtitles in') return parser.parse_args() @@ -30,18 +32,19 @@ def _is_7z_on_path(command: str = "7z") -> bool: return shutil.which(command) is not None -def main(movie_path: str) -> None: +def main(movie_path: str, subtitles_path: Optional[str] = None) -> None: movie_path = path.abspath(movie_path) + subtitles_path = path.abspath(subtitles_path or get_target_path_for_subtitle(movie_path)) if path.exists(movie_path): if _is_7z_on_path(): try: movie_hash = calc_movie_hash_as_hex(movie_path) - print("Downloading subtitles for movie: {} (hash: {})".format(path.basename(movie_path), movie_hash)) + print("Downloading for {} ({})".format(path.basename(movie_path), movie_hash)) content_7z = download_for(movie_hash) subtitles_as_bytes = un7zip_api_response(content_7z) - subtitles_as_target_bytes = convert_subtitles_encoding(subtitles_as_bytes) - subtitles_path = store_subtitles(subtitles_as_target_bytes, movie_path) - print("Success: stored subtitles at: {}".format(subtitles_path)) + src_enc, tgt_enc, subtitles_as_target_bytes = convert_subtitles_encoding(subtitles_as_bytes) + subtitles_path = store_subtitles(subtitles_path, subtitles_as_target_bytes) + print("Saved subs ({} -> {}) in {}".format(src_enc, tgt_enc, subtitles_path)) except Exception as e: traceback.print_exc() print("Error: ".format(e)) diff --git a/napi/store_subs.py b/napi/store_subs.py index 98a93fe..a19a015 100644 --- a/napi/store_subs.py +++ b/napi/store_subs.py @@ -1,13 +1,12 @@ import os -def _get_target_path_for_subtitle(movie_path: str) -> str: +def get_target_path_for_subtitle(movie_path: str) -> str: filename, extension = os.path.splitext(movie_path) return filename + ".txt" -def store_subtitles(binary_subs: bytes, movie_path: str) -> str: - store_path = _get_target_path_for_subtitle(movie_path) - with open(store_path, "wb") as subtitles_file: +def store_subtitles(subtitles_path: str, binary_subs: bytes) -> str: + with open(subtitles_path, "wb") as subtitles_file: subtitles_file.write(binary_subs) - return store_path + return subtitles_path From 3e54b936aaebd44ecfef56a6eae992d2031fea9d Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 21 Jan 2019 21:20:04 +0100 Subject: [PATCH 14/77] reorganized package, added makefile and setup files, updated readme --- Makefile | 31 ++++++++++++++++++ README.md | 19 +++++------ setup.py | 31 ++++++++++++++++++ .../resources/DunkirkSubtitles.7zip | Bin test.py => test/test.py | 2 +- 5 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 Makefile create mode 100644 setup.py rename DunkirkSubtitles.7zip => test/resources/DunkirkSubtitles.7zip (100%) rename test.py => test/test.py (94%) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f8879b3 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +config: venv-clean venv install +all: test build + +PY3 = python3 +VENV = ~/.venv/napi.py +VENV_PY3 = ~/.venv/napi.py/bin/python3 + +venv-clean: + @echo "---- Doing cleanup ----" + @mkdir -p ~/.venv + @rm -rf $(VENV) + +venv: + @echo "---- Setting virtualenv ----" + @$(PY3) -m venv $(VENV) + @echo "---- Installing dependencies and app itself in editable mode ----" + @$(VENV_PY3) -m pip install --upgrade pip + +install: + @$(VENV_PY3) -m pip install -e .[dev] + +test: + @echo "---- Testing ---- " + @$(VENV_PY3) -m mypy --ignore-missing-imports ./napi + @$(VENV_PY3) -m pytest -v --cov=./napi ./test + +build: + @echo "---- Building package ---- " + @$(VENV_PY3) setup.py sdist bdist_wheel --python-tag py3 --dist-dir ./dist + +.PHONY: all config test build diff --git a/README.md b/README.md index 3b7cfc6..a1d0496 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,12 @@ -### napi.py -CLI script to download subtitles from napiprojekt.pl +# napi.py +Unix CLI script for downloading subtitles from napiprojekt.pl -#### Requirements -- Python 3 -- 7-zip (7z available on PATH) -- Internet connection +## Installation +- prerequisites: `python3` and `7z` available on PATH +- `pip install napi-py` -#### Usage -- execute in Terminal `napiprojekt.py /path/to/movie` -- or `napiprojekt.py /path/to/movie1 /path/to/movie2` for multiple movies -- subtitles shall be downloaded to the directory with movie, with `.txt` extension +## Usage +- execute in Terminal `napi-py MyMovie.mkv` (or `napi-py MyMovie1.mkv MyMovie2.mkv` for multiple movies) -#### Notices +## Notices - implemented encoding from `windows-1250` to unicode correctly, so english Windows and Linux should display diacritics (ś, ę, ł, ó etc.) in subtitles correctly \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..40b4ced --- /dev/null +++ b/setup.py @@ -0,0 +1,31 @@ +from distutils.core import setup +from setuptools import find_packages + +REQUIREMENTS = [ +] + +REQUIREMENTS_DEV = [ + "mypy>=0.660,<1.0.0", + "pytest>=4.1.1,<5.0.0", + "wheel>=0.32.3,<1.0.0" +] + +setup( + name="napi-py", + version="0.0.1", + description="CLI for downloading subtitles from napiprojekt.pl", + author="Mateusz Korzeniowski", + author_email="emkor93@gmail.com", + url="https://github.com/emkor/napi.py", + packages=find_packages(exclude=("test", "test.*")), + install_requires=REQUIREMENTS, + tests_require=REQUIREMENTS_DEV, + extras_require={ + "dev": REQUIREMENTS_DEV + }, + entry_points={ + "console_scripts": [ + "napi-py = napi.main:cli_main" + ] + } +) diff --git a/DunkirkSubtitles.7zip b/test/resources/DunkirkSubtitles.7zip similarity index 100% rename from DunkirkSubtitles.7zip rename to test/resources/DunkirkSubtitles.7zip diff --git a/test.py b/test/test.py similarity index 94% rename from test.py rename to test/test.py index 4705e75..cf5e442 100644 --- a/test.py +++ b/test/test.py @@ -1,7 +1,7 @@ import os import unittest -from napiprojekt import build_url, un7zip_api_response, encode_to_unicode +from napi.main import build_url, un7zip_api_response, encode_to_unicode COMPRESSED_SUBTITLES_FILE_NAME = 'DunkirkSubtitles.7zip' From 07786f56c6211c394e977101a6c718d8ec7bee20 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 12:51:00 +0200 Subject: [PATCH 15/77] updated gitignore with build caches, changed venv path in makefile --- .gitignore | 9 ++++++++- Makefile | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d4b0c5a..e3379e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ *.iml -.idea \ No newline at end of file +.idea/ + +.venv/ +.mypy_cache/ +.pytest_cache/ +*.egg-info/ +build/ +dist/ \ No newline at end of file diff --git a/Makefile b/Makefile index f8879b3..7cccf4c 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,12 @@ config: venv-clean venv install all: test build PY3 = python3 -VENV = ~/.venv/napi.py -VENV_PY3 = ~/.venv/napi.py/bin/python3 +VENV = .venv/napi.py +VENV_PY3 = .venv/napi.py/bin/python3 venv-clean: @echo "---- Doing cleanup ----" - @mkdir -p ~/.venv + @mkdir -p .venv @rm -rf $(VENV) venv: @@ -22,7 +22,7 @@ install: test: @echo "---- Testing ---- " @$(VENV_PY3) -m mypy --ignore-missing-imports ./napi - @$(VENV_PY3) -m pytest -v --cov=./napi ./test + @$(VENV_PY3) -m pytest -v ./test build: @echo "---- Building package ---- " From 22320be8a52ee47cbe3a88531549c50636ca8161 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 12:52:52 +0200 Subject: [PATCH 16/77] bumped patch version, fixed tests, split method for decoding/encoding subs --- napi/encoding.py | 22 ++++++++++-------- napi/main.py | 7 +++--- setup.py | 2 +- ...{test.py => test_sub_dl_and_conversion.py} | 23 ++++++++++++++----- 4 files changed, 34 insertions(+), 20 deletions(-) rename test/{test.py => test_sub_dl_and_conversion.py} (58%) diff --git a/napi/encoding.py b/napi/encoding.py index 24a31bb..5eec55d 100644 --- a/napi/encoding.py +++ b/napi/encoding.py @@ -4,19 +4,21 @@ DECODING_ORDER = ["windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "utf-8"] -def _try_decode(binary: bytes) -> Tuple[str, str]: +def _try_decode(subs: bytes) -> Tuple[str, str]: + last_exc = None for i, enc in enumerate(DECODING_ORDER): try: - text = binary.decode(enc) - return enc, text + return enc, subs.decode(enc) except UnicodeDecodeError as e: - if i == len(DECODING_ORDER) - 1: - raise e - else: - pass + last_exc = e + raise ValueError("Could not encode using any of {}: {}".format(DECODING_ORDER, last_exc)) -def convert_subtitles_encoding(subtitles_binary: bytes) -> Tuple[str, str, bytes]: - target_encoding = locale.getpreferredencoding() +def decode_subs(subtitles_binary: bytes) -> Tuple[str, str]: source_encoding, subs = _try_decode(subtitles_binary) - return source_encoding, target_encoding, subs.encode(target_encoding) + return source_encoding, subs + + +def encode_subs(subs: str) -> Tuple[str, bytes]: + target_encoding = locale.getpreferredencoding() + return target_encoding, subs.encode(target_encoding) diff --git a/napi/main.py b/napi/main.py index 7767159..28c9c6b 100755 --- a/napi/main.py +++ b/napi/main.py @@ -5,7 +5,7 @@ from typing import Optional from napi.api import download_for -from napi.encoding import convert_subtitles_encoding +from napi.encoding import decode_subs, encode_subs from napi.hash import calc_movie_hash_as_hex from napi.read_7z import un7zip_api_response from napi.store_subs import store_subtitles, get_target_path_for_subtitle @@ -42,8 +42,9 @@ def main(movie_path: str, subtitles_path: Optional[str] = None) -> None: print("Downloading for {} ({})".format(path.basename(movie_path), movie_hash)) content_7z = download_for(movie_hash) subtitles_as_bytes = un7zip_api_response(content_7z) - src_enc, tgt_enc, subtitles_as_target_bytes = convert_subtitles_encoding(subtitles_as_bytes) - subtitles_path = store_subtitles(subtitles_path, subtitles_as_target_bytes) + src_enc, utf8_subs = decode_subs(subtitles_as_bytes) + tgt_enc, utf8_subs_bin = encode_subs(utf8_subs) + subtitles_path = store_subtitles(subtitles_path, utf8_subs_bin) print("Saved subs ({} -> {}) in {}".format(src_enc, tgt_enc, subtitles_path)) except Exception as e: traceback.print_exc() diff --git a/setup.py b/setup.py index 40b4ced..cd2e78d 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="napi-py", - version="0.0.1", + version="0.0.2", description="CLI for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", diff --git a/test/test.py b/test/test_sub_dl_and_conversion.py similarity index 58% rename from test/test.py rename to test/test_sub_dl_and_conversion.py index cf5e442..0ee0eb7 100644 --- a/test/test.py +++ b/test/test_sub_dl_and_conversion.py @@ -1,9 +1,18 @@ import os import unittest +from os import path -from napi.main import build_url, un7zip_api_response, encode_to_unicode +from napi.api import _build_url +from napi.encoding import decode_subs +from napi.main import un7zip_api_response -COMPRESSED_SUBTITLES_FILE_NAME = 'DunkirkSubtitles.7zip' +TEST_SUBS_7Z = 'test/resources/DunkirkSubtitles.7zip' + + +def _get_project_dir(file_: str) -> str: + curr_dir = os.path.dirname(os.path.realpath(file_)) + code_directory, proj_dir, _ = curr_dir.partition("napi.py") + return path.join(code_directory, proj_dir) class NapiPyTest(unittest.TestCase): @@ -11,21 +20,23 @@ def test_should_generate_correct_url(self): movie_hash = '6e7d92a7c0f40706067248d50d3b1d5a' expected_url = 'http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f=6e7d92a7c0f40706067248d50d3b1d5a&t=c6705&v=other&kolejka=false&nick=&pass=&napios={}'.format( os.name) - actual_url = build_url(movie_hash) + actual_url = _build_url(movie_hash) self.assertEqual(expected_url, actual_url) def test_should_unpack_downloaded_7zip(self): - with open(COMPRESSED_SUBTITLES_FILE_NAME, 'rb') as input_file: + subs_path = path.join(_get_project_dir(__file__), TEST_SUBS_7Z) + with open(subs_path, 'rb') as input_file: compressed_content = input_file.read() sub_bin_content = un7zip_api_response(compressed_content) expected_phrase = b"GrupaHatak.pl" self.assertIn(expected_phrase, sub_bin_content) def test_should_encode_subtitles_correctly(self): - with open(COMPRESSED_SUBTITLES_FILE_NAME, 'rb') as input_file: + subs_path = path.join(_get_project_dir(__file__), TEST_SUBS_7Z) + with open(subs_path, 'rb') as input_file: compressed_content = input_file.read() sub_bin_content = un7zip_api_response(compressed_content) - sub_utf8_content = encode_to_unicode(sub_bin_content) + _, sub_utf8_content = decode_subs(sub_bin_content) expected_phrases = ['Tłumaczenie', 'Dunkierką', 'Francuzów', 'Uwięzieni'] for expected_phrase in expected_phrases: self.assertIn(expected_phrase, sub_utf8_content) From 5a27b7a44765a145bc05f869c7e17f26b603510a Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 13:58:27 +0200 Subject: [PATCH 17/77] introduce logging instead of raw prints, update readme --- README.md | 19 ++++++++++++------- napi/main.py | 22 ++++++++++++++++------ setup.py | 2 +- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a1d0496..6672de5 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,17 @@ # napi.py Unix CLI script for downloading subtitles from napiprojekt.pl -## Installation -- prerequisites: `python3` and `7z` available on PATH -- `pip install napi-py` +## installation +- prerequisites: + - Python 3.6 or newer + - `7z` available on PATH +- clone repository, enter `napi.py` directory and run: + - `sudo pip install .` for system wide installation -## Usage -- execute in Terminal `napi-py MyMovie.mkv` (or `napi-py MyMovie1.mkv MyMovie2.mkv` for multiple movies) +## usage +- execute in shell `napi-py MyMovie.mkv` -## Notices -- implemented encoding from `windows-1250` to unicode correctly, so english Windows and Linux should display diacritics (ś, ę, ł, ó etc.) in subtitles correctly \ No newline at end of file +## development +- `make config` installs `venv` under `.venv/napi.py` +- `make build` creates installable packages +- `make test` runs unit tests \ No newline at end of file diff --git a/napi/main.py b/napi/main.py index 28c9c6b..2f88004 100755 --- a/napi/main.py +++ b/napi/main.py @@ -1,5 +1,7 @@ import argparse +import logging import shutil +import time import traceback from os import path from typing import Optional @@ -17,6 +19,11 @@ EXIT_CODE_FAILED = 4 +def setup_logger(level: int = logging.INFO) -> None: + logging.basicConfig(format='%(levelname)s | %(asctime)s UTC | %(message)s', level=level) + logging.Formatter.converter = time.gmtime + + class NoMatchingSubtitle(Exception): pass @@ -33,36 +40,39 @@ def _is_7z_on_path(command: str = "7z") -> bool: def main(movie_path: str, subtitles_path: Optional[str] = None) -> None: + log = logging.getLogger() movie_path = path.abspath(movie_path) subtitles_path = path.abspath(subtitles_path or get_target_path_for_subtitle(movie_path)) if path.exists(movie_path): if _is_7z_on_path(): try: movie_hash = calc_movie_hash_as_hex(movie_path) - print("Downloading for {} ({})".format(path.basename(movie_path), movie_hash)) + log.debug("Downloading for {} ({})".format(path.basename(movie_path), movie_hash)) content_7z = download_for(movie_hash) subtitles_as_bytes = un7zip_api_response(content_7z) src_enc, utf8_subs = decode_subs(subtitles_as_bytes) tgt_enc, utf8_subs_bin = encode_subs(utf8_subs) subtitles_path = store_subtitles(subtitles_path, utf8_subs_bin) - print("Saved subs ({} -> {}) in {}".format(src_enc, tgt_enc, subtitles_path)) + log.info("Saved subs ({} -> {}) in {}".format(src_enc, tgt_enc, subtitles_path)) except Exception as e: traceback.print_exc() - print("Error: ".format(e)) + log.error(e) exit(EXIT_CODE_FAILED) else: - print("Error: 7z seems to be unavailable on PATH!") + log.error("7z seems to be unavailable on PATH!") exit(EXIT_CODE_LACK_OF_7Z_ON_PATH) else: - print("Error: no such file: {}".format(movie_path)) + log.error("No such file: {}".format(movie_path)) exit(EXIT_CODE_NO_SUCH_MOVIE) def cli_main(): + setup_logger() + log = logging.getLogger() try: args = _parse_args() main(args.movie_path) except Exception as e: - print("Parameters error: {}".format(e)) + log.error("Parameters error: {}".format(e)) exit(EXIT_CODE_WRONG_ARGS) exit(EXIT_CODE_OK) diff --git a/setup.py b/setup.py index cd2e78d..faeb0f9 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="napi-py", - version="0.0.2", + version="0.0.3", description="CLI for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From 99d9ca052b96800244cb9229532d06c6941018ba Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 18:28:43 +0200 Subject: [PATCH 18/77] add acceptance test, add base class to use as a lib, extend readme --- README.md | 17 +++++++++++++-- napi/__init__.py | 1 + napi/main.py | 22 ++++++++----------- napi/napi.py | 34 ++++++++++++++++++++++++++++++ setup.py | 2 +- test/test_acceptance.py | 18 ++++++++++++++++ test/test_sub_dl_and_conversion.py | 2 +- 7 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 napi/napi.py create mode 100644 test/test_acceptance.py diff --git a/README.md b/README.md index 6672de5..1c20990 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,23 @@ Unix CLI script for downloading subtitles from napiprojekt.pl - clone repository, enter `napi.py` directory and run: - `sudo pip install .` for system wide installation -## usage +## usage as tool - execute in shell `napi-py MyMovie.mkv` +## usage as lib +```python +from napi import NapiPy + +movie_path = "~/Downloads/MyMovie.mp4" + +napi = NapiPy() +movie_hash = napi.calc_hash(movie_path) +source_encoding, tmp_file = napi.download_subs(movie_hash) +subs_path = napi.move_subs_to_movie(tmp_file, movie_path) +print(subs_path) +``` + ## development - `make config` installs `venv` under `.venv/napi.py` - `make build` creates installable packages -- `make test` runs unit tests \ No newline at end of file +- `make test` runs unit and acceptance tests \ No newline at end of file diff --git a/napi/__init__.py b/napi/__init__.py index e69de29..70a6c08 100644 --- a/napi/__init__.py +++ b/napi/__init__.py @@ -0,0 +1 @@ +from napi.napi import NapiPy diff --git a/napi/main.py b/napi/main.py index 2f88004..6513237 100755 --- a/napi/main.py +++ b/napi/main.py @@ -6,11 +6,8 @@ from os import path from typing import Optional -from napi.api import download_for -from napi.encoding import decode_subs, encode_subs -from napi.hash import calc_movie_hash_as_hex -from napi.read_7z import un7zip_api_response -from napi.store_subs import store_subtitles, get_target_path_for_subtitle +from napi import NapiPy +from napi.store_subs import get_target_path_for_subtitle EXIT_CODE_OK = 0 EXIT_CODE_WRONG_ARGS = 1 @@ -46,14 +43,13 @@ def main(movie_path: str, subtitles_path: Optional[str] = None) -> None: if path.exists(movie_path): if _is_7z_on_path(): try: - movie_hash = calc_movie_hash_as_hex(movie_path) - log.debug("Downloading for {} ({})".format(path.basename(movie_path), movie_hash)) - content_7z = download_for(movie_hash) - subtitles_as_bytes = un7zip_api_response(content_7z) - src_enc, utf8_subs = decode_subs(subtitles_as_bytes) - tgt_enc, utf8_subs_bin = encode_subs(utf8_subs) - subtitles_path = store_subtitles(subtitles_path, utf8_subs_bin) - log.info("Saved subs ({} -> {}) in {}".format(src_enc, tgt_enc, subtitles_path)) + napi_client = NapiPy() + movie_hash = napi_client.calc_hash(movie_path) + log.info("Downloading for {} ({})".format(path.basename(movie_path), movie_hash)) + src_enc, tmp_file = napi_client.download_subs(movie_hash) + subs_path = napi_client.move_subs(tmp_file, subtitles_path) \ + if subtitles_path else napi_client.move_subs_to_movie(tmp_file, movie_path) + log.info("Saved subs ({}) in {}".format(src_enc, subs_path)) except Exception as e: traceback.print_exc() log.error(e) diff --git a/napi/napi.py b/napi/napi.py new file mode 100644 index 0000000..351b2ff --- /dev/null +++ b/napi/napi.py @@ -0,0 +1,34 @@ +import os +import tempfile +from typing import Tuple + +from napi.api import download_for +from napi.encoding import decode_subs, encode_subs +from napi.hash import calc_movie_hash_as_hex +from napi.read_7z import un7zip_api_response +from napi.store_subs import get_target_path_for_subtitle + + +class NapiPy: + def __init__(self) -> None: + pass + + def calc_hash(self, movie: str) -> str: + return calc_movie_hash_as_hex(movie) + + def download_subs(self, movie_hash: str) -> Tuple[str, str]: + subs_bin = un7zip_api_response(download_for(movie_hash)) + src_enc, subs_utf8 = decode_subs(subs_bin) + tgt_enc, subs_bin = encode_subs(subs_utf8) + with tempfile.NamedTemporaryFile(delete=False) as fileTemp: + fileTemp.write(subs_bin) + return src_enc, fileTemp.name + + def move_subs_to_movie(self, tmp_subs: str, movie: str) -> str: + tgt_path = get_target_path_for_subtitle(movie) + os.rename(tmp_subs, tgt_path) + return tgt_path + + def move_subs(self, tmp_subs: str, path: str) -> str: + os.rename(tmp_subs, path) + return path diff --git a/setup.py b/setup.py index faeb0f9..0fdb505 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="napi-py", - version="0.0.3", + version="0.1.0", description="CLI for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", diff --git a/test/test_acceptance.py b/test/test_acceptance.py new file mode 100644 index 0000000..c7b6f1d --- /dev/null +++ b/test/test_acceptance.py @@ -0,0 +1,18 @@ +import unittest + +from napi import NapiPy + + +class NapiPyAcceptanceTest(unittest.TestCase): + def test_should_download_correctly_encoded_subs(self): + movie_hash = '25b1087d997bfbf8a4be462255e05a05' + napi = NapiPy() + src_enc, tmp_file = napi.download_subs(movie_hash) + self.assertEqual(src_enc, "utf-8") + + with open(tmp_file) as subs_file: + subs = subs_file.read() + + expected_phrases = ['źródło', 'władzę', 'Dziękuję', 'zgłębiają', 'ZWYCIĘŻĄ!'] + for expected_phrase in expected_phrases: + self.assertIn(expected_phrase, subs) diff --git a/test/test_sub_dl_and_conversion.py b/test/test_sub_dl_and_conversion.py index 0ee0eb7..9765629 100644 --- a/test/test_sub_dl_and_conversion.py +++ b/test/test_sub_dl_and_conversion.py @@ -4,7 +4,7 @@ from napi.api import _build_url from napi.encoding import decode_subs -from napi.main import un7zip_api_response +from napi.read_7z import un7zip_api_response TEST_SUBS_7Z = 'test/resources/DunkirkSubtitles.7zip' From f23c5a7d0b9b015b00b25c113c265851f2a716ed Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 18:30:36 +0200 Subject: [PATCH 19/77] add CI definition (travis) --- .travis.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..636adae --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: python +cache: pip +python: + - "3.6" + - "3.7" + +before_script: + - make config + +script: + - make test + - make build + +notifications: + email: + on_success: never + on_failure: change \ No newline at end of file From 799b61c4af652b3fd66f72216cd4e0a2cf2d5972 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 18:37:38 +0200 Subject: [PATCH 20/77] add installation of 7z exec --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 636adae..4e9a0d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ python: - "3.7" before_script: + - sudo apt-get install -y p7zip - make config script: From a040d7f3db53555e04b25e47cd5854dd7a2e75d9 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 18:42:05 +0200 Subject: [PATCH 21/77] add installation of 7z exec --- .travis.yml | 2 +- README.md | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4e9a0d4..8e9f832 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ python: - "3.7" before_script: - - sudo apt-get install -y p7zip + - sudo apt-get install -y p7zip-full - make config script: diff --git a/README.md b/README.md index 1c20990..b591c2f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# napi.py +# napi.py [![Build Status](https://travis-ci.com/emkor/napi.py.svg?branch=master)](https://travis-ci.com/emkor/napi.py) Unix CLI script for downloading subtitles from napiprojekt.pl ## installation diff --git a/setup.py b/setup.py index 0fdb505..2106805 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="napi-py", - version="0.1.0", + version="0.1.1", description="CLI for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From f135c50dcc252384f5e197c3f77589f7807ddafb Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 19:15:47 +0200 Subject: [PATCH 22/77] add scripts for publishing to pypi --- .travis.yml | 5 + LICENSE.md | 674 +++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 5 + README.md | 14 +- napi/__init__.py | 2 + setup.py | 21 +- 6 files changed, 711 insertions(+), 10 deletions(-) create mode 100644 LICENSE.md diff --git a/.travis.yml b/.travis.yml index 8e9f832..127f08c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,11 @@ script: - make test - make build +after_success: + - if [ "$TRAVIS_BRANCH" == "master" ]; then + make publish + fi + notifications: email: on_success: never diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..7a3b7c2 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/Makefile b/Makefile index 7cccf4c..224abe0 100644 --- a/Makefile +++ b/Makefile @@ -28,4 +28,9 @@ build: @echo "---- Building package ---- " @$(VENV_PY3) setup.py sdist bdist_wheel --python-tag py3 --dist-dir ./dist +publish: + @echo "---- Pushing package to PyPI ---- " + @$(VENV_PY3) -m pip install --upgrade twine + @$(VENV_PY3) -m twine upload -u $PYPI_USER -p $PYPI_PASSWORD dist/* + .PHONY: all config test build diff --git a/README.md b/README.md index b591c2f..b6ffe1b 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # napi.py [![Build Status](https://travis-ci.com/emkor/napi.py.svg?branch=master)](https://travis-ci.com/emkor/napi.py) -Unix CLI script for downloading subtitles from napiprojekt.pl +CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py](https://github.com/gabrys/napi.py) + +## prerequisites +- Python 3.6 or 3.7 +- `7z` available on PATH ## installation -- prerequisites: - - Python 3.6 or newer - - `7z` available on PATH -- clone repository, enter `napi.py` directory and run: - - `sudo pip install .` for system wide installation +- `sudo pip install napi-py` for system wide installation ## usage as tool -- execute in shell `napi-py MyMovie.mkv` +- `napi-py ~/Downloads/MyMovie.mp4` ## usage as lib ```python diff --git a/napi/__init__.py b/napi/__init__.py index 70a6c08..15a1612 100644 --- a/napi/__init__.py +++ b/napi/__init__.py @@ -1 +1,3 @@ from napi.napi import NapiPy + +name = "napi.py" diff --git a/setup.py b/setup.py index 2106805..7e94dcd 100644 --- a/setup.py +++ b/setup.py @@ -10,12 +10,17 @@ "wheel>=0.32.3,<1.0.0" ] +with open("README.md", "r") as fh: + long_description = fh.read() + setup( name="napi-py", - version="0.1.1", - description="CLI for downloading subtitles from napiprojekt.pl", + version="0.1.2", + description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", + long_description=long_description, + long_description_content_type="text/markdown", url="https://github.com/emkor/napi.py", packages=find_packages(exclude=("test", "test.*")), install_requires=REQUIREMENTS, @@ -27,5 +32,15 @@ "console_scripts": [ "napi-py = napi.main:cli_main" ] - } + }, + classifiers=[ + "Programming Language :: Python :: 3", + "Development Status :: 3 - Alpha", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Natural Language :: English", + "Operating System :: POSIX :: Linux", + "Topic :: Utilities" + ], ) From d127f9f622d52c58781217437915e3d118dbf42e Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 19:18:36 +0200 Subject: [PATCH 23/77] reduce testing to just python 3.7 as travis would try to publish package in each environment, to be resolved later --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 127f08c..de3dc6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: python cache: pip python: - - "3.6" - "3.7" before_script: From 1cd9b1bc79133af3b33f054488fb7750fad82cfe Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 19:37:43 +0200 Subject: [PATCH 24/77] wrap if branch == master into bash script as it was failing on travis CI --- .travis.yml | 4 +--- ci_publish.sh | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100755 ci_publish.sh diff --git a/.travis.yml b/.travis.yml index de3dc6f..864dbd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,7 @@ script: - make build after_success: - - if [ "$TRAVIS_BRANCH" == "master" ]; then - make publish - fi + - ./ci_publish.sh notifications: email: diff --git a/ci_publish.sh b/ci_publish.sh new file mode 100755 index 0000000..bcdc53f --- /dev/null +++ b/ci_publish.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +if [ "$TRAVIS_BRANCH" == "master" ]; then + make publish +fi \ No newline at end of file From 41ebd2448b2910bae18a6ae328fed0812de188d2 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 25 Aug 2019 19:49:43 +0200 Subject: [PATCH 25/77] moving publishing code to script --- Makefile | 5 ----- ci_publish.sh | 6 +++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 224abe0..7cccf4c 100644 --- a/Makefile +++ b/Makefile @@ -28,9 +28,4 @@ build: @echo "---- Building package ---- " @$(VENV_PY3) setup.py sdist bdist_wheel --python-tag py3 --dist-dir ./dist -publish: - @echo "---- Pushing package to PyPI ---- " - @$(VENV_PY3) -m pip install --upgrade twine - @$(VENV_PY3) -m twine upload -u $PYPI_USER -p $PYPI_PASSWORD dist/* - .PHONY: all config test build diff --git a/ci_publish.sh b/ci_publish.sh index bcdc53f..60668a2 100755 --- a/ci_publish.sh +++ b/ci_publish.sh @@ -3,5 +3,9 @@ set -e if [ "$TRAVIS_BRANCH" == "master" ]; then - make publish + pip install --upgrade twine + echo "Uploading as user: $PYPI_USER" + twine upload -u $PYPI_USER -p $PYPI_PASSWORD dist/* + else + echo "Not on CI master branch, not publishing" fi \ No newline at end of file From 5bce86d191e6cface6261d2a74d4a6e3145f4506 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Tue, 27 Aug 2019 19:32:14 +0200 Subject: [PATCH 26/77] implement case with no such subtitles found --- napi/main.py | 17 +++++++++++------ napi/napi.py | 22 +++++++++++++++------- napi/read_7z.py | 8 ++++++-- setup.py | 2 +- test/test_acceptance.py | 7 +++++++ 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/napi/main.py b/napi/main.py index 6513237..117ef84 100755 --- a/napi/main.py +++ b/napi/main.py @@ -13,11 +13,12 @@ EXIT_CODE_WRONG_ARGS = 1 EXIT_CODE_NO_SUCH_MOVIE = 2 EXIT_CODE_LACK_OF_7Z_ON_PATH = 3 -EXIT_CODE_FAILED = 4 +EXIT_SUBS_NOT_FOUND = 4 +EXIT_CODE_FAILED = 5 def setup_logger(level: int = logging.INFO) -> None: - logging.basicConfig(format='%(levelname)s | %(asctime)s UTC | %(message)s', level=level) + logging.basicConfig(format='%(asctime)s UTC | %(levelname)s | %(message)s', level=level) logging.Formatter.converter = time.gmtime @@ -45,11 +46,15 @@ def main(movie_path: str, subtitles_path: Optional[str] = None) -> None: try: napi_client = NapiPy() movie_hash = napi_client.calc_hash(movie_path) - log.info("Downloading for {} ({})".format(path.basename(movie_path), movie_hash)) + log.info("Downloading subs for {} ({})".format(path.basename(movie_path), movie_hash)) src_enc, tmp_file = napi_client.download_subs(movie_hash) - subs_path = napi_client.move_subs(tmp_file, subtitles_path) \ - if subtitles_path else napi_client.move_subs_to_movie(tmp_file, movie_path) - log.info("Saved subs ({}) in {}".format(src_enc, subs_path)) + if src_enc is not None and tmp_file is not None: + subs_path = napi_client.move_subs(tmp_file, subtitles_path) \ + if subtitles_path else napi_client.move_subs_to_movie(tmp_file, movie_path) + log.info("Saved subs ({}) in {}".format(src_enc, subs_path)) + else: + log.error("Napiprojekt.pl does not have subtitles for this movie") + exit(EXIT_SUBS_NOT_FOUND) except Exception as e: traceback.print_exc() log.error(e) diff --git a/napi/napi.py b/napi/napi.py index 351b2ff..8c0c935 100644 --- a/napi/napi.py +++ b/napi/napi.py @@ -1,6 +1,6 @@ import os import tempfile -from typing import Tuple +from typing import Tuple, Optional from napi.api import download_for from napi.encoding import decode_subs, encode_subs @@ -16,13 +16,15 @@ def __init__(self) -> None: def calc_hash(self, movie: str) -> str: return calc_movie_hash_as_hex(movie) - def download_subs(self, movie_hash: str) -> Tuple[str, str]: + def download_subs(self, movie_hash: str) -> Tuple[Optional[str], Optional[str]]: subs_bin = un7zip_api_response(download_for(movie_hash)) - src_enc, subs_utf8 = decode_subs(subs_bin) - tgt_enc, subs_bin = encode_subs(subs_utf8) - with tempfile.NamedTemporaryFile(delete=False) as fileTemp: - fileTemp.write(subs_bin) - return src_enc, fileTemp.name + if subs_bin: + src_enc, subs_utf8 = decode_subs(subs_bin) + tgt_enc, subs_bin = encode_subs(subs_utf8) + with tempfile.NamedTemporaryFile(delete=False) as fileTemp: + fileTemp.write(subs_bin) + return src_enc, fileTemp.name + return None, None def move_subs_to_movie(self, tmp_subs: str, movie: str) -> str: tgt_path = get_target_path_for_subtitle(movie) @@ -32,3 +34,9 @@ def move_subs_to_movie(self, tmp_subs: str, movie: str) -> str: def move_subs(self, tmp_subs: str, path: str) -> str: os.rename(tmp_subs, path) return path + + +if __name__ == '__main__': + hash = "f6d059b545618f35fd86da4d72126d1c" + napi = NapiPy() + subs = napi.download_subs(hash) diff --git a/napi/read_7z.py b/napi/read_7z.py index 1888519..f26eb53 100644 --- a/napi/read_7z.py +++ b/napi/read_7z.py @@ -1,5 +1,6 @@ from subprocess import Popen, PIPE from tempfile import NamedTemporaryFile +from typing import Optional TMP_FILE_SUFFIX = ".7z" TMP_FILE_PREFIX = "un7zip" @@ -31,5 +32,8 @@ def un7zip(archive, password=None): return content -def un7zip_api_response(content_7z: bytes) -> bytes: - return un7zip(content_7z, password=NAPI_ARCHIVE_PASSWORD) +def un7zip_api_response(content_7z: bytes) -> Optional[bytes]: + try: + return un7zip(content_7z, password=NAPI_ARCHIVE_PASSWORD) + except Un7ZipError: + return None diff --git a/setup.py b/setup.py index 7e94dcd..ef4abef 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( name="napi-py", - version="0.1.2", + version="0.1.3", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", diff --git a/test/test_acceptance.py b/test/test_acceptance.py index c7b6f1d..17d8d20 100644 --- a/test/test_acceptance.py +++ b/test/test_acceptance.py @@ -16,3 +16,10 @@ def test_should_download_correctly_encoded_subs(self): expected_phrases = ['źródło', 'władzę', 'Dziękuję', 'zgłębiają', 'ZWYCIĘŻĄ!'] for expected_phrase in expected_phrases: self.assertIn(expected_phrase, subs) + + def test_should_return_none_when_no_subtitles_for_movie(self): + movie_hash = '00000000000000000000000000000000' + napi = NapiPy() + src_enc, tmp_file = napi.download_subs(movie_hash) + self.assertIsNone(src_enc) + self.assertIsNone(tmp_file) From 745d9342506ebc957c2261a3b4a01c3ec06ab068 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Tue, 27 Aug 2019 19:44:22 +0200 Subject: [PATCH 27/77] implement feature of downloading subs for given hash, fix few bugs (moving file between filesystems now should work) --- README.md | 2 +- napi/main.py | 13 +++++++------ napi/napi.py | 18 ++++++------------ setup.py | 2 +- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b6ffe1b..f937d20 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ movie_path = "~/Downloads/MyMovie.mp4" napi = NapiPy() movie_hash = napi.calc_hash(movie_path) -source_encoding, tmp_file = napi.download_subs(movie_hash) +source_encoding, target_encoding, tmp_file = napi.download_subs(movie_hash) subs_path = napi.move_subs_to_movie(tmp_file, movie_path) print(subs_path) ``` diff --git a/napi/main.py b/napi/main.py index 117ef84..db98dc3 100755 --- a/napi/main.py +++ b/napi/main.py @@ -30,6 +30,7 @@ def _parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(prog="napi-py", description='CLI for downloading subtitles from napiprojekt.pl') parser.add_argument('movie_path', type=str, help='Path to movie file') parser.add_argument('--target', type=str, required=False, default=None, help='Path to store the subtitles in') + parser.add_argument('--hash', type=str, required=False, default=None, help='Use given hash for this movie') return parser.parse_args() @@ -37,7 +38,7 @@ def _is_7z_on_path(command: str = "7z") -> bool: return shutil.which(command) is not None -def main(movie_path: str, subtitles_path: Optional[str] = None) -> None: +def main(movie_path: str, subtitles_path: Optional[str] = None, use_hash: Optional[str] = None) -> None: log = logging.getLogger() movie_path = path.abspath(movie_path) subtitles_path = path.abspath(subtitles_path or get_target_path_for_subtitle(movie_path)) @@ -45,13 +46,13 @@ def main(movie_path: str, subtitles_path: Optional[str] = None) -> None: if _is_7z_on_path(): try: napi_client = NapiPy() - movie_hash = napi_client.calc_hash(movie_path) - log.info("Downloading subs for {} ({})".format(path.basename(movie_path), movie_hash)) - src_enc, tmp_file = napi_client.download_subs(movie_hash) + movie_hash = use_hash or napi_client.calc_hash(movie_path) + log.info("Downloading subs for {} (hash: {})".format(path.basename(movie_path), movie_hash)) + src_enc, tgt_src, tmp_file = napi_client.download_subs(movie_hash) if src_enc is not None and tmp_file is not None: subs_path = napi_client.move_subs(tmp_file, subtitles_path) \ if subtitles_path else napi_client.move_subs_to_movie(tmp_file, movie_path) - log.info("Saved subs ({}) in {}".format(src_enc, subs_path)) + log.info("Saved subs ({} -> {}) in {}".format(src_enc, tgt_src, subs_path)) else: log.error("Napiprojekt.pl does not have subtitles for this movie") exit(EXIT_SUBS_NOT_FOUND) @@ -72,7 +73,7 @@ def cli_main(): log = logging.getLogger() try: args = _parse_args() - main(args.movie_path) + main(args.movie_path, subtitles_path=args.target, use_hash=args.hash) except Exception as e: log.error("Parameters error: {}".format(e)) exit(EXIT_CODE_WRONG_ARGS) diff --git a/napi/napi.py b/napi/napi.py index 8c0c935..18d8504 100644 --- a/napi/napi.py +++ b/napi/napi.py @@ -1,4 +1,4 @@ -import os +import shutil import tempfile from typing import Tuple, Optional @@ -16,27 +16,21 @@ def __init__(self) -> None: def calc_hash(self, movie: str) -> str: return calc_movie_hash_as_hex(movie) - def download_subs(self, movie_hash: str) -> Tuple[Optional[str], Optional[str]]: + def download_subs(self, movie_hash: str) -> Tuple[Optional[str], Optional[str], Optional[str]]: subs_bin = un7zip_api_response(download_for(movie_hash)) if subs_bin: src_enc, subs_utf8 = decode_subs(subs_bin) tgt_enc, subs_bin = encode_subs(subs_utf8) with tempfile.NamedTemporaryFile(delete=False) as fileTemp: fileTemp.write(subs_bin) - return src_enc, fileTemp.name - return None, None + return src_enc, tgt_enc, fileTemp.name + return None, None, None def move_subs_to_movie(self, tmp_subs: str, movie: str) -> str: tgt_path = get_target_path_for_subtitle(movie) - os.rename(tmp_subs, tgt_path) + shutil.move(tmp_subs, tgt_path) return tgt_path def move_subs(self, tmp_subs: str, path: str) -> str: - os.rename(tmp_subs, path) + shutil.move(tmp_subs, path) return path - - -if __name__ == '__main__': - hash = "f6d059b545618f35fd86da4d72126d1c" - napi = NapiPy() - subs = napi.download_subs(hash) diff --git a/setup.py b/setup.py index ef4abef..eaba8df 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( name="napi-py", - version="0.1.3", + version="0.1.4", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From 021dfdaf507627fd4d3c1459afd7fd8997fdb639 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Tue, 27 Aug 2019 19:47:00 +0200 Subject: [PATCH 28/77] fix tests according to download_subs() API change --- test/test_acceptance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_acceptance.py b/test/test_acceptance.py index 17d8d20..ddc48a7 100644 --- a/test/test_acceptance.py +++ b/test/test_acceptance.py @@ -7,7 +7,7 @@ class NapiPyAcceptanceTest(unittest.TestCase): def test_should_download_correctly_encoded_subs(self): movie_hash = '25b1087d997bfbf8a4be462255e05a05' napi = NapiPy() - src_enc, tmp_file = napi.download_subs(movie_hash) + src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash) self.assertEqual(src_enc, "utf-8") with open(tmp_file) as subs_file: @@ -20,6 +20,6 @@ def test_should_download_correctly_encoded_subs(self): def test_should_return_none_when_no_subtitles_for_movie(self): movie_hash = '00000000000000000000000000000000' napi = NapiPy() - src_enc, tmp_file = napi.download_subs(movie_hash) + src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash) self.assertIsNone(src_enc) self.assertIsNone(tmp_file) From 48f5888fcac1c5e6283e92ac86385c76f37e2692 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 27 Sep 2019 19:28:03 +0200 Subject: [PATCH 29/77] add flag to force treating downloaded subs as given encoding instead of guessing --- napi/encoding.py | 10 ++++++---- napi/main.py | 9 ++++++--- napi/napi.py | 4 ++-- setup.py | 2 +- test/test_acceptance.py | 13 +++++++++++++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/napi/encoding.py b/napi/encoding.py index 5eec55d..3d40393 100644 --- a/napi/encoding.py +++ b/napi/encoding.py @@ -1,5 +1,5 @@ import locale -from typing import Tuple +from typing import Tuple, Optional DECODING_ORDER = ["windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "utf-8"] @@ -14,9 +14,11 @@ def _try_decode(subs: bytes) -> Tuple[str, str]: raise ValueError("Could not encode using any of {}: {}".format(DECODING_ORDER, last_exc)) -def decode_subs(subtitles_binary: bytes) -> Tuple[str, str]: - source_encoding, subs = _try_decode(subtitles_binary) - return source_encoding, subs +def decode_subs(subtitles_binary: bytes, use_enc: Optional[str] = None) -> Tuple[str, str]: + if use_enc is not None: + return use_enc, subtitles_binary.decode(use_enc) + else: + return _try_decode(subtitles_binary) def encode_subs(subs: str) -> Tuple[str, bytes]: diff --git a/napi/main.py b/napi/main.py index db98dc3..022551f 100755 --- a/napi/main.py +++ b/napi/main.py @@ -31,6 +31,8 @@ def _parse_args() -> argparse.Namespace: parser.add_argument('movie_path', type=str, help='Path to movie file') parser.add_argument('--target', type=str, required=False, default=None, help='Path to store the subtitles in') parser.add_argument('--hash', type=str, required=False, default=None, help='Use given hash for this movie') + parser.add_argument('--from-enc', type=str, required=False, default=None, + help='Treat downloaded subs as this encoding instead of guessing') return parser.parse_args() @@ -38,7 +40,8 @@ def _is_7z_on_path(command: str = "7z") -> bool: return shutil.which(command) is not None -def main(movie_path: str, subtitles_path: Optional[str] = None, use_hash: Optional[str] = None) -> None: +def main(movie_path: str, subtitles_path: Optional[str] = None, use_hash: Optional[str] = None, + from_enc: Optional[str] = None) -> None: log = logging.getLogger() movie_path = path.abspath(movie_path) subtitles_path = path.abspath(subtitles_path or get_target_path_for_subtitle(movie_path)) @@ -48,7 +51,7 @@ def main(movie_path: str, subtitles_path: Optional[str] = None, use_hash: Option napi_client = NapiPy() movie_hash = use_hash or napi_client.calc_hash(movie_path) log.info("Downloading subs for {} (hash: {})".format(path.basename(movie_path), movie_hash)) - src_enc, tgt_src, tmp_file = napi_client.download_subs(movie_hash) + src_enc, tgt_src, tmp_file = napi_client.download_subs(movie_hash, use_enc=from_enc) if src_enc is not None and tmp_file is not None: subs_path = napi_client.move_subs(tmp_file, subtitles_path) \ if subtitles_path else napi_client.move_subs_to_movie(tmp_file, movie_path) @@ -73,7 +76,7 @@ def cli_main(): log = logging.getLogger() try: args = _parse_args() - main(args.movie_path, subtitles_path=args.target, use_hash=args.hash) + main(args.movie_path, subtitles_path=args.target, use_hash=args.hash, from_enc=args.from_enc) except Exception as e: log.error("Parameters error: {}".format(e)) exit(EXIT_CODE_WRONG_ARGS) diff --git a/napi/napi.py b/napi/napi.py index 18d8504..f3dcab6 100644 --- a/napi/napi.py +++ b/napi/napi.py @@ -16,10 +16,10 @@ def __init__(self) -> None: def calc_hash(self, movie: str) -> str: return calc_movie_hash_as_hex(movie) - def download_subs(self, movie_hash: str) -> Tuple[Optional[str], Optional[str], Optional[str]]: + def download_subs(self, movie_hash: str, use_enc: Optional[str] = None) -> Tuple[Optional[str], Optional[str], Optional[str]]: subs_bin = un7zip_api_response(download_for(movie_hash)) if subs_bin: - src_enc, subs_utf8 = decode_subs(subs_bin) + src_enc, subs_utf8 = decode_subs(subs_bin, use_enc=use_enc) tgt_enc, subs_bin = encode_subs(subs_utf8) with tempfile.NamedTemporaryFile(delete=False) as fileTemp: fileTemp.write(subs_bin) diff --git a/setup.py b/setup.py index eaba8df..de31143 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( name="napi-py", - version="0.1.4", + version="0.1.5", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", diff --git a/test/test_acceptance.py b/test/test_acceptance.py index ddc48a7..7602859 100644 --- a/test/test_acceptance.py +++ b/test/test_acceptance.py @@ -23,3 +23,16 @@ def test_should_return_none_when_no_subtitles_for_movie(self): src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash) self.assertIsNone(src_enc) self.assertIsNone(tmp_file) + + def test_should_download_subs_with_forced_encoding(self): + movie_hash = '0e9b0d0d3dc5abc0538d207d477af4a1' + napi = NapiPy() + src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash, use_enc="utf-8") + self.assertEqual(src_enc, "utf-8") + + with open(tmp_file) as subs_file: + subs = subs_file.read() + + expected_phrases = ['ciąży', 'artykułów', 'Właśnie', 'wyjść', 'wciąż'] + for expected_phrase in expected_phrases: + self.assertIn(expected_phrase, subs) From af07dc9e787c4040b5b962d8aa12a7b7260a8859 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 29 Dec 2019 17:00:51 +0100 Subject: [PATCH 30/77] use tox instead of raw pytest to check if tools is working under different python versions --- .gitignore | 1 + Makefile | 7 +++---- README.md | 18 +++++++++++++----- napi/__init__.py | 2 +- setup.py | 9 ++++----- test/test_sub_dl_and_conversion.py | 2 +- tox.ini | 16 ++++++++++++++++ 7 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index e3379e1..76122ec 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .idea/ .venv/ +.tox/ .mypy_cache/ .pytest_cache/ *.egg-info/ diff --git a/Makefile b/Makefile index 7cccf4c..9b30c9e 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ config: venv-clean venv install all: test build PY3 = python3 -VENV = .venv/napi.py -VENV_PY3 = .venv/napi.py/bin/python3 +VENV = .venv/$(basename $PWD) +VENV_PY3 = .venv/$(basename $PWD)/bin/python3 venv-clean: @echo "---- Doing cleanup ----" @@ -21,8 +21,7 @@ install: test: @echo "---- Testing ---- " - @$(VENV_PY3) -m mypy --ignore-missing-imports ./napi - @$(VENV_PY3) -m pytest -v ./test + @$(VENV_PY3) -m tox build: @echo "---- Building package ---- " diff --git a/README.md b/README.md index f937d20..e31a810 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# napi.py [![Build Status](https://travis-ci.com/emkor/napi.py.svg?branch=master)](https://travis-ci.com/emkor/napi.py) +# napi-py [![Build Status](https://travis-ci.com/emkor/napi.py.svg?branch=master)](https://travis-ci.com/emkor/napi-py) CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py](https://github.com/gabrys/napi.py) ## prerequisites -- Python 3.6 or 3.7 +- Python 3.6 or later - `7z` available on PATH ## installation @@ -24,7 +24,15 @@ subs_path = napi.move_subs_to_movie(tmp_file, movie_path) print(subs_path) ``` +## in case of issues +- if there's issue with weird characters in downloaded subtitles, try to re-download and use flag `--from-enc utf-8` +- if there's no subtitles for your movie, there's still hope: + - open the movie web page on `napiprojekt.pl` in your browser, as in example: `https://www.napiprojekt.pl/napisy1,1,1-dla-55534-Z%C5%82odziejaszki-(2018)` + - choose subtitles that might match your movie, right-click them and select "Copy link", which looks like this `napiprojekt:96edd6537d9852a51cbdd5b64fee9194` + - use flag `--hash 96edd6537d9852a51cbdd5b64fee9194` in this tool + + ## development -- `make config` installs `venv` under `.venv/napi.py` -- `make build` creates installable packages -- `make test` runs unit and acceptance tests \ No newline at end of file +- `make config` installs `venv` under `.venv/napi-py` +- `make test` runs tests +- `make build` creates installable package diff --git a/napi/__init__.py b/napi/__init__.py index 15a1612..15098ab 100644 --- a/napi/__init__.py +++ b/napi/__init__.py @@ -1,3 +1,3 @@ from napi.napi import NapiPy -name = "napi.py" +name = "napi-py" diff --git a/setup.py b/setup.py index de31143..abb59da 100644 --- a/setup.py +++ b/setup.py @@ -5,9 +5,8 @@ ] REQUIREMENTS_DEV = [ - "mypy>=0.660,<1.0.0", - "pytest>=4.1.1,<5.0.0", - "wheel>=0.32.3,<1.0.0" + "tox==3.*", + "wheel==0.*" ] with open("README.md", "r") as fh: @@ -15,13 +14,13 @@ setup( name="napi-py", - version="0.1.5", + version="0.1.6", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", long_description=long_description, long_description_content_type="text/markdown", - url="https://github.com/emkor/napi.py", + url="https://github.com/emkor/napi-py", packages=find_packages(exclude=("test", "test.*")), install_requires=REQUIREMENTS, tests_require=REQUIREMENTS_DEV, diff --git a/test/test_sub_dl_and_conversion.py b/test/test_sub_dl_and_conversion.py index 9765629..34f4c79 100644 --- a/test/test_sub_dl_and_conversion.py +++ b/test/test_sub_dl_and_conversion.py @@ -11,7 +11,7 @@ def _get_project_dir(file_: str) -> str: curr_dir = os.path.dirname(os.path.realpath(file_)) - code_directory, proj_dir, _ = curr_dir.partition("napi.py") + code_directory, proj_dir, _ = curr_dir.partition("napi-py") return path.join(code_directory, proj_dir) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..2456355 --- /dev/null +++ b/tox.ini @@ -0,0 +1,16 @@ +[tox] +envlist = py{36,37},lint + +[testenv] +deps = + pytest==5.3.* + wheel==0.33.* + mypy==0.* +commands = + pytest -ra -v test + +[testenv:lint] +deps = + mypy==0.* +commands = + mypy --ignore-missing-imports napi \ No newline at end of file From 876cc83deab2867a6fcd5de739a096802788ad57 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 29 Dec 2019 17:06:39 +0100 Subject: [PATCH 31/77] fix travis by adding missing python interpreter --- .travis.yml | 1 + README.md | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 864dbd5..92e61d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python cache: pip python: + - "3.6" - "3.7" before_script: diff --git a/README.md b/README.md index e31a810..96afdbc 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,8 @@ print(subs_path) - if there's issue with weird characters in downloaded subtitles, try to re-download and use flag `--from-enc utf-8` - if there's no subtitles for your movie, there's still hope: - open the movie web page on `napiprojekt.pl` in your browser, as in example: `https://www.napiprojekt.pl/napisy1,1,1-dla-55534-Z%C5%82odziejaszki-(2018)` - - choose subtitles that might match your movie, right-click them and select "Copy link", which looks like this `napiprojekt:96edd6537d9852a51cbdd5b64fee9194` - - use flag `--hash 96edd6537d9852a51cbdd5b64fee9194` in this tool - + - choose subtitles that might match your movie, right-click them and select "Copy link" on link containing hash, which looks like this `napiprojekt:96edd6537d9852a51cbdd5b64fee9194` + - use flag `--hash YOURHASH` in this tool, i.e. `--hash 96edd6537d9852a51cbdd5b64fee9194` ## development - `make config` installs `venv` under `.venv/napi-py` From 92a8a464210af5c1992cb5340760f43d9d99033d Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 29 Dec 2019 17:20:01 +0100 Subject: [PATCH 32/77] add checking which python is available on CI --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 92e61d5..040ad1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,8 @@ before_script: - make config script: - - make test + - tox -e lint + - if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then tox -e py36; else tox -e py37; fi - make build after_success: From d9445dccfea353818a4ea049d2547a281ff7d533 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 29 Dec 2019 17:23:15 +0100 Subject: [PATCH 33/77] fixed publishing: now it's executed only on python 3.7-based job variant --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 040ad1c..d850a31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,11 +10,11 @@ before_script: script: - tox -e lint - - if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then tox -e py36; else tox -e py37; fi + - if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]]; then tox -e py37; else tox -e py36; fi - make build after_success: - - ./ci_publish.sh + - if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]]; then ./ci_publish.sh ; fi notifications: email: From c92fdda65a9cebb995d7528431cd1e5d010f22e2 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 29 Dec 2019 17:32:01 +0100 Subject: [PATCH 34/77] fix build status link, remove not-needed dependency in unit test phase (mypy) --- README.md | 2 +- setup.py | 2 +- tox.ini | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 96afdbc..407dac3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# napi-py [![Build Status](https://travis-ci.com/emkor/napi.py.svg?branch=master)](https://travis-ci.com/emkor/napi-py) +# napi-py [![Build Status](https://travis-ci.com/emkor/napi-py.svg?branch=master)](https://travis-ci.com/emkor/napi-py) CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py](https://github.com/gabrys/napi.py) ## prerequisites diff --git a/setup.py b/setup.py index abb59da..95c6bfe 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name="napi-py", - version="0.1.6", + version="0.1.7", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", diff --git a/tox.ini b/tox.ini index 2456355..2ec12ab 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,6 @@ envlist = py{36,37},lint deps = pytest==5.3.* wheel==0.33.* - mypy==0.* commands = pytest -ra -v test From 67e54698cc9ba7ff8836ed47a06fe8acab1f9832 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 22 Nov 2020 18:07:58 +0100 Subject: [PATCH 35/77] include envrc for easier developemnt, add instruction for installing 7z binary under Linux --- .envrc | 4 ++++ README.md | 4 ++-- setup.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..0d4b2e7 --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +export VIRTUAL_ENV=$PWD/.venv/$(basename "$PWD") +PATH_add .venv/$(basename "$PWD")/bin +echo "Using $(python --version) from $(which python)" +source creds.sh \ No newline at end of file diff --git a/README.md b/README.md index 407dac3..7bd13a0 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py] ## prerequisites - Python 3.6 or later -- `7z` available on PATH +- `7z` executable available on PATH, can be installed on Debian-based distros with `sudo apt-get install p7zip-full` ## installation -- `sudo pip install napi-py` for system wide installation +- `pip install napi-py` for system wide installation ## usage as tool - `napi-py ~/Downloads/MyMovie.mp4` diff --git a/setup.py b/setup.py index 95c6bfe..baf1a53 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name="napi-py", - version="0.1.7", + version="0.1.8", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From 40f811a29a8356a37ae6c344c0c4e8dd6a6fda12 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 22 Nov 2020 18:20:00 +0100 Subject: [PATCH 36/77] allow using movie hash format `napiprojekt:SOMEHASH` --- README.md | 2 +- napi/main.py | 2 ++ setup.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7bd13a0..1d9f3d3 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ print(subs_path) - if there's no subtitles for your movie, there's still hope: - open the movie web page on `napiprojekt.pl` in your browser, as in example: `https://www.napiprojekt.pl/napisy1,1,1-dla-55534-Z%C5%82odziejaszki-(2018)` - choose subtitles that might match your movie, right-click them and select "Copy link" on link containing hash, which looks like this `napiprojekt:96edd6537d9852a51cbdd5b64fee9194` - - use flag `--hash YOURHASH` in this tool, i.e. `--hash 96edd6537d9852a51cbdd5b64fee9194` + - use flag `--hash YOURHASH` in this tool, i.e. `--hash 96edd6537d9852a51cbdd5b64fee9194` or `--hash napiprojekt:96edd6537d9852a51cbdd5b64fee9194` ## development - `make config` installs `venv` under `.venv/napi-py` diff --git a/napi/main.py b/napi/main.py index 022551f..b4878d7 100755 --- a/napi/main.py +++ b/napi/main.py @@ -47,6 +47,8 @@ def main(movie_path: str, subtitles_path: Optional[str] = None, use_hash: Option subtitles_path = path.abspath(subtitles_path or get_target_path_for_subtitle(movie_path)) if path.exists(movie_path): if _is_7z_on_path(): + if use_hash and use_hash.startswith('napiprojekt:'): + use_hash = use_hash.partition('napiprojekt:')[-1] try: napi_client = NapiPy() movie_hash = use_hash or napi_client.calc_hash(movie_path) diff --git a/setup.py b/setup.py index baf1a53..6b210d9 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name="napi-py", - version="0.1.8", + version="0.2.0", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From e6bb7aadcf1e3a089f4480a4da5b8c260b2f635d Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 22 Nov 2020 18:24:01 +0100 Subject: [PATCH 37/77] include testing against python 3.8 in tox, include clean command in makefile --- Makefile | 12 ++++++++---- tox.ini | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 9b30c9e..5bcf793 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ -config: venv-clean venv install +config: clean setup install all: test build PY3 = python3 VENV = .venv/$(basename $PWD) VENV_PY3 = .venv/$(basename $PWD)/bin/python3 -venv-clean: +clean: @echo "---- Doing cleanup ----" + @rm -rf .venv .tox .mypy_cache *.egg-info build dist @mkdir -p .venv - @rm -rf $(VENV) -venv: +setup: @echo "---- Setting virtualenv ----" @$(PY3) -m venv $(VENV) @echo "---- Installing dependencies and app itself in editable mode ----" @@ -27,4 +27,8 @@ build: @echo "---- Building package ---- " @$(VENV_PY3) setup.py sdist bdist_wheel --python-tag py3 --dist-dir ./dist +publish: + @echo "---- Publishing package ---- " + + .PHONY: all config test build diff --git a/tox.ini b/tox.ini index 2ec12ab..1fd41d4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,10 @@ [tox] -envlist = py{36,37},lint +envlist = lint,py{36,37,38} [testenv] deps = - pytest==5.3.* - wheel==0.33.* + pytest==6.* + wheel==0.* commands = pytest -ra -v test From 3bfd079d5913f6fbfd6c88a378c7f1b65f7a6a79 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 22 Nov 2020 18:24:45 +0100 Subject: [PATCH 38/77] bump version in relation to updating makefile --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6b210d9..8613d0e 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name="napi-py", - version="0.2.0", + version="0.2.1", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From 1bf16a4c9f735a7731e0a010f4ad1bdbed554f26 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 22 Nov 2020 18:50:19 +0100 Subject: [PATCH 39/77] change default extension to .srt, add acceptance test for CLI tool --- README.md | 8 +++++--- napi/store_subs.py | 2 +- setup.py | 2 +- test/test_acceptance_cli.py | 18 ++++++++++++++++++ ...st_acceptance.py => test_acceptance_lib.py} | 0 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 test/test_acceptance_cli.py rename test/{test_acceptance.py => test_acceptance_lib.py} (100%) diff --git a/README.md b/README.md index 1d9f3d3..f23afcb 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,16 @@ CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py](https://github.com/gabrys/napi.py) ## prerequisites -- Python 3.6 or later -- `7z` executable available on PATH, can be installed on Debian-based distros with `sudo apt-get install p7zip-full` +- Python 3.6 or newer +- `7z` executable available on PATH, can be installed: + - on Debian-based distros with `sudo apt-get install p7zip-full` + - on macOS with `brew install p7zip` using [homebrew](https://brew.sh/) ## installation - `pip install napi-py` for system wide installation ## usage as tool -- `napi-py ~/Downloads/MyMovie.mp4` +- `napi-py ~/Downloads/MyMovie.mp4` will download and save subtitles under `~/Downloads/MyMovie.srt` ## usage as lib ```python diff --git a/napi/store_subs.py b/napi/store_subs.py index a19a015..9a74f7a 100644 --- a/napi/store_subs.py +++ b/napi/store_subs.py @@ -3,7 +3,7 @@ def get_target_path_for_subtitle(movie_path: str) -> str: filename, extension = os.path.splitext(movie_path) - return filename + ".txt" + return filename + ".srt" def store_subtitles(subtitles_path: str, binary_subs: bytes) -> str: diff --git a/setup.py b/setup.py index 8613d0e..4fec1d8 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name="napi-py", - version="0.2.1", + version="1.0.0rc0", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", diff --git a/test/test_acceptance_cli.py b/test/test_acceptance_cli.py new file mode 100644 index 0000000..def1a31 --- /dev/null +++ b/test/test_acceptance_cli.py @@ -0,0 +1,18 @@ +from os import path +import subprocess +import tempfile + + +def test_should_physically_download_subtitle_file(): + with tempfile.NamedTemporaryFile() as _movie_file: + cmd = f'napi-py --from-enc utf-8 --hash 25b1087d997bfbf8a4be462255e05a05 {_movie_file.name}' + subprocess.check_call(cmd.split()) + expected_subs_file = f'{_movie_file.name}.srt' + assert path.isfile(expected_subs_file), f'Expected subtitles file under {expected_subs_file} is absent' + + with open(expected_subs_file, 'rt') as _sub_file: + subs = _sub_file.readlines() + first_20_subs = [l.strip().lower() for l in subs[:20]] + expected_sub_phrase = 'ŻOŁNIERZE KOSMOSU' + assert expected_sub_phrase.strip().lower() in first_20_subs, \ + f"{expected_sub_phrase} not found in first 20 lines of file {expected_subs_file}" diff --git a/test/test_acceptance.py b/test/test_acceptance_lib.py similarity index 100% rename from test/test_acceptance.py rename to test/test_acceptance_lib.py From 4d35cd04b5cabcb6283777d09384ff3cdaf3b670 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 22 Nov 2020 18:54:41 +0100 Subject: [PATCH 40/77] tag the release, add some minor fixes in readme --- README.md | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f23afcb..7bca74c 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py] - on macOS with `brew install p7zip` using [homebrew](https://brew.sh/) ## installation -- `pip install napi-py` for system wide installation +- `pip install napi-py` for user-wide installation -## usage as tool +## usage as CLI tool - `napi-py ~/Downloads/MyMovie.mp4` will download and save subtitles under `~/Downloads/MyMovie.srt` ## usage as lib diff --git a/setup.py b/setup.py index 4fec1d8..025f938 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name="napi-py", - version="1.0.0rc0", + version="1.0.0", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From 608702a5fc2731dd9adbf76f61168e0a540a94a4 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 22 Nov 2020 19:01:27 +0100 Subject: [PATCH 41/77] add setup for python 3.8 --- .travis.yml | 8 ++++---- setup.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d850a31..9587954 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: python cache: pip python: - - "3.6" - "3.7" + - "3.8" before_script: - sudo apt-get install -y p7zip-full @@ -10,13 +10,13 @@ before_script: script: - tox -e lint - - if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]]; then tox -e py37; else tox -e py36; fi + - if [[ $TRAVIS_PYTHON_VERSION == 3.8 ]]; then tox -e py38; else tox -e py37; fi - make build after_success: - - if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]]; then ./ci_publish.sh ; fi + - if [[ $TRAVIS_PYTHON_VERSION == 3.8 ]]; then ./ci_publish.sh ; fi notifications: email: on_success: never - on_failure: change \ No newline at end of file + on_failure: change diff --git a/setup.py b/setup.py index 025f938..5965c56 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ }, classifiers=[ "Programming Language :: Python :: 3", - "Development Status :: 3 - Alpha", + "Development Status :: 3 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Affero General Public License v3", From 8a5887495721e59c094d8cb52cbdc248640c77ad Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 22 Nov 2020 19:09:37 +0100 Subject: [PATCH 42/77] include verifying twine installation --- ci_publish.sh | 1 - setup.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci_publish.sh b/ci_publish.sh index 60668a2..0c04fe7 100755 --- a/ci_publish.sh +++ b/ci_publish.sh @@ -3,7 +3,6 @@ set -e if [ "$TRAVIS_BRANCH" == "master" ]; then - pip install --upgrade twine echo "Uploading as user: $PYPI_USER" twine upload -u $PYPI_USER -p $PYPI_PASSWORD dist/* else diff --git a/setup.py b/setup.py index 5965c56..10adcd3 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,8 @@ REQUIREMENTS_DEV = [ "tox==3.*", - "wheel==0.*" + "wheel==0.*", + "twine" ] with open("README.md", "r") as fh: From 5ac5e6d57b10f35cbf4d2ff25b0ce5d15db35a53 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 22 Nov 2020 19:27:02 +0100 Subject: [PATCH 43/77] remove beta classifier --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 10adcd3..47e4d20 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,6 @@ }, classifiers=[ "Programming Language :: Python :: 3", - "Development Status :: 3 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Affero General Public License v3", From 1a2355192e3c0cd33227799a3fdd2b3fc1e94a7a Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 23 Nov 2020 18:41:56 +0100 Subject: [PATCH 44/77] implement detecting encoding correctly, implement acceptance tests --- napi/encoding.py | 25 +++++++++++++++++++++++- test/test_acceptance_cli.py | 35 +++++++++++++++++++++++++++------ test/test_encoding.py | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 test/test_encoding.py diff --git a/napi/encoding.py b/napi/encoding.py index 3d40393..b6afa16 100644 --- a/napi/encoding.py +++ b/napi/encoding.py @@ -2,13 +2,36 @@ from typing import Tuple, Optional DECODING_ORDER = ["windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "utf-8"] +SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 = ["Ĺş", "ĹĽ", "Ĺ‚", "Ĺ›", "ć", "Ä…", "Ä™", "Ăł", "Ĺ„"] +POLISH_DIACRITICS = ["ź", "ż", "ł", "ś", "ć", "ą", "ę", "ó", "ń"] +CHECK_IN_WORD_COUNT = 1000 + + +def _diacritics_count_in_word(word: str) -> int: + return len([pd for pd in POLISH_DIACRITICS + if pd.lower() in word.lower()]) + + +def _err_symbol_count_in_word(word: str) -> int: + return len([err_sym for err_sym in SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 + if err_sym.lower() in word.lower()]) + + +def _is_correct_encoding(subs: str) -> bool: + err_symbols, diacritics = 0, 0 + for word in subs.split()[:CHECK_IN_WORD_COUNT]: + diacritics += _diacritics_count_in_word(word) + err_symbols += _err_symbol_count_in_word(word) + return err_symbols < diacritics def _try_decode(subs: bytes) -> Tuple[str, str]: last_exc = None for i, enc in enumerate(DECODING_ORDER): try: - return enc, subs.decode(enc) + encoded_subs = subs.decode(enc) + if _is_correct_encoding(encoded_subs): + return enc, encoded_subs except UnicodeDecodeError as e: last_exc = e raise ValueError("Could not encode using any of {}: {}".format(DECODING_ORDER, last_exc)) diff --git a/test/test_acceptance_cli.py b/test/test_acceptance_cli.py index def1a31..acd1517 100644 --- a/test/test_acceptance_cli.py +++ b/test/test_acceptance_cli.py @@ -1,6 +1,18 @@ from os import path import subprocess import tempfile +from typing import List + + +def _read_first_lines_of_subs(subs_file: str, lines: int = 20) -> List[str]: + with open(subs_file, 'rt') as _sub_file: + subs = _sub_file.readlines() + return [l.strip() for l in subs[:lines]] + + +def _contains_phrase(phrase: str, text: List[str]) -> bool: + phrase = phrase.strip().lower() + return any([phrase in line.strip().lower() for line in text]) def test_should_physically_download_subtitle_file(): @@ -10,9 +22,20 @@ def test_should_physically_download_subtitle_file(): expected_subs_file = f'{_movie_file.name}.srt' assert path.isfile(expected_subs_file), f'Expected subtitles file under {expected_subs_file} is absent' - with open(expected_subs_file, 'rt') as _sub_file: - subs = _sub_file.readlines() - first_20_subs = [l.strip().lower() for l in subs[:20]] - expected_sub_phrase = 'ŻOŁNIERZE KOSMOSU' - assert expected_sub_phrase.strip().lower() in first_20_subs, \ - f"{expected_sub_phrase} not found in first 20 lines of file {expected_subs_file}" + first_20_lines = _read_first_lines_of_subs(expected_subs_file, 20) + expected_phrase = 'ŻOŁNIERZE KOSMOSU' + assert _contains_phrase(expected_phrase, first_20_lines), \ + f"{expected_phrase} not found in first 20 lines of file {expected_subs_file}" + + +def test_should_download_and_correctly_encode_utf8_src_subs(): + with tempfile.NamedTemporaryFile() as _movie_file: + cmd = f'napi-py --from-enc utf-8 --hash 0e9b0d0d3dc5abc0538d207d477af4a1 {_movie_file.name}' + subprocess.check_call(cmd.split()) + expected_subs_file = f'{_movie_file.name}.srt' + assert path.isfile(expected_subs_file), f'Expected subtitles file under {expected_subs_file} is absent' + + first_20_lines = _read_first_lines_of_subs(expected_subs_file, 20) + expected_phrase = 'rządzie ciąży' + assert _contains_phrase(expected_phrase, first_20_lines), \ + f"{expected_phrase} not found in first 20 lines of file {expected_subs_file}" diff --git a/test/test_encoding.py b/test/test_encoding.py new file mode 100644 index 0000000..069878a --- /dev/null +++ b/test/test_encoding.py @@ -0,0 +1,39 @@ +from napi.encoding import _is_correct_encoding + +CORRECT_SUBS = """1 +00:00:09,320 --> 00:00:15,000 +Na rządzie ciąży presja, +by pilnie zredukować wzrost cen jedzenia. + +2 +00:00:15,320 --> 00:00:20,000 +Najnowszy indeks cen żywności wskazuje, +że w ciągu ostatniego półrocza + +3 +00:00:20,320 --> 00:00:25,400 +wartość wielu artykułów podwoiła się, +co odbiło się na wzroście cen.""" + +INCORRECT_SUB = """1 +00:00:09,320 --> 00:00:15,000 +Na rzÄ…dzie ciÄ…ĹĽy presja, +by pilnie zredukować wzrost cen jedzenia. + +2 +00:00:15,320 --> 00:00:20,000 +Najnowszy indeks cen ĹĽywnoĹ›ci wskazuje, +ĹĽe w ciÄ…gu ostatniego półrocza + +3 +00:00:20,320 --> 00:00:25,400 +wartość wielu artykułów podwoiĹ‚a siÄ™, +co odbiĹ‚o siÄ™ na wzroĹ›cie cen.""" + + +def test_should_detect_correct_encoding(): + assert _is_correct_encoding(CORRECT_SUBS) is True, f"Failed to detect correct encoding" + + +def test_should_detect_incorrect_encoding(): + assert _is_correct_encoding(INCORRECT_SUB) is False, f"Failed to detect incorrect encoding" From 6612cb115c7ea0a1c54358ba090670a7e79afd14 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 23 Nov 2020 19:07:01 +0100 Subject: [PATCH 45/77] remove unused creds.sh sourcing in .envrc --- .envrc | 1 - 1 file changed, 1 deletion(-) diff --git a/.envrc b/.envrc index 0d4b2e7..da3e81b 100644 --- a/.envrc +++ b/.envrc @@ -1,4 +1,3 @@ export VIRTUAL_ENV=$PWD/.venv/$(basename "$PWD") PATH_add .venv/$(basename "$PWD")/bin echo "Using $(python --version) from $(which python)" -source creds.sh \ No newline at end of file From 4971ec6c0f7eb3f881337a966a505567b06df1fd Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 23 Nov 2020 19:08:56 +0100 Subject: [PATCH 46/77] switch to using raw pytest instead of tox --- Makefile | 24 +++++++++++++------ setup.py | 7 +++--- test/{ => acceptance}/test_acceptance_cli.py | 0 test/{ => acceptance}/test_acceptance_lib.py | 0 test/{ => unit}/test_encoding.py | 0 test/{ => unit}/test_sub_dl_and_conversion.py | 0 6 files changed, 21 insertions(+), 10 deletions(-) rename test/{ => acceptance}/test_acceptance_cli.py (100%) rename test/{ => acceptance}/test_acceptance_lib.py (100%) rename test/{ => unit}/test_encoding.py (100%) rename test/{ => unit}/test_sub_dl_and_conversion.py (100%) diff --git a/Makefile b/Makefile index 5bcf793..aa62a77 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ config: clean setup install +test: ut lint at all: test build PY3 = python3 -VENV = .venv/$(basename $PWD) -VENV_PY3 = .venv/$(basename $PWD)/bin/python3 +VENV = .venv/$(shell basename $$PWD) +VENV_PY3 = .venv/$(shell basename $$PWD)/bin/python3 clean: @echo "---- Doing cleanup ----" @@ -11,17 +12,26 @@ clean: @mkdir -p .venv setup: - @echo "---- Setting virtualenv ----" + @echo "---- Setting up virtualenv ----" @$(PY3) -m venv $(VENV) @echo "---- Installing dependencies and app itself in editable mode ----" @$(VENV_PY3) -m pip install --upgrade pip install: + @echo "---- Installing napi-py ---- " @$(VENV_PY3) -m pip install -e .[dev] -test: - @echo "---- Testing ---- " - @$(VENV_PY3) -m tox +lint: + @echo "---- Running linter ---- " + @$(VENV_PY3) -m mypy -v --ignore-missing-imports napi + +ut: + @echo "---- Running unit tests ---- " + @$(VENV_PY3) -m pytest -ra -v test/unit + +at: + @echo "---- Running acceptance tests ---- " + @$(VENV_PY3) -m pytest -ra -v test/acceptance build: @echo "---- Building package ---- " @@ -29,6 +39,6 @@ build: publish: @echo "---- Publishing package ---- " - + @$(VENV_PY3) -m twine upload -u $PYPI_USER -p $PYPI_PASSWORD dist/* .PHONY: all config test build diff --git a/setup.py b/setup.py index 47e4d20..716a095 100644 --- a/setup.py +++ b/setup.py @@ -5,9 +5,10 @@ ] REQUIREMENTS_DEV = [ - "tox==3.*", - "wheel==0.*", - "twine" + "mypy==0.*", + "pytest==6.*", + "twine", + "wheel==0.*" ] with open("README.md", "r") as fh: diff --git a/test/test_acceptance_cli.py b/test/acceptance/test_acceptance_cli.py similarity index 100% rename from test/test_acceptance_cli.py rename to test/acceptance/test_acceptance_cli.py diff --git a/test/test_acceptance_lib.py b/test/acceptance/test_acceptance_lib.py similarity index 100% rename from test/test_acceptance_lib.py rename to test/acceptance/test_acceptance_lib.py diff --git a/test/test_encoding.py b/test/unit/test_encoding.py similarity index 100% rename from test/test_encoding.py rename to test/unit/test_encoding.py diff --git a/test/test_sub_dl_and_conversion.py b/test/unit/test_sub_dl_and_conversion.py similarity index 100% rename from test/test_sub_dl_and_conversion.py rename to test/unit/test_sub_dl_and_conversion.py From 9032fae1a0b3ab54734c5318bd81c0e6b710a76e Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 23 Nov 2020 19:12:25 +0100 Subject: [PATCH 47/77] remove tox.ini, switch to using makefile on CI --- .travis.yml | 5 +++-- Makefile | 8 ++------ setup.py | 2 +- tox.ini | 15 --------------- 4 files changed, 6 insertions(+), 24 deletions(-) delete mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml index 9587954..fbfe97e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,9 @@ before_script: - make config script: - - tox -e lint - - if [[ $TRAVIS_PYTHON_VERSION == 3.8 ]]; then tox -e py38; else tox -e py37; fi + - make lint + - make ut + - make at - make build after_success: diff --git a/Makefile b/Makefile index aa62a77..4436082 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ VENV_PY3 = .venv/$(shell basename $$PWD)/bin/python3 clean: @echo "---- Doing cleanup ----" - @rm -rf .venv .tox .mypy_cache *.egg-info build dist + @rm -rf .venv .mypy_cache *.egg-info build dist @mkdir -p .venv setup: @@ -37,8 +37,4 @@ build: @echo "---- Building package ---- " @$(VENV_PY3) setup.py sdist bdist_wheel --python-tag py3 --dist-dir ./dist -publish: - @echo "---- Publishing package ---- " - @$(VENV_PY3) -m twine upload -u $PYPI_USER -p $PYPI_PASSWORD dist/* - -.PHONY: all config test build +.PHONY: all config test build clean setup install lint ut at diff --git a/setup.py b/setup.py index 716a095..517ce97 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name="napi-py", - version="1.0.0", + version="1.1.0rc0", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 1fd41d4..0000000 --- a/tox.ini +++ /dev/null @@ -1,15 +0,0 @@ -[tox] -envlist = lint,py{36,37,38} - -[testenv] -deps = - pytest==6.* - wheel==0.* -commands = - pytest -ra -v test - -[testenv:lint] -deps = - mypy==0.* -commands = - mypy --ignore-missing-imports napi \ No newline at end of file From 9f679d612e3cbb786e417a2d1700f9789cabfc03 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 23 Nov 2020 19:16:33 +0100 Subject: [PATCH 48/77] bump minor versions --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 517ce97..202388a 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name="napi-py", - version="1.1.0rc0", + version="1.1.0", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From c35d33b15298583d032131d699d5252228d83850 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Tue, 24 Nov 2020 11:07:06 +0100 Subject: [PATCH 49/77] rewrite the tests to use pytest approach --- test/acceptance/test_acceptance_lib.py | 57 ++++++++++++------------- test/unit/test_sub_dl_and_conversion.py | 52 +++++++++++----------- 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/test/acceptance/test_acceptance_lib.py b/test/acceptance/test_acceptance_lib.py index 7602859..0f0e1c8 100644 --- a/test/acceptance/test_acceptance_lib.py +++ b/test/acceptance/test_acceptance_lib.py @@ -1,38 +1,37 @@ -import unittest - from napi import NapiPy -class NapiPyAcceptanceTest(unittest.TestCase): - def test_should_download_correctly_encoded_subs(self): - movie_hash = '25b1087d997bfbf8a4be462255e05a05' - napi = NapiPy() - src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash) - self.assertEqual(src_enc, "utf-8") +def test_should_download_correctly_encoded_subs(): + movie_hash = '25b1087d997bfbf8a4be462255e05a05' + napi = NapiPy() + src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash) + assert src_enc == "utf-8" + + with open(tmp_file) as subs_file: + subs = subs_file.read() + + expected_phrases = ['źródło', 'władzę', 'Dziękuję', 'zgłębiają', 'ZWYCIĘŻĄ!'] + for expected_phrase in expected_phrases: + assert expected_phrase in subs - with open(tmp_file) as subs_file: - subs = subs_file.read() - expected_phrases = ['źródło', 'władzę', 'Dziękuję', 'zgłębiają', 'ZWYCIĘŻĄ!'] - for expected_phrase in expected_phrases: - self.assertIn(expected_phrase, subs) +def test_should_return_none_when_no_subtitles_for_movie(): + movie_hash = '00000000000000000000000000000000' + napi = NapiPy() + src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash) + assert src_enc is None + assert tmp_file is None - def test_should_return_none_when_no_subtitles_for_movie(self): - movie_hash = '00000000000000000000000000000000' - napi = NapiPy() - src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash) - self.assertIsNone(src_enc) - self.assertIsNone(tmp_file) - def test_should_download_subs_with_forced_encoding(self): - movie_hash = '0e9b0d0d3dc5abc0538d207d477af4a1' - napi = NapiPy() - src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash, use_enc="utf-8") - self.assertEqual(src_enc, "utf-8") +def test_should_download_subs_with_forced_encoding(): + movie_hash = '0e9b0d0d3dc5abc0538d207d477af4a1' + napi = NapiPy() + src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash, use_enc="utf-8") + assert src_enc == "utf-8" - with open(tmp_file) as subs_file: - subs = subs_file.read() + with open(tmp_file) as subs_file: + subs = subs_file.read() - expected_phrases = ['ciąży', 'artykułów', 'Właśnie', 'wyjść', 'wciąż'] - for expected_phrase in expected_phrases: - self.assertIn(expected_phrase, subs) + expected_phrases = ['ciąży', 'artykułów', 'Właśnie', 'wyjść', 'wciąż'] + for expected_phrase in expected_phrases: + assert expected_phrase in subs diff --git a/test/unit/test_sub_dl_and_conversion.py b/test/unit/test_sub_dl_and_conversion.py index 34f4c79..c69b05c 100644 --- a/test/unit/test_sub_dl_and_conversion.py +++ b/test/unit/test_sub_dl_and_conversion.py @@ -1,5 +1,4 @@ import os -import unittest from os import path from napi.api import _build_url @@ -15,28 +14,29 @@ def _get_project_dir(file_: str) -> str: return path.join(code_directory, proj_dir) -class NapiPyTest(unittest.TestCase): - def test_should_generate_correct_url(self): - movie_hash = '6e7d92a7c0f40706067248d50d3b1d5a' - expected_url = 'http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f=6e7d92a7c0f40706067248d50d3b1d5a&t=c6705&v=other&kolejka=false&nick=&pass=&napios={}'.format( - os.name) - actual_url = _build_url(movie_hash) - self.assertEqual(expected_url, actual_url) - - def test_should_unpack_downloaded_7zip(self): - subs_path = path.join(_get_project_dir(__file__), TEST_SUBS_7Z) - with open(subs_path, 'rb') as input_file: - compressed_content = input_file.read() - sub_bin_content = un7zip_api_response(compressed_content) - expected_phrase = b"GrupaHatak.pl" - self.assertIn(expected_phrase, sub_bin_content) - - def test_should_encode_subtitles_correctly(self): - subs_path = path.join(_get_project_dir(__file__), TEST_SUBS_7Z) - with open(subs_path, 'rb') as input_file: - compressed_content = input_file.read() - sub_bin_content = un7zip_api_response(compressed_content) - _, sub_utf8_content = decode_subs(sub_bin_content) - expected_phrases = ['Tłumaczenie', 'Dunkierką', 'Francuzów', 'Uwięzieni'] - for expected_phrase in expected_phrases: - self.assertIn(expected_phrase, sub_utf8_content) +def test_should_generate_correct_url(): + movie_hash = '6e7d92a7c0f40706067248d50d3b1d5a' + expected_url = 'http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f=6e7d92a7c0f40706067248d50d3b1d5a&t=c6705&v=other&kolejka=false&nick=&pass=&napios={}'.format( + os.name) + actual_url = _build_url(movie_hash) + assert expected_url == actual_url + + +def test_should_unpack_downloaded_7zip(): + subs_path = path.join(_get_project_dir(__file__), TEST_SUBS_7Z) + with open(subs_path, 'rb') as input_file: + compressed_content = input_file.read() + sub_bin_content = un7zip_api_response(compressed_content) + expected_phrase = b"GrupaHatak.pl" + assert expected_phrase in sub_bin_content + + +def test_should_encode_subtitles_correctly(): + subs_path = path.join(_get_project_dir(__file__), TEST_SUBS_7Z) + with open(subs_path, 'rb') as input_file: + compressed_content = input_file.read() + sub_bin_content = un7zip_api_response(compressed_content) + _, sub_utf8_content = decode_subs(sub_bin_content) + expected_phrases = ['Tłumaczenie', 'Dunkierką', 'Francuzów', 'Uwięzieni'] + for expected_phrase in expected_phrases: + assert expected_phrase in sub_utf8_content From f28a55706ba10d756aee51652d9778bbe5350ab3 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Tue, 24 Nov 2020 11:07:15 +0100 Subject: [PATCH 50/77] support python 3.6 in travis CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index fbfe97e..9b1baf4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python cache: pip python: + - "3.6" - "3.7" - "3.8" From 4396174a63247487ff0bf10574c6eb349266186c Mon Sep 17 00:00:00 2001 From: emkor93 Date: Tue, 24 Nov 2020 11:24:13 +0100 Subject: [PATCH 51/77] update patch revision as the changes were not in functionality --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 202388a..b21ae4c 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name="napi-py", - version="1.1.0", + version="1.1.1", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From e879bfde82a37cc8058adfb04e20959496679be8 Mon Sep 17 00:00:00 2001 From: lipowskm <54337215+lipowskm@users.noreply.github.com> Date: Wed, 2 Dec 2020 21:49:06 +0100 Subject: [PATCH 52/77] Remove the usage of 7z (#2) * implement archive extraction using pylzma instead of using 7z in subprocess, update setup.py * Update README.md * Update setup.py --- README.md | 3 --- napi/read_7z.py | 37 ++++++------------------------------- setup.py | 4 +++- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 7bca74c..e418e88 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,6 @@ CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py] ## prerequisites - Python 3.6 or newer -- `7z` executable available on PATH, can be installed: - - on Debian-based distros with `sudo apt-get install p7zip-full` - - on macOS with `brew install p7zip` using [homebrew](https://brew.sh/) ## installation - `pip install napi-py` for user-wide installation diff --git a/napi/read_7z.py b/napi/read_7z.py index f26eb53..0af49a7 100644 --- a/napi/read_7z.py +++ b/napi/read_7z.py @@ -1,39 +1,14 @@ -from subprocess import Popen, PIPE -from tempfile import NamedTemporaryFile +from io import BytesIO from typing import Optional +from py7zlib import Archive7z, ArchiveError -TMP_FILE_SUFFIX = ".7z" -TMP_FILE_PREFIX = "un7zip" NAPI_ARCHIVE_PASSWORD = "iBlm8NTigvru0Jr0" -class Un7ZipError(Exception): - pass - - -def un7zip(archive, password=None): - tmp_file = NamedTemporaryFile(prefix=TMP_FILE_PREFIX, suffix=TMP_FILE_SUFFIX) - tmp_file.write(archive) - tmp_file.flush() - - cmd = ["7z", "x", "-y", "-so"] - if password is not None: - cmd += ["-p" + password] - cmd += [tmp_file.name] - - sp = Popen(cmd, stdout=PIPE, stderr=PIPE) - - content = sp.communicate()[0] - - if sp.wait() != 0: - raise Un7ZipError("Downloaded archive with subtitles is broken!") - - tmp_file.close() # deletes the file - return content - - def un7zip_api_response(content_7z: bytes) -> Optional[bytes]: try: - return un7zip(content_7z, password=NAPI_ARCHIVE_PASSWORD) - except Un7ZipError: + buffer = BytesIO(content_7z) + archive = Archive7z(buffer, password=NAPI_ARCHIVE_PASSWORD) + return archive.getmember(0).read() + except ArchiveError: return None diff --git a/setup.py b/setup.py index b21ae4c..79cdabb 100644 --- a/setup.py +++ b/setup.py @@ -2,10 +2,12 @@ from setuptools import find_packages REQUIREMENTS = [ + "pylzma==0.*" ] REQUIREMENTS_DEV = [ "mypy==0.*", + "pylzma==0.*", "pytest==6.*", "twine", "wheel==0.*" @@ -16,7 +18,7 @@ setup( name="napi-py", - version="1.1.1", + version="1.1.2", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From ff03d43df1c1cbda2d98f743135d1a331104df55 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 25 Dec 2020 19:08:31 +0100 Subject: [PATCH 53/77] implement workflow for github actions --- .github/workflows/main.yml | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..1d09f6d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,50 @@ +name: CI + +on: push + +jobs: + + test: + name: Test with Python ${{ matrix.python-version }} + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: [ 3.6, 3.7, 3.8 ] + steps: + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up virtualenv, install from source + run: make config + - name: Run unit tests and static analysis + run: make lint ut + - name: Build distributable package + run: make build + - name: Install the package globally + run: for pkg in $(find dist/napi-py*.tar.gz); do pip3 install $pkg; done + - name: Run acceptance tests + run: make at + + release: + name: Publish the package + needs: test + if: ${{ github.ref == 'master' }} + runs-on: ubuntu-20.04 + steps: + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up virtualenv, install from source + run: make config + - name: Build distributable package + run: make build + - name: List files + run: find . -type f | grep -v .venv | sort + - name: Release package + run: twine upload -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* From 54ece62b4b82369bb1d9825eab64eba60704296a Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 25 Dec 2020 19:09:21 +0100 Subject: [PATCH 54/77] fix test failing due to double `napi-py` phrase in project path appearing in github actions CI environment --- test/unit/test_sub_dl_and_conversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/test_sub_dl_and_conversion.py b/test/unit/test_sub_dl_and_conversion.py index c69b05c..52c0fe7 100644 --- a/test/unit/test_sub_dl_and_conversion.py +++ b/test/unit/test_sub_dl_and_conversion.py @@ -10,7 +10,7 @@ def _get_project_dir(file_: str) -> str: curr_dir = os.path.dirname(os.path.realpath(file_)) - code_directory, proj_dir, _ = curr_dir.partition("napi-py") + code_directory, proj_dir, _ = curr_dir.rpartition("napi-py") return path.join(code_directory, proj_dir) From 196e659d942abf747c435863ec8f92fe6a4475b8 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 25 Dec 2020 19:09:43 +0100 Subject: [PATCH 55/77] change the CI badge to github-provided one --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e418e88..75e474d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# napi-py [![Build Status](https://travis-ci.com/emkor/napi-py.svg?branch=master)](https://travis-ci.com/emkor/napi-py) +# napi-py ![CI](https://github.com/emkor/napi-py/workflows/CI/badge.svg) CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py](https://github.com/gabrys/napi.py) ## prerequisites From f24738df5eca057707dbb118258401b527b949cd Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 25 Dec 2020 19:10:00 +0100 Subject: [PATCH 56/77] remove travis CI - related configuration --- .travis.yml | 24 ------------------------ ci_publish.sh | 10 ---------- 2 files changed, 34 deletions(-) delete mode 100644 .travis.yml delete mode 100755 ci_publish.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9b1baf4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: python -cache: pip -python: - - "3.6" - - "3.7" - - "3.8" - -before_script: - - sudo apt-get install -y p7zip-full - - make config - -script: - - make lint - - make ut - - make at - - make build - -after_success: - - if [[ $TRAVIS_PYTHON_VERSION == 3.8 ]]; then ./ci_publish.sh ; fi - -notifications: - email: - on_success: never - on_failure: change diff --git a/ci_publish.sh b/ci_publish.sh deleted file mode 100755 index 0c04fe7..0000000 --- a/ci_publish.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -e - -if [ "$TRAVIS_BRANCH" == "master" ]; then - echo "Uploading as user: $PYPI_USER" - twine upload -u $PYPI_USER -p $PYPI_PASSWORD dist/* - else - echo "Not on CI master branch, not publishing" -fi \ No newline at end of file From 0742efb52a1fde029d9b6fea7133570ac4d41238 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 25 Dec 2020 19:10:10 +0100 Subject: [PATCH 57/77] bump patch revision --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 79cdabb..de7ed1e 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( name="napi-py", - version="1.1.2", + version="1.1.3", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From faacc62a02700a6ad34d24b698003bdeb1634e93 Mon Sep 17 00:00:00 2001 From: Mateusz Korzeniowski Date: Fri, 25 Dec 2020 19:17:20 +0100 Subject: [PATCH 58/77] Update main.yml correct conditional for checking for master branch --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1d09f6d..d552661 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,7 +31,7 @@ jobs: release: name: Publish the package needs: test - if: ${{ github.ref == 'master' }} + if: ${{ github.ref == 'refs/heads/master' }} runs-on: ubuntu-20.04 steps: - name: Set up Python ${{ matrix.python-version }} From f393c392307c38d065e620c8dcdd86374c12e7f0 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 25 Dec 2020 19:21:58 +0100 Subject: [PATCH 59/77] install twine globally, remove it from dependencies --- .github/workflows/main.yml | 4 +++- Makefile | 2 +- setup.py | 4 +--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d552661..0ca285a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,4 +47,6 @@ jobs: - name: List files run: find . -type f | grep -v .venv | sort - name: Release package - run: twine upload -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* + run: | + pip3 install twine + twine upload -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* diff --git a/Makefile b/Makefile index 4436082..5b53ba8 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ setup: @echo "---- Setting up virtualenv ----" @$(PY3) -m venv $(VENV) @echo "---- Installing dependencies and app itself in editable mode ----" - @$(VENV_PY3) -m pip install --upgrade pip + @$(VENV_PY3) -m pip install --upgrade pip wheel setuptools install: @echo "---- Installing napi-py ---- " diff --git a/setup.py b/setup.py index de7ed1e..7e1696d 100644 --- a/setup.py +++ b/setup.py @@ -2,15 +2,13 @@ from setuptools import find_packages REQUIREMENTS = [ - "pylzma==0.*" + "pylzma==0.*", ] REQUIREMENTS_DEV = [ "mypy==0.*", "pylzma==0.*", "pytest==6.*", - "twine", - "wheel==0.*" ] with open("README.md", "r") as fh: From 86f896cb633b8205ca6f20994749b577ef1eeb96 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 25 Dec 2020 19:27:57 +0100 Subject: [PATCH 60/77] remove no-longer-required 7z-executable leftovers --- napi/main.py | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/napi/main.py b/napi/main.py index b4878d7..7598a82 100755 --- a/napi/main.py +++ b/napi/main.py @@ -1,6 +1,5 @@ import argparse import logging -import shutil import time import traceback from os import path @@ -12,7 +11,6 @@ EXIT_CODE_OK = 0 EXIT_CODE_WRONG_ARGS = 1 EXIT_CODE_NO_SUCH_MOVIE = 2 -EXIT_CODE_LACK_OF_7Z_ON_PATH = 3 EXIT_SUBS_NOT_FOUND = 4 EXIT_CODE_FAILED = 5 @@ -36,38 +34,30 @@ def _parse_args() -> argparse.Namespace: return parser.parse_args() -def _is_7z_on_path(command: str = "7z") -> bool: - return shutil.which(command) is not None - - def main(movie_path: str, subtitles_path: Optional[str] = None, use_hash: Optional[str] = None, from_enc: Optional[str] = None) -> None: log = logging.getLogger() movie_path = path.abspath(movie_path) subtitles_path = path.abspath(subtitles_path or get_target_path_for_subtitle(movie_path)) if path.exists(movie_path): - if _is_7z_on_path(): - if use_hash and use_hash.startswith('napiprojekt:'): - use_hash = use_hash.partition('napiprojekt:')[-1] - try: - napi_client = NapiPy() - movie_hash = use_hash or napi_client.calc_hash(movie_path) - log.info("Downloading subs for {} (hash: {})".format(path.basename(movie_path), movie_hash)) - src_enc, tgt_src, tmp_file = napi_client.download_subs(movie_hash, use_enc=from_enc) - if src_enc is not None and tmp_file is not None: - subs_path = napi_client.move_subs(tmp_file, subtitles_path) \ - if subtitles_path else napi_client.move_subs_to_movie(tmp_file, movie_path) - log.info("Saved subs ({} -> {}) in {}".format(src_enc, tgt_src, subs_path)) - else: - log.error("Napiprojekt.pl does not have subtitles for this movie") - exit(EXIT_SUBS_NOT_FOUND) - except Exception as e: - traceback.print_exc() - log.error(e) - exit(EXIT_CODE_FAILED) - else: - log.error("7z seems to be unavailable on PATH!") - exit(EXIT_CODE_LACK_OF_7Z_ON_PATH) + if use_hash and use_hash.startswith('napiprojekt:'): + use_hash = use_hash.partition('napiprojekt:')[-1] + try: + napi_client = NapiPy() + movie_hash = use_hash or napi_client.calc_hash(movie_path) + log.info("Downloading subs for {} (hash: {})".format(path.basename(movie_path), movie_hash)) + src_enc, tgt_src, tmp_file = napi_client.download_subs(movie_hash, use_enc=from_enc) + if src_enc is not None and tmp_file is not None: + subs_path = napi_client.move_subs(tmp_file, subtitles_path) \ + if subtitles_path else napi_client.move_subs_to_movie(tmp_file, movie_path) + log.info("Saved subs ({} -> {}) in {}".format(src_enc, tgt_src, subs_path)) + else: + log.error("Napiprojekt.pl does not have subtitles for this movie") + exit(EXIT_SUBS_NOT_FOUND) + except Exception as e: + traceback.print_exc() + log.error(e) + exit(EXIT_CODE_FAILED) else: log.error("No such file: {}".format(movie_path)) exit(EXIT_CODE_NO_SUCH_MOVIE) From 2088e67b38a7aff24a9ef99aa740ae285619f489 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 25 Dec 2020 19:28:36 +0100 Subject: [PATCH 61/77] fix bug with cross-device error while moving subs from /tmp to mounted network share on macOS --- napi/napi.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/napi/napi.py b/napi/napi.py index f3dcab6..3ff1afa 100644 --- a/napi/napi.py +++ b/napi/napi.py @@ -1,3 +1,4 @@ +import os import shutil import tempfile from typing import Tuple, Optional @@ -28,9 +29,11 @@ def download_subs(self, movie_hash: str, use_enc: Optional[str] = None) -> Tuple def move_subs_to_movie(self, tmp_subs: str, movie: str) -> str: tgt_path = get_target_path_for_subtitle(movie) - shutil.move(tmp_subs, tgt_path) + shutil.copy(tmp_subs, tgt_path) + os.remove(tmp_subs) return tgt_path def move_subs(self, tmp_subs: str, path: str) -> str: - shutil.move(tmp_subs, path) + shutil.copy(tmp_subs, path) + os.remove(tmp_subs) return path From 59f64fc4a4adbd01f6ee8fde92bec7dc05fb2a63 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Fri, 25 Dec 2020 19:29:55 +0100 Subject: [PATCH 62/77] correct grammar errors in readme, include python3-dev package as explicit requirement for pylzma dependency, bump revision --- Makefile | 10 +++++----- README.md | 5 +++-- setup.py | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 5b53ba8..d3b545f 100644 --- a/Makefile +++ b/Makefile @@ -18,23 +18,23 @@ setup: @$(VENV_PY3) -m pip install --upgrade pip wheel setuptools install: - @echo "---- Installing napi-py ---- " + @echo "---- Installing napi-py in virtualenv ---- " @$(VENV_PY3) -m pip install -e .[dev] lint: @echo "---- Running linter ---- " - @$(VENV_PY3) -m mypy -v --ignore-missing-imports napi + @$(VENV_PY3) -m mypy --ignore-missing-imports napi ut: @echo "---- Running unit tests ---- " - @$(VENV_PY3) -m pytest -ra -v test/unit + @$(VENV_PY3) -m pytest -ra -v -s test/unit at: - @echo "---- Running acceptance tests ---- " + @echo "---- Running acceptance tests (requires napi-py on global PATH) ---- " @$(VENV_PY3) -m pytest -ra -v test/acceptance build: - @echo "---- Building package ---- " + @echo "---- Building distributable package ---- " @$(VENV_PY3) setup.py sdist bdist_wheel --python-tag py3 --dist-dir ./dist .PHONY: all config test build clean setup install lint ut at diff --git a/README.md b/README.md index 75e474d..5ce80c6 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py] ## prerequisites - Python 3.6 or newer +- on Linux, `python3-dev` package: + - for Debian-based systems, use `sudo apt-get install python3-dev` ## installation - `pip install napi-py` for user-wide installation @@ -24,8 +26,7 @@ print(subs_path) ``` ## in case of issues -- if there's issue with weird characters in downloaded subtitles, try to re-download and use flag `--from-enc utf-8` -- if there's no subtitles for your movie, there's still hope: +- if there are no subs for your movie, there's still hope: - open the movie web page on `napiprojekt.pl` in your browser, as in example: `https://www.napiprojekt.pl/napisy1,1,1-dla-55534-Z%C5%82odziejaszki-(2018)` - choose subtitles that might match your movie, right-click them and select "Copy link" on link containing hash, which looks like this `napiprojekt:96edd6537d9852a51cbdd5b64fee9194` - use flag `--hash YOURHASH` in this tool, i.e. `--hash 96edd6537d9852a51cbdd5b64fee9194` or `--hash napiprojekt:96edd6537d9852a51cbdd5b64fee9194` diff --git a/setup.py b/setup.py index 7e1696d..f939182 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name="napi-py", - version="1.1.3", + version="1.1.4", description="CLI tool for downloading subtitles from napiprojekt.pl", author="Mateusz Korzeniowski", author_email="emkor93@gmail.com", From e5f3ff3661ca1de92bc75704f12912a7f617e977 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 31 May 2021 22:34:37 +0200 Subject: [PATCH 63/77] switch from setup.py to poetry tool for dependency management --- .envrc | 3 - .github/workflows/main.yml | 28 ++-- Makefile | 40 ++--- mypy.ini | 5 + napi/__init__.py | 2 - poetry.lock | 307 +++++++++++++++++++++++++++++++++++++ pyproject.toml | 25 +++ setup.py | 46 ------ 8 files changed, 365 insertions(+), 91 deletions(-) delete mode 100644 .envrc create mode 100644 mypy.ini create mode 100644 poetry.lock create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.envrc b/.envrc deleted file mode 100644 index da3e81b..0000000 --- a/.envrc +++ /dev/null @@ -1,3 +0,0 @@ -export VIRTUAL_ENV=$PWD/.venv/$(basename "$PWD") -PATH_add .venv/$(basename "$PWD")/bin -echo "Using $(python --version) from $(which python)" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0ca285a..8cc5343 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: [ 3.6, 3.7, 3.8 ] + python-version: [ 3.6, 3.7, 3.8, 3.9 ] steps: - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 @@ -17,16 +17,14 @@ jobs: python-version: ${{ matrix.python-version }} - name: Checkout code uses: actions/checkout@v2 - - name: Set up virtualenv, install from source - run: make config + - name: Install poetry + run: pip install poetry + - name: Set up virtualenv + run: make install - name: Run unit tests and static analysis - run: make lint ut + run: make test - name: Build distributable package run: make build - - name: Install the package globally - run: for pkg in $(find dist/napi-py*.tar.gz); do pip3 install $pkg; done - - name: Run acceptance tests - run: make at release: name: Publish the package @@ -37,16 +35,16 @@ jobs: - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: 3.9 - name: Checkout code uses: actions/checkout@v2 - - name: Set up virtualenv, install from source - run: make config + - name: Install poetry + run: pip install poetry + - name: Install from source + run: make install - name: Build distributable package run: make build - name: List files run: find . -type f | grep -v .venv | sort - - name: Release package - run: | - pip3 install twine - twine upload -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* + - name: Publish package to pypi + run: poetry publish --username ${{ secrets.PYPI_USER }} --password ${{ secrets.PYPI_PASSWORD }} diff --git a/Makefile b/Makefile index d3b545f..b627407 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,30 @@ -config: clean setup install -test: ut lint at -all: test build +test: lint unit-test acceptance-test +all: clean test build -PY3 = python3 -VENV = .venv/$(shell basename $$PWD) -VENV_PY3 = .venv/$(shell basename $$PWD)/bin/python3 +POETRY = poetry clean: @echo "---- Doing cleanup ----" - @rm -rf .venv .mypy_cache *.egg-info build dist - @mkdir -p .venv - -setup: - @echo "---- Setting up virtualenv ----" - @$(PY3) -m venv $(VENV) - @echo "---- Installing dependencies and app itself in editable mode ----" - @$(VENV_PY3) -m pip install --upgrade pip wheel setuptools + @rm -rf .mypy_cache .pytest_cache dist install: - @echo "---- Installing napi-py in virtualenv ---- " - @$(VENV_PY3) -m pip install -e .[dev] + @echo "---- Installing package ---- " + @$(POETRY) install lint: - @echo "---- Running linter ---- " - @$(VENV_PY3) -m mypy --ignore-missing-imports napi + @echo "---- Running type check and linter ---- " + @$(POETRY) run mypy napi -ut: +unit-test: @echo "---- Running unit tests ---- " - @$(VENV_PY3) -m pytest -ra -v -s test/unit + @$(POETRY) run pytest -ra -vv test/unit -at: - @echo "---- Running acceptance tests (requires napi-py on global PATH) ---- " - @$(VENV_PY3) -m pytest -ra -v test/acceptance +acceptance-test: + @echo "---- Running acceptance tests ---- " + @$(POETRY) run pytest -ra -vv test/acceptance build: - @echo "---- Building distributable package ---- " - @$(VENV_PY3) setup.py sdist bdist_wheel --python-tag py3 --dist-dir ./dist + @echo "---- Build distributable ---- " + @$(POETRY) build .PHONY: all config test build clean setup install lint ut at diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..2c31f82 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,5 @@ +[mypy] +warn_unused_configs = True + +[mypy-py7zlib] +ignore_missing_imports = True \ No newline at end of file diff --git a/napi/__init__.py b/napi/__init__.py index 15098ab..70a6c08 100644 --- a/napi/__init__.py +++ b/napi/__init__.py @@ -1,3 +1 @@ from napi.napi import NapiPy - -name = "napi-py" diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..e1b6101 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,307 @@ +[[package]] +name = "atomicwrites" +version = "1.4.0" +description = "Atomic file writes." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[[package]] +name = "attrs" +version = "21.2.0" +description = "Classes Without Boilerplate" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[package.extras] +dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit"] +docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] +tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface"] +tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins"] + +[[package]] +name = "colorama" +version = "0.4.4" +description = "Cross-platform colored terminal text." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "importlib-metadata" +version = "4.4.0" +description = "Read metadata from Python packages" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} +zipp = ">=0.5" + +[package.extras] +docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] +testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] + +[[package]] +name = "iniconfig" +version = "1.1.1" +description = "iniconfig: brain-dead simple config-ini parsing" +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "mypy" +version = "0.812" +description = "Optional static typing for Python" +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.dependencies] +mypy-extensions = ">=0.4.3,<0.5.0" +typed-ast = ">=1.4.0,<1.5.0" +typing-extensions = ">=3.7.4" + +[package.extras] +dmypy = ["psutil (>=4.0)"] + +[[package]] +name = "mypy-extensions" +version = "0.4.3" +description = "Experimental type system extensions for programs checked with the mypy typechecker." +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "packaging" +version = "20.9" +description = "Core utilities for Python packages" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[package.dependencies] +pyparsing = ">=2.0.2" + +[[package]] +name = "pluggy" +version = "0.13.1" +description = "plugin and hook calling mechanisms for python" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[package.dependencies] +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} + +[package.extras] +dev = ["pre-commit", "tox"] + +[[package]] +name = "py" +version = "1.10.0" +description = "library with cross-python path, ini-parsing, io, code, log facilities" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[[package]] +name = "pylzma" +version = "0.5.0" +description = "Python bindings for the LZMA library by Igor Pavlov." +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "pyparsing" +version = "2.4.7" +description = "Python parsing module" +category = "dev" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" + +[[package]] +name = "pytest" +version = "6.2.4" +description = "pytest: simple powerful testing with Python" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} +attrs = ">=19.2.0" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<1.0.0a1" +py = ">=1.8.2" +toml = "*" + +[package.extras] +testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] + +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +category = "dev" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" + +[[package]] +name = "typed-ast" +version = "1.4.3" +description = "a fork of Python 2 and 3 ast modules with type comment support" +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "typing-extensions" +version = "3.10.0.0" +description = "Backported and Experimental Type Hints for Python 3.5+" +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "zipp" +version = "3.4.1" +description = "Backport of pathlib-compatible object wrapper for zip files" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.extras] +docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] +testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "pytest-enabler", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"] + +[metadata] +lock-version = "1.1" +python-versions = "^3.6" +content-hash = "f0ab05cc5251ccffe33641f1598e82052c60f1e14f4e212bd9c5c70cc5b16927" + +[metadata.files] +atomicwrites = [ + {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, + {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, +] +attrs = [ + {file = "attrs-21.2.0-py2.py3-none-any.whl", hash = "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1"}, + {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"}, +] +colorama = [ + {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, + {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, +] +importlib-metadata = [ + {file = "importlib_metadata-4.4.0-py3-none-any.whl", hash = "sha256:960d52ba7c21377c990412aca380bf3642d734c2eaab78a2c39319f67c6a5786"}, + {file = "importlib_metadata-4.4.0.tar.gz", hash = "sha256:e592faad8de1bda9fe920cf41e15261e7131bcf266c30306eec00e8e225c1dd5"}, +] +iniconfig = [ + {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, + {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, +] +mypy = [ + {file = "mypy-0.812-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:a26f8ec704e5a7423c8824d425086705e381b4f1dfdef6e3a1edab7ba174ec49"}, + {file = "mypy-0.812-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:28fb5479c494b1bab244620685e2eb3c3f988d71fd5d64cc753195e8ed53df7c"}, + {file = "mypy-0.812-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:9743c91088d396c1a5a3c9978354b61b0382b4e3c440ce83cf77994a43e8c521"}, + {file = "mypy-0.812-cp35-cp35m-win_amd64.whl", hash = "sha256:d7da2e1d5f558c37d6e8c1246f1aec1e7349e4913d8fb3cb289a35de573fe2eb"}, + {file = "mypy-0.812-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:4eec37370483331d13514c3f55f446fc5248d6373e7029a29ecb7b7494851e7a"}, + {file = "mypy-0.812-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:d65cc1df038ef55a99e617431f0553cd77763869eebdf9042403e16089fe746c"}, + {file = "mypy-0.812-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:61a3d5b97955422964be6b3baf05ff2ce7f26f52c85dd88db11d5e03e146a3a6"}, + {file = "mypy-0.812-cp36-cp36m-win_amd64.whl", hash = "sha256:25adde9b862f8f9aac9d2d11971f226bd4c8fbaa89fb76bdadb267ef22d10064"}, + {file = "mypy-0.812-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:552a815579aa1e995f39fd05dde6cd378e191b063f031f2acfe73ce9fb7f9e56"}, + {file = "mypy-0.812-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:499c798053cdebcaa916eef8cd733e5584b5909f789de856b482cd7d069bdad8"}, + {file = "mypy-0.812-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:5873888fff1c7cf5b71efbe80e0e73153fe9212fafdf8e44adfe4c20ec9f82d7"}, + {file = "mypy-0.812-cp37-cp37m-win_amd64.whl", hash = "sha256:9f94aac67a2045ec719ffe6111df543bac7874cee01f41928f6969756e030564"}, + {file = "mypy-0.812-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d23e0ea196702d918b60c8288561e722bf437d82cb7ef2edcd98cfa38905d506"}, + {file = "mypy-0.812-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:674e822aa665b9fd75130c6c5f5ed9564a38c6cea6a6432ce47eafb68ee578c5"}, + {file = "mypy-0.812-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:abf7e0c3cf117c44d9285cc6128856106183938c68fd4944763003decdcfeb66"}, + {file = "mypy-0.812-cp38-cp38-win_amd64.whl", hash = "sha256:0d0a87c0e7e3a9becdfbe936c981d32e5ee0ccda3e0f07e1ef2c3d1a817cf73e"}, + {file = "mypy-0.812-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7ce3175801d0ae5fdfa79b4f0cfed08807af4d075b402b7e294e6aa72af9aa2a"}, + {file = "mypy-0.812-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:b09669bcda124e83708f34a94606e01b614fa71931d356c1f1a5297ba11f110a"}, + {file = "mypy-0.812-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:33f159443db0829d16f0a8d83d94df3109bb6dd801975fe86bacb9bf71628e97"}, + {file = "mypy-0.812-cp39-cp39-win_amd64.whl", hash = "sha256:3f2aca7f68580dc2508289c729bd49ee929a436208d2b2b6aab15745a70a57df"}, + {file = "mypy-0.812-py3-none-any.whl", hash = "sha256:2f9b3407c58347a452fc0736861593e105139b905cca7d097e413453a1d650b4"}, + {file = "mypy-0.812.tar.gz", hash = "sha256:cd07039aa5df222037005b08fbbfd69b3ab0b0bd7a07d7906de75ae52c4e3119"}, +] +mypy-extensions = [ + {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, + {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, +] +packaging = [ + {file = "packaging-20.9-py2.py3-none-any.whl", hash = "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"}, + {file = "packaging-20.9.tar.gz", hash = "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"}, +] +pluggy = [ + {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, + {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, +] +py = [ + {file = "py-1.10.0-py2.py3-none-any.whl", hash = "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"}, + {file = "py-1.10.0.tar.gz", hash = "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3"}, +] +pylzma = [ + {file = "pylzma-0.5.0.tar.gz", hash = "sha256:b874172afbf37770e643bf2dc9d9b6b03eb95d8f8162e157145b3fe9e1b68a1c"}, +] +pyparsing = [ + {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, + {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, +] +pytest = [ + {file = "pytest-6.2.4-py3-none-any.whl", hash = "sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890"}, + {file = "pytest-6.2.4.tar.gz", hash = "sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b"}, +] +toml = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] +typed-ast = [ + {file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:2068531575a125b87a41802130fa7e29f26c09a2833fea68d9a40cf33902eba6"}, + {file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:c907f561b1e83e93fad565bac5ba9c22d96a54e7ea0267c708bffe863cbe4075"}, + {file = "typed_ast-1.4.3-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:1b3ead4a96c9101bef08f9f7d1217c096f31667617b58de957f690c92378b528"}, + {file = "typed_ast-1.4.3-cp35-cp35m-win32.whl", hash = "sha256:dde816ca9dac1d9c01dd504ea5967821606f02e510438120091b84e852367428"}, + {file = "typed_ast-1.4.3-cp35-cp35m-win_amd64.whl", hash = "sha256:777a26c84bea6cd934422ac2e3b78863a37017618b6e5c08f92ef69853e765d3"}, + {file = "typed_ast-1.4.3-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f8afcf15cc511ada719a88e013cec87c11aff7b91f019295eb4530f96fe5ef2f"}, + {file = "typed_ast-1.4.3-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:52b1eb8c83f178ab787f3a4283f68258525f8d70f778a2f6dd54d3b5e5fb4341"}, + {file = "typed_ast-1.4.3-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:01ae5f73431d21eead5015997ab41afa53aa1fbe252f9da060be5dad2c730ace"}, + {file = "typed_ast-1.4.3-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:c190f0899e9f9f8b6b7863debfb739abcb21a5c054f911ca3596d12b8a4c4c7f"}, + {file = "typed_ast-1.4.3-cp36-cp36m-win32.whl", hash = "sha256:398e44cd480f4d2b7ee8d98385ca104e35c81525dd98c519acff1b79bdaac363"}, + {file = "typed_ast-1.4.3-cp36-cp36m-win_amd64.whl", hash = "sha256:bff6ad71c81b3bba8fa35f0f1921fb24ff4476235a6e94a26ada2e54370e6da7"}, + {file = "typed_ast-1.4.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0fb71b8c643187d7492c1f8352f2c15b4c4af3f6338f21681d3681b3dc31a266"}, + {file = "typed_ast-1.4.3-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:760ad187b1041a154f0e4d0f6aae3e40fdb51d6de16e5c99aedadd9246450e9e"}, + {file = "typed_ast-1.4.3-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:5feca99c17af94057417d744607b82dd0a664fd5e4ca98061480fd8b14b18d04"}, + {file = "typed_ast-1.4.3-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:95431a26309a21874005845c21118c83991c63ea800dd44843e42a916aec5899"}, + {file = "typed_ast-1.4.3-cp37-cp37m-win32.whl", hash = "sha256:aee0c1256be6c07bd3e1263ff920c325b59849dc95392a05f258bb9b259cf39c"}, + {file = "typed_ast-1.4.3-cp37-cp37m-win_amd64.whl", hash = "sha256:9ad2c92ec681e02baf81fdfa056fe0d818645efa9af1f1cd5fd6f1bd2bdfd805"}, + {file = "typed_ast-1.4.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:b36b4f3920103a25e1d5d024d155c504080959582b928e91cb608a65c3a49e1a"}, + {file = "typed_ast-1.4.3-cp38-cp38-manylinux1_i686.whl", hash = "sha256:067a74454df670dcaa4e59349a2e5c81e567d8d65458d480a5b3dfecec08c5ff"}, + {file = "typed_ast-1.4.3-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7538e495704e2ccda9b234b82423a4038f324f3a10c43bc088a1636180f11a41"}, + {file = "typed_ast-1.4.3-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:af3d4a73793725138d6b334d9d247ce7e5f084d96284ed23f22ee626a7b88e39"}, + {file = "typed_ast-1.4.3-cp38-cp38-win32.whl", hash = "sha256:f2362f3cb0f3172c42938946dbc5b7843c2a28aec307c49100c8b38764eb6927"}, + {file = "typed_ast-1.4.3-cp38-cp38-win_amd64.whl", hash = "sha256:dd4a21253f42b8d2b48410cb31fe501d32f8b9fbeb1f55063ad102fe9c425e40"}, + {file = "typed_ast-1.4.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:f328adcfebed9f11301eaedfa48e15bdece9b519fb27e6a8c01aa52a17ec31b3"}, + {file = "typed_ast-1.4.3-cp39-cp39-manylinux1_i686.whl", hash = "sha256:2c726c276d09fc5c414693a2de063f521052d9ea7c240ce553316f70656c84d4"}, + {file = "typed_ast-1.4.3-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:cae53c389825d3b46fb37538441f75d6aecc4174f615d048321b716df2757fb0"}, + {file = "typed_ast-1.4.3-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:b9574c6f03f685070d859e75c7f9eeca02d6933273b5e69572e5ff9d5e3931c3"}, + {file = "typed_ast-1.4.3-cp39-cp39-win32.whl", hash = "sha256:209596a4ec71d990d71d5e0d312ac935d86930e6eecff6ccc7007fe54d703808"}, + {file = "typed_ast-1.4.3-cp39-cp39-win_amd64.whl", hash = "sha256:9c6d1a54552b5330bc657b7ef0eae25d00ba7ffe85d9ea8ae6540d2197a3788c"}, + {file = "typed_ast-1.4.3.tar.gz", hash = "sha256:fb1bbeac803adea29cedd70781399c99138358c26d05fcbd23c13016b7f5ec65"}, +] +typing-extensions = [ + {file = "typing_extensions-3.10.0.0-py2-none-any.whl", hash = "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497"}, + {file = "typing_extensions-3.10.0.0-py3-none-any.whl", hash = "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84"}, + {file = "typing_extensions-3.10.0.0.tar.gz", hash = "sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342"}, +] +zipp = [ + {file = "zipp-3.4.1-py3-none-any.whl", hash = "sha256:51cb66cc54621609dd593d1787f286ee42a5c0adbb4b29abea5a63edc3e03098"}, + {file = "zipp-3.4.1.tar.gz", hash = "sha256:3607921face881ba3e026887d8150cca609d517579abe052ac81fc5aeffdbd76"}, +] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cbade4f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,25 @@ +[tool.poetry] +name = "napi-py" +version = "0.1.5" +description = "CLI tool for downloading subtitles from napiprojekt.pl" +authors = ["emkor93 "] +license = "GPL-3.0 License" +readme = "README.md" +homepage = "https://github.com/emkor/napi-py" +repository = "https://github.com/emkor/napi-py" +keywords = ["napiprojekt", "subs", "subtitles", "movie", "film"] +packages = [ + { include = "napi" }, +] + +[tool.poetry.dependencies] +python = "^3.6" +pylzma = "^0.5.0" + +[tool.poetry.dev-dependencies] +mypy = "^0.812" +pytest = "^6.2.4" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/setup.py b/setup.py deleted file mode 100644 index f939182..0000000 --- a/setup.py +++ /dev/null @@ -1,46 +0,0 @@ -from distutils.core import setup -from setuptools import find_packages - -REQUIREMENTS = [ - "pylzma==0.*", -] - -REQUIREMENTS_DEV = [ - "mypy==0.*", - "pylzma==0.*", - "pytest==6.*", -] - -with open("README.md", "r") as fh: - long_description = fh.read() - -setup( - name="napi-py", - version="1.1.4", - description="CLI tool for downloading subtitles from napiprojekt.pl", - author="Mateusz Korzeniowski", - author_email="emkor93@gmail.com", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/emkor/napi-py", - packages=find_packages(exclude=("test", "test.*")), - install_requires=REQUIREMENTS, - tests_require=REQUIREMENTS_DEV, - extras_require={ - "dev": REQUIREMENTS_DEV - }, - entry_points={ - "console_scripts": [ - "napi-py = napi.main:cli_main" - ] - }, - classifiers=[ - "Programming Language :: Python :: 3", - "Environment :: Console", - "Intended Audience :: Developers", - "License :: OSI Approved :: GNU Affero General Public License v3", - "Natural Language :: English", - "Operating System :: POSIX :: Linux", - "Topic :: Utilities" - ], -) From eb1375771e6319f03b5b3897c1e00199e8c509d2 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 31 May 2021 22:40:26 +0200 Subject: [PATCH 64/77] switch from check_call to run in acceptance tests --- .github/workflows/main.yml | 2 +- test/acceptance/test_acceptance_cli.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8cc5343..dd3ff58 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: run: pip install poetry - name: Set up virtualenv run: make install - - name: Run unit tests and static analysis + - name: Run tests run: make test - name: Build distributable package run: make build diff --git a/test/acceptance/test_acceptance_cli.py b/test/acceptance/test_acceptance_cli.py index acd1517..19187fd 100644 --- a/test/acceptance/test_acceptance_cli.py +++ b/test/acceptance/test_acceptance_cli.py @@ -18,7 +18,7 @@ def _contains_phrase(phrase: str, text: List[str]) -> bool: def test_should_physically_download_subtitle_file(): with tempfile.NamedTemporaryFile() as _movie_file: cmd = f'napi-py --from-enc utf-8 --hash 25b1087d997bfbf8a4be462255e05a05 {_movie_file.name}' - subprocess.check_call(cmd.split()) + subprocess.run(cmd.split(), timeout=10.) expected_subs_file = f'{_movie_file.name}.srt' assert path.isfile(expected_subs_file), f'Expected subtitles file under {expected_subs_file} is absent' @@ -31,7 +31,7 @@ def test_should_physically_download_subtitle_file(): def test_should_download_and_correctly_encode_utf8_src_subs(): with tempfile.NamedTemporaryFile() as _movie_file: cmd = f'napi-py --from-enc utf-8 --hash 0e9b0d0d3dc5abc0538d207d477af4a1 {_movie_file.name}' - subprocess.check_call(cmd.split()) + subprocess.run(cmd.split(), timeout=10.) expected_subs_file = f'{_movie_file.name}.srt' assert path.isfile(expected_subs_file), f'Expected subtitles file under {expected_subs_file} is absent' From 00498f66f8af589d4154595950c0a8c0eb54e5fd Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 31 May 2021 22:42:35 +0200 Subject: [PATCH 65/77] register CLI entrypoint in poetry --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index cbade4f..c17a1d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,9 @@ pylzma = "^0.5.0" mypy = "^0.812" pytest = "^6.2.4" +[tool.poetry.scripts] +napi-py = 'napi.main:cli_main' + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" From 7d59e8ee20706810fb398604bd6ad4da5f755c64 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 31 May 2021 22:59:33 +0200 Subject: [PATCH 66/77] add black code reformatter as a part of CI job --- Makefile | 1 + README.md | 6 +-- napi/api.py | 9 ++-- napi/encoding.py | 41 +++++++++++--- napi/hash.py | 2 +- napi/main.py | 79 ++++++++++++++++++++------- napi/napi.py | 4 +- poetry.lock | 136 ++++++++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 3 +- 9 files changed, 243 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index b627407..4b281e8 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ install: lint: @echo "---- Running type check and linter ---- " @$(POETRY) run mypy napi + @$(POETRY) run black napi unit-test: @echo "---- Running unit tests ---- " diff --git a/README.md b/README.md index 5ce80c6..83479df 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# napi-py ![CI](https://github.com/emkor/napi-py/workflows/CI/badge.svg) +# napi-py ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/napi-py) ![CI](https://github.com/emkor/napi-py/workflows/CI/badge.svg) CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py](https://github.com/gabrys/napi.py) ## prerequisites -- Python 3.6 or newer +- Python 3.6.2 or newer - on Linux, `python3-dev` package: - for Debian-based systems, use `sudo apt-get install python3-dev` @@ -32,6 +32,6 @@ print(subs_path) - use flag `--hash YOURHASH` in this tool, i.e. `--hash 96edd6537d9852a51cbdd5b64fee9194` or `--hash napiprojekt:96edd6537d9852a51cbdd5b64fee9194` ## development -- `make config` installs `venv` under `.venv/napi-py` +- `make install` installs poetry virtualenv - `make test` runs tests - `make build` creates installable package diff --git a/napi/api.py b/napi/api.py index 1c21423..f8b0d9c 100644 --- a/napi/api.py +++ b/napi/api.py @@ -3,9 +3,9 @@ def _cipher(z): - idx = [0xe, 0x3, 0x6, 0x8, 0x2] + idx = [0xE, 0x3, 0x6, 0x8, 0x2] mul = [2, 2, 5, 4, 3] - add = [0, 0xd, 0x10, 0xb, 0x5] + add = [0, 0xD, 0x10, 0xB, 0x5] b = [] for i in range(len(idx)): @@ -14,7 +14,7 @@ def _cipher(z): i = idx[i] t = a + int(z[i], 16) - v = int(z[t:t + 2], 16) + v = int(z[t : t + 2], 16) b.append(("%x" % (v * m))[-1]) return "".join(b) @@ -22,7 +22,8 @@ def _cipher(z): def _build_url(movie_hash): return "http://napiprojekt.pl/unit_napisy/dl.php?l=PL&f={}&t={}&v=other&kolejka=false&nick=&pass=&napios={}".format( - movie_hash, _cipher(movie_hash), os.name) + movie_hash, _cipher(movie_hash), os.name + ) def download_for(movie_hash: str) -> bytes: diff --git a/napi/encoding.py b/napi/encoding.py index b6afa16..2c3dc95 100644 --- a/napi/encoding.py +++ b/napi/encoding.py @@ -1,20 +1,41 @@ import locale from typing import Tuple, Optional -DECODING_ORDER = ["windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "utf-8"] -SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 = ["Ĺş", "ĹĽ", "Ĺ‚", "Ĺ›", "ć", "Ä…", "Ä™", "Ăł", "Ĺ„"] +DECODING_ORDER = [ + "windows-1250", + "windows-1251", + "windows-1252", + "windows-1253", + "windows-1254", + "utf-8", +] +SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 = [ + "Ĺş", + "ĹĽ", + "Ĺ‚", + "Ĺ›", + "ć", + "Ä…", + "Ä™", + "Ăł", + "Ĺ„", +] POLISH_DIACRITICS = ["ź", "ż", "ł", "ś", "ć", "ą", "ę", "ó", "ń"] CHECK_IN_WORD_COUNT = 1000 def _diacritics_count_in_word(word: str) -> int: - return len([pd for pd in POLISH_DIACRITICS - if pd.lower() in word.lower()]) + return len([pd for pd in POLISH_DIACRITICS if pd.lower() in word.lower()]) def _err_symbol_count_in_word(word: str) -> int: - return len([err_sym for err_sym in SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 - if err_sym.lower() in word.lower()]) + return len( + [ + err_sym + for err_sym in SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 + if err_sym.lower() in word.lower() + ] + ) def _is_correct_encoding(subs: str) -> bool: @@ -34,10 +55,14 @@ def _try_decode(subs: bytes) -> Tuple[str, str]: return enc, encoded_subs except UnicodeDecodeError as e: last_exc = e - raise ValueError("Could not encode using any of {}: {}".format(DECODING_ORDER, last_exc)) + raise ValueError( + "Could not encode using any of {}: {}".format(DECODING_ORDER, last_exc) + ) -def decode_subs(subtitles_binary: bytes, use_enc: Optional[str] = None) -> Tuple[str, str]: +def decode_subs( + subtitles_binary: bytes, use_enc: Optional[str] = None +) -> Tuple[str, str]: if use_enc is not None: return use_enc, subtitles_binary.decode(use_enc) else: diff --git a/napi/hash.py b/napi/hash.py index f504f92..e2f0436 100644 --- a/napi/hash.py +++ b/napi/hash.py @@ -5,7 +5,7 @@ def calc_movie_hash_as_hex(movie_path: str) -> str: md5_hash_gen = hashlib.md5() - with open(movie_path, mode='rb') as movie_file: + with open(movie_path, mode="rb") as movie_file: content_of_first_10mbs = movie_file.read(SIZE_10_MBs_IN_BYTES) md5_hash_gen.update(content_of_first_10mbs) return md5_hash_gen.hexdigest() diff --git a/napi/main.py b/napi/main.py index 7598a82..af6c740 100755 --- a/napi/main.py +++ b/napi/main.py @@ -16,7 +16,9 @@ def setup_logger(level: int = logging.INFO) -> None: - logging.basicConfig(format='%(asctime)s UTC | %(levelname)s | %(message)s', level=level) + logging.basicConfig( + format="%(asctime)s UTC | %(levelname)s | %(message)s", level=level + ) logging.Formatter.converter = time.gmtime @@ -25,32 +27,68 @@ class NoMatchingSubtitle(Exception): def _parse_args() -> argparse.Namespace: - parser = argparse.ArgumentParser(prog="napi-py", description='CLI for downloading subtitles from napiprojekt.pl') - parser.add_argument('movie_path', type=str, help='Path to movie file') - parser.add_argument('--target', type=str, required=False, default=None, help='Path to store the subtitles in') - parser.add_argument('--hash', type=str, required=False, default=None, help='Use given hash for this movie') - parser.add_argument('--from-enc', type=str, required=False, default=None, - help='Treat downloaded subs as this encoding instead of guessing') + parser = argparse.ArgumentParser( + prog="napi-py", description="CLI for downloading subtitles from napiprojekt.pl" + ) + parser.add_argument("movie_path", type=str, help="Path to movie file") + parser.add_argument( + "--target", + type=str, + required=False, + default=None, + help="Path to store the subtitles in", + ) + parser.add_argument( + "--hash", + type=str, + required=False, + default=None, + help="Use given hash for this movie", + ) + parser.add_argument( + "--from-enc", + type=str, + required=False, + default=None, + help="Treat downloaded subs as this encoding instead of guessing", + ) return parser.parse_args() -def main(movie_path: str, subtitles_path: Optional[str] = None, use_hash: Optional[str] = None, - from_enc: Optional[str] = None) -> None: +def main( + movie_path: str, + subtitles_path: Optional[str] = None, + use_hash: Optional[str] = None, + from_enc: Optional[str] = None, +) -> None: log = logging.getLogger() movie_path = path.abspath(movie_path) - subtitles_path = path.abspath(subtitles_path or get_target_path_for_subtitle(movie_path)) + subtitles_path = path.abspath( + subtitles_path or get_target_path_for_subtitle(movie_path) + ) if path.exists(movie_path): - if use_hash and use_hash.startswith('napiprojekt:'): - use_hash = use_hash.partition('napiprojekt:')[-1] + if use_hash and use_hash.startswith("napiprojekt:"): + use_hash = use_hash.partition("napiprojekt:")[-1] try: napi_client = NapiPy() movie_hash = use_hash or napi_client.calc_hash(movie_path) - log.info("Downloading subs for {} (hash: {})".format(path.basename(movie_path), movie_hash)) - src_enc, tgt_src, tmp_file = napi_client.download_subs(movie_hash, use_enc=from_enc) + log.info( + "Downloading subs for {} (hash: {})".format( + path.basename(movie_path), movie_hash + ) + ) + src_enc, tgt_src, tmp_file = napi_client.download_subs( + movie_hash, use_enc=from_enc + ) if src_enc is not None and tmp_file is not None: - subs_path = napi_client.move_subs(tmp_file, subtitles_path) \ - if subtitles_path else napi_client.move_subs_to_movie(tmp_file, movie_path) - log.info("Saved subs ({} -> {}) in {}".format(src_enc, tgt_src, subs_path)) + subs_path = ( + napi_client.move_subs(tmp_file, subtitles_path) + if subtitles_path + else napi_client.move_subs_to_movie(tmp_file, movie_path) + ) + log.info( + "Saved subs ({} -> {}) in {}".format(src_enc, tgt_src, subs_path) + ) else: log.error("Napiprojekt.pl does not have subtitles for this movie") exit(EXIT_SUBS_NOT_FOUND) @@ -68,7 +106,12 @@ def cli_main(): log = logging.getLogger() try: args = _parse_args() - main(args.movie_path, subtitles_path=args.target, use_hash=args.hash, from_enc=args.from_enc) + main( + args.movie_path, + subtitles_path=args.target, + use_hash=args.hash, + from_enc=args.from_enc, + ) except Exception as e: log.error("Parameters error: {}".format(e)) exit(EXIT_CODE_WRONG_ARGS) diff --git a/napi/napi.py b/napi/napi.py index 3ff1afa..32f7595 100644 --- a/napi/napi.py +++ b/napi/napi.py @@ -17,7 +17,9 @@ def __init__(self) -> None: def calc_hash(self, movie: str) -> str: return calc_movie_hash_as_hex(movie) - def download_subs(self, movie_hash: str, use_enc: Optional[str] = None) -> Tuple[Optional[str], Optional[str], Optional[str]]: + def download_subs( + self, movie_hash: str, use_enc: Optional[str] = None + ) -> Tuple[Optional[str], Optional[str], Optional[str]]: subs_bin = un7zip_api_response(download_for(movie_hash)) if subs_bin: src_enc, subs_utf8 = decode_subs(subs_bin, use_enc=use_enc) diff --git a/poetry.lock b/poetry.lock index e1b6101..843e151 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,3 +1,11 @@ +[[package]] +name = "appdirs" +version = "1.4.4" +description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "atomicwrites" version = "1.4.0" @@ -20,6 +28,43 @@ docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface"] tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins"] +[[package]] +name = "black" +version = "21.5b2" +description = "The uncompromising code formatter." +category = "dev" +optional = false +python-versions = ">=3.6.2" + +[package.dependencies] +appdirs = "*" +click = ">=7.1.2" +dataclasses = {version = ">=0.6", markers = "python_version < \"3.7\""} +mypy-extensions = ">=0.4.3" +pathspec = ">=0.8.1,<1" +regex = ">=2020.1.8" +toml = ">=0.10.1" +typed-ast = {version = ">=1.4.2", markers = "python_version < \"3.8\""} +typing-extensions = {version = ">=3.7.4", markers = "python_version < \"3.8\""} + +[package.extras] +colorama = ["colorama (>=0.4.3)"] +d = ["aiohttp (>=3.6.0)", "aiohttp-cors (>=0.4.0)"] +python2 = ["typed-ast (>=1.4.2)"] +uvloop = ["uvloop (>=0.15.2)"] + +[[package]] +name = "click" +version = "8.0.1" +description = "Composable command line interface toolkit" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} + [[package]] name = "colorama" version = "0.4.4" @@ -28,6 +73,14 @@ category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +[[package]] +name = "dataclasses" +version = "0.8" +description = "A backport of the dataclasses module for Python 3.6" +category = "dev" +optional = false +python-versions = ">=3.6, <3.7" + [[package]] name = "importlib-metadata" version = "4.4.0" @@ -87,6 +140,14 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" [package.dependencies] pyparsing = ">=2.0.2" +[[package]] +name = "pathspec" +version = "0.8.1" +description = "Utility library for gitignore style pattern matching of file paths." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + [[package]] name = "pluggy" version = "0.13.1" @@ -147,6 +208,14 @@ toml = "*" [package.extras] testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] +[[package]] +name = "regex" +version = "2021.4.4" +description = "Alternative regular expression module, to replace re." +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "toml" version = "0.10.2" @@ -185,10 +254,14 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt [metadata] lock-version = "1.1" -python-versions = "^3.6" -content-hash = "f0ab05cc5251ccffe33641f1598e82052c60f1e14f4e212bd9c5c70cc5b16927" +python-versions = "^3.6.2" +content-hash = "cee1ee354530fd9f6ff760e52d0768b674d54d65a766a53711e21b0bd26404bf" [metadata.files] +appdirs = [ + {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, + {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, +] atomicwrites = [ {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, @@ -197,10 +270,22 @@ attrs = [ {file = "attrs-21.2.0-py2.py3-none-any.whl", hash = "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1"}, {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"}, ] +black = [ + {file = "black-21.5b2-py3-none-any.whl", hash = "sha256:e5cf21ebdffc7a9b29d73912b6a6a9a4df4ce70220d523c21647da2eae0751ef"}, + {file = "black-21.5b2.tar.gz", hash = "sha256:1fc0e0a2c8ae7d269dfcf0c60a89afa299664f3e811395d40b1922dff8f854b5"}, +] +click = [ + {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"}, + {file = "click-8.0.1.tar.gz", hash = "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"}, +] colorama = [ {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, ] +dataclasses = [ + {file = "dataclasses-0.8-py3-none-any.whl", hash = "sha256:0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf"}, + {file = "dataclasses-0.8.tar.gz", hash = "sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97"}, +] importlib-metadata = [ {file = "importlib_metadata-4.4.0-py3-none-any.whl", hash = "sha256:960d52ba7c21377c990412aca380bf3642d734c2eaab78a2c39319f67c6a5786"}, {file = "importlib_metadata-4.4.0.tar.gz", hash = "sha256:e592faad8de1bda9fe920cf41e15261e7131bcf266c30306eec00e8e225c1dd5"}, @@ -241,6 +326,10 @@ packaging = [ {file = "packaging-20.9-py2.py3-none-any.whl", hash = "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"}, {file = "packaging-20.9.tar.gz", hash = "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"}, ] +pathspec = [ + {file = "pathspec-0.8.1-py2.py3-none-any.whl", hash = "sha256:aa0cb481c4041bf52ffa7b0d8fa6cd3e88a2ca4879c533c9153882ee2556790d"}, + {file = "pathspec-0.8.1.tar.gz", hash = "sha256:86379d6b86d75816baba717e64b1a3a3469deb93bb76d613c9ce79edc5cb68fd"}, +] pluggy = [ {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, @@ -260,6 +349,49 @@ pytest = [ {file = "pytest-6.2.4-py3-none-any.whl", hash = "sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890"}, {file = "pytest-6.2.4.tar.gz", hash = "sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b"}, ] +regex = [ + {file = "regex-2021.4.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:619d71c59a78b84d7f18891fe914446d07edd48dc8328c8e149cbe0929b4e000"}, + {file = "regex-2021.4.4-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:47bf5bf60cf04d72bf6055ae5927a0bd9016096bf3d742fa50d9bf9f45aa0711"}, + {file = "regex-2021.4.4-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:281d2fd05555079448537fe108d79eb031b403dac622621c78944c235f3fcf11"}, + {file = "regex-2021.4.4-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:bd28bc2e3a772acbb07787c6308e00d9626ff89e3bfcdebe87fa5afbfdedf968"}, + {file = "regex-2021.4.4-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:7c2a1af393fcc09e898beba5dd59196edaa3116191cc7257f9224beaed3e1aa0"}, + {file = "regex-2021.4.4-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:c38c71df845e2aabb7fb0b920d11a1b5ac8526005e533a8920aea97efb8ec6a4"}, + {file = "regex-2021.4.4-cp36-cp36m-manylinux2014_i686.whl", hash = "sha256:96fcd1888ab4d03adfc9303a7b3c0bd78c5412b2bfbe76db5b56d9eae004907a"}, + {file = "regex-2021.4.4-cp36-cp36m-manylinux2014_x86_64.whl", hash = "sha256:ade17eb5d643b7fead300a1641e9f45401c98eee23763e9ed66a43f92f20b4a7"}, + {file = "regex-2021.4.4-cp36-cp36m-win32.whl", hash = "sha256:e8e5b509d5c2ff12f8418006d5a90e9436766133b564db0abaec92fd27fcee29"}, + {file = "regex-2021.4.4-cp36-cp36m-win_amd64.whl", hash = "sha256:11d773d75fa650cd36f68d7ca936e3c7afaae41b863b8c387a22aaa78d3c5c79"}, + {file = "regex-2021.4.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:d3029c340cfbb3ac0a71798100ccc13b97dddf373a4ae56b6a72cf70dfd53bc8"}, + {file = "regex-2021.4.4-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:18c071c3eb09c30a264879f0d310d37fe5d3a3111662438889ae2eb6fc570c31"}, + {file = "regex-2021.4.4-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:4c557a7b470908b1712fe27fb1ef20772b78079808c87d20a90d051660b1d69a"}, + {file = "regex-2021.4.4-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:01afaf2ec48e196ba91b37451aa353cb7eda77efe518e481707e0515025f0cd5"}, + {file = "regex-2021.4.4-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:3a9cd17e6e5c7eb328517969e0cb0c3d31fd329298dd0c04af99ebf42e904f82"}, + {file = "regex-2021.4.4-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:90f11ff637fe8798933fb29f5ae1148c978cccb0452005bf4c69e13db951e765"}, + {file = "regex-2021.4.4-cp37-cp37m-manylinux2014_i686.whl", hash = "sha256:919859aa909429fb5aa9cf8807f6045592c85ef56fdd30a9a3747e513db2536e"}, + {file = "regex-2021.4.4-cp37-cp37m-manylinux2014_x86_64.whl", hash = "sha256:339456e7d8c06dd36a22e451d58ef72cef293112b559010db3d054d5560ef439"}, + {file = "regex-2021.4.4-cp37-cp37m-win32.whl", hash = "sha256:67bdb9702427ceddc6ef3dc382455e90f785af4c13d495f9626861763ee13f9d"}, + {file = "regex-2021.4.4-cp37-cp37m-win_amd64.whl", hash = "sha256:32e65442138b7b76dd8173ffa2cf67356b7bc1768851dded39a7a13bf9223da3"}, + {file = "regex-2021.4.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1e1c20e29358165242928c2de1482fb2cf4ea54a6a6dea2bd7a0e0d8ee321500"}, + {file = "regex-2021.4.4-cp38-cp38-manylinux1_i686.whl", hash = "sha256:314d66636c494ed9c148a42731b3834496cc9a2c4251b1661e40936814542b14"}, + {file = "regex-2021.4.4-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:6d1b01031dedf2503631d0903cb563743f397ccaf6607a5e3b19a3d76fc10480"}, + {file = "regex-2021.4.4-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:741a9647fcf2e45f3a1cf0e24f5e17febf3efe8d4ba1281dcc3aa0459ef424dc"}, + {file = "regex-2021.4.4-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:4c46e22a0933dd783467cf32b3516299fb98cfebd895817d685130cc50cd1093"}, + {file = "regex-2021.4.4-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:e512d8ef5ad7b898cdb2d8ee1cb09a8339e4f8be706d27eaa180c2f177248a10"}, + {file = "regex-2021.4.4-cp38-cp38-manylinux2014_i686.whl", hash = "sha256:980d7be47c84979d9136328d882f67ec5e50008681d94ecc8afa8a65ed1f4a6f"}, + {file = "regex-2021.4.4-cp38-cp38-manylinux2014_x86_64.whl", hash = "sha256:ce15b6d103daff8e9fee13cf7f0add05245a05d866e73926c358e871221eae87"}, + {file = "regex-2021.4.4-cp38-cp38-win32.whl", hash = "sha256:a91aa8619b23b79bcbeb37abe286f2f408d2f2d6f29a17237afda55bb54e7aac"}, + {file = "regex-2021.4.4-cp38-cp38-win_amd64.whl", hash = "sha256:c0502c0fadef0d23b128605d69b58edb2c681c25d44574fc673b0e52dce71ee2"}, + {file = "regex-2021.4.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:598585c9f0af8374c28edd609eb291b5726d7cbce16be6a8b95aa074d252ee17"}, + {file = "regex-2021.4.4-cp39-cp39-manylinux1_i686.whl", hash = "sha256:ee54ff27bf0afaf4c3b3a62bcd016c12c3fdb4ec4f413391a90bd38bc3624605"}, + {file = "regex-2021.4.4-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:7d9884d86dd4dd489e981d94a65cd30d6f07203d90e98f6f657f05170f6324c9"}, + {file = "regex-2021.4.4-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:bf5824bfac591ddb2c1f0a5f4ab72da28994548c708d2191e3b87dd207eb3ad7"}, + {file = "regex-2021.4.4-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:563085e55b0d4fb8f746f6a335893bda5c2cef43b2f0258fe1020ab1dd874df8"}, + {file = "regex-2021.4.4-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:b9c3db21af35e3b3c05764461b262d6f05bbca08a71a7849fd79d47ba7bc33ed"}, + {file = "regex-2021.4.4-cp39-cp39-manylinux2014_i686.whl", hash = "sha256:3916d08be28a1149fb97f7728fca1f7c15d309a9f9682d89d79db75d5e52091c"}, + {file = "regex-2021.4.4-cp39-cp39-manylinux2014_x86_64.whl", hash = "sha256:fd45ff9293d9274c5008a2054ecef86a9bfe819a67c7be1afb65e69b405b3042"}, + {file = "regex-2021.4.4-cp39-cp39-win32.whl", hash = "sha256:fa4537fb4a98fe8fde99626e4681cc644bdcf2a795038533f9f711513a862ae6"}, + {file = "regex-2021.4.4-cp39-cp39-win_amd64.whl", hash = "sha256:97f29f57d5b84e73fbaf99ab3e26134e6687348e95ef6b48cfd2c06807005a07"}, + {file = "regex-2021.4.4.tar.gz", hash = "sha256:52ba3d3f9b942c49d7e4bc105bb28551c44065f139a65062ab7912bef10c9afb"}, +] toml = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, diff --git a/pyproject.toml b/pyproject.toml index c17a1d4..f979934 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,12 +13,13 @@ packages = [ ] [tool.poetry.dependencies] -python = "^3.6" +python = "^3.6.2" pylzma = "^0.5.0" [tool.poetry.dev-dependencies] mypy = "^0.812" pytest = "^6.2.4" +black = "^21.5b2" [tool.poetry.scripts] napi-py = 'napi.main:cli_main' From 9ae8ddc213219bc6149b10ce0a64ff3508527227 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 31 May 2021 23:05:06 +0200 Subject: [PATCH 67/77] bump patch revision to publish the pacakge on pypi --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f979934..eeecc77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "napi-py" -version = "0.1.5" +version = "0.1.6" description = "CLI tool for downloading subtitles from napiprojekt.pl" authors = ["emkor93 "] license = "GPL-3.0 License" From e2d959e9bdc18850fb09413ffff0ed75a61667c3 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 31 May 2021 23:12:58 +0200 Subject: [PATCH 68/77] switch back to publishing with twine --- .github/workflows/main.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dd3ff58..7139273 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,12 +39,10 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Install poetry - run: pip install poetry + run: pip install poetry twine - name: Install from source run: make install - - name: Build distributable package + - name: Build the package run: make build - - name: List files - run: find . -type f | grep -v .venv | sort - name: Publish package to pypi - run: poetry publish --username ${{ secrets.PYPI_USER }} --password ${{ secrets.PYPI_PASSWORD }} + run: twine upload -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* From b1691faccea35b9301cb08ed06518ab0798f3853 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 31 May 2021 23:15:11 +0200 Subject: [PATCH 69/77] increase logging in twine publish step --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7139273..c8a1926 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,4 +45,4 @@ jobs: - name: Build the package run: make build - name: Publish package to pypi - run: twine upload -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* + run: twine upload --verbose -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* From 2a2534198e491e3a3c8d620c4954cf0e2deb79a4 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 31 May 2021 23:19:06 +0200 Subject: [PATCH 70/77] add --skip-existing flag for twine to force uploading new release to pypi --- .github/workflows/main.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c8a1926..aa1af2a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,4 +45,4 @@ jobs: - name: Build the package run: make build - name: Publish package to pypi - run: twine upload --verbose -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* + run: twine upload --skip-existing --verbose -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* diff --git a/pyproject.toml b/pyproject.toml index eeecc77..c79f90f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "napi-py" -version = "0.1.6" +version = "0.1.7" description = "CLI tool for downloading subtitles from napiprojekt.pl" authors = ["emkor93 "] license = "GPL-3.0 License" From f652eac5187119ba577cc2f50508fa39759604d2 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Mon, 31 May 2021 23:28:04 +0200 Subject: [PATCH 71/77] publish new version with minor updated --- .github/workflows/main.yml | 6 ++---- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aa1af2a..0b0d524 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,10 +39,8 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Install poetry - run: pip install poetry twine + run: pip install poetry - name: Install from source run: make install - - name: Build the package - run: make build - name: Publish package to pypi - run: twine upload --skip-existing --verbose -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} dist/* + run: poetry publish --build -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} diff --git a/pyproject.toml b/pyproject.toml index c79f90f..572fd71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "napi-py" -version = "0.1.7" +version = "0.2.1" description = "CLI tool for downloading subtitles from napiprojekt.pl" authors = ["emkor93 "] license = "GPL-3.0 License" From 86a1aa03301cf7976998aeba9dc6512564c09018 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sun, 13 Jun 2021 20:35:34 +0200 Subject: [PATCH 72/77] re-format using black, bump dependencies, publish using tokens --- napi/encoding.py | 16 +++------------- napi/main.py | 26 ++++++-------------------- poetry.lock | 12 ++++++------ pyproject.toml | 6 +++++- 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/napi/encoding.py b/napi/encoding.py index 2c3dc95..0ae8dcb 100644 --- a/napi/encoding.py +++ b/napi/encoding.py @@ -29,13 +29,7 @@ def _diacritics_count_in_word(word: str) -> int: def _err_symbol_count_in_word(word: str) -> int: - return len( - [ - err_sym - for err_sym in SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 - if err_sym.lower() in word.lower() - ] - ) + return len([err_sym for err_sym in SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 if err_sym.lower() in word.lower()]) def _is_correct_encoding(subs: str) -> bool: @@ -55,14 +49,10 @@ def _try_decode(subs: bytes) -> Tuple[str, str]: return enc, encoded_subs except UnicodeDecodeError as e: last_exc = e - raise ValueError( - "Could not encode using any of {}: {}".format(DECODING_ORDER, last_exc) - ) + raise ValueError("Could not encode using any of {}: {}".format(DECODING_ORDER, last_exc)) -def decode_subs( - subtitles_binary: bytes, use_enc: Optional[str] = None -) -> Tuple[str, str]: +def decode_subs(subtitles_binary: bytes, use_enc: Optional[str] = None) -> Tuple[str, str]: if use_enc is not None: return use_enc, subtitles_binary.decode(use_enc) else: diff --git a/napi/main.py b/napi/main.py index af6c740..de268be 100755 --- a/napi/main.py +++ b/napi/main.py @@ -16,9 +16,7 @@ def setup_logger(level: int = logging.INFO) -> None: - logging.basicConfig( - format="%(asctime)s UTC | %(levelname)s | %(message)s", level=level - ) + logging.basicConfig(format="%(asctime)s UTC | %(levelname)s | %(message)s", level=level) logging.Formatter.converter = time.gmtime @@ -27,9 +25,7 @@ class NoMatchingSubtitle(Exception): def _parse_args() -> argparse.Namespace: - parser = argparse.ArgumentParser( - prog="napi-py", description="CLI for downloading subtitles from napiprojekt.pl" - ) + parser = argparse.ArgumentParser(prog="napi-py", description="CLI for downloading subtitles from napiprojekt.pl") parser.add_argument("movie_path", type=str, help="Path to movie file") parser.add_argument( "--target", @@ -63,32 +59,22 @@ def main( ) -> None: log = logging.getLogger() movie_path = path.abspath(movie_path) - subtitles_path = path.abspath( - subtitles_path or get_target_path_for_subtitle(movie_path) - ) + subtitles_path = path.abspath(subtitles_path or get_target_path_for_subtitle(movie_path)) if path.exists(movie_path): if use_hash and use_hash.startswith("napiprojekt:"): use_hash = use_hash.partition("napiprojekt:")[-1] try: napi_client = NapiPy() movie_hash = use_hash or napi_client.calc_hash(movie_path) - log.info( - "Downloading subs for {} (hash: {})".format( - path.basename(movie_path), movie_hash - ) - ) - src_enc, tgt_src, tmp_file = napi_client.download_subs( - movie_hash, use_enc=from_enc - ) + log.info("Downloading subs for {} (hash: {})".format(path.basename(movie_path), movie_hash)) + src_enc, tgt_src, tmp_file = napi_client.download_subs(movie_hash, use_enc=from_enc) if src_enc is not None and tmp_file is not None: subs_path = ( napi_client.move_subs(tmp_file, subtitles_path) if subtitles_path else napi_client.move_subs_to_movie(tmp_file, movie_path) ) - log.info( - "Saved subs ({} -> {}) in {}".format(src_enc, tgt_src, subs_path) - ) + log.info("Saved subs ({} -> {}) in {}".format(src_enc, tgt_src, subs_path)) else: log.error("Napiprojekt.pl does not have subtitles for this movie") exit(EXIT_SUBS_NOT_FOUND) diff --git a/poetry.lock b/poetry.lock index 843e151..453f1ea 100644 --- a/poetry.lock +++ b/poetry.lock @@ -30,7 +30,7 @@ tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (> [[package]] name = "black" -version = "21.5b2" +version = "21.6b0" description = "The uncompromising code formatter." category = "dev" optional = false @@ -83,7 +83,7 @@ python-versions = ">=3.6, <3.7" [[package]] name = "importlib-metadata" -version = "4.4.0" +version = "4.5.0" description = "Read metadata from Python packages" category = "dev" optional = false @@ -271,8 +271,8 @@ attrs = [ {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"}, ] black = [ - {file = "black-21.5b2-py3-none-any.whl", hash = "sha256:e5cf21ebdffc7a9b29d73912b6a6a9a4df4ce70220d523c21647da2eae0751ef"}, - {file = "black-21.5b2.tar.gz", hash = "sha256:1fc0e0a2c8ae7d269dfcf0c60a89afa299664f3e811395d40b1922dff8f854b5"}, + {file = "black-21.6b0-py3-none-any.whl", hash = "sha256:dfb8c5a069012b2ab1e972e7b908f5fb42b6bbabcba0a788b86dc05067c7d9c7"}, + {file = "black-21.6b0.tar.gz", hash = "sha256:dc132348a88d103016726fe360cb9ede02cecf99b76e3660ce6c596be132ce04"}, ] click = [ {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"}, @@ -287,8 +287,8 @@ dataclasses = [ {file = "dataclasses-0.8.tar.gz", hash = "sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97"}, ] importlib-metadata = [ - {file = "importlib_metadata-4.4.0-py3-none-any.whl", hash = "sha256:960d52ba7c21377c990412aca380bf3642d734c2eaab78a2c39319f67c6a5786"}, - {file = "importlib_metadata-4.4.0.tar.gz", hash = "sha256:e592faad8de1bda9fe920cf41e15261e7131bcf266c30306eec00e8e225c1dd5"}, + {file = "importlib_metadata-4.5.0-py3-none-any.whl", hash = "sha256:833b26fb89d5de469b24a390e9df088d4e52e4ba33b01dc5e0e4f41b81a16c00"}, + {file = "importlib_metadata-4.5.0.tar.gz", hash = "sha256:b142cc1dd1342f31ff04bb7d022492b09920cb64fed867cd3ea6f80fe3ebd139"}, ] iniconfig = [ {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, diff --git a/pyproject.toml b/pyproject.toml index 572fd71..dd39ef8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "napi-py" -version = "0.2.1" +version = "0.2.2" description = "CLI tool for downloading subtitles from napiprojekt.pl" authors = ["emkor93 "] license = "GPL-3.0 License" @@ -27,3 +27,7 @@ napi-py = 'napi.main:cli_main' [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" + +[tool.black] +line-length = 120 +target-version = ['py36', 'py37', 'py38', 'py39'] \ No newline at end of file From 3632fea4b1c52f0f7189863769a505589cc87e76 Mon Sep 17 00:00:00 2001 From: Adam Steciuk Date: Sat, 15 Jun 2024 21:43:48 +0200 Subject: [PATCH 73/77] Fix encoding issues for utf-16 (#3) * fix issues with utf-16 encoded subs * add auto encoding detection using chardet * add chardet as dependency and bump python to 3.7 * bump napi-py to 0.2.3 * add utf-16 test --- .gitignore | 3 +- napi/encoding.py | 67 +++--- poetry.lock | 320 ++++++++++++------------- pyproject.toml | 11 +- test/acceptance/test_acceptance_lib.py | 16 +- 5 files changed, 203 insertions(+), 214 deletions(-) diff --git a/.gitignore b/.gitignore index 76122ec..05857c0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ .pytest_cache/ *.egg-info/ build/ -dist/ \ No newline at end of file +dist/ +__pycache__/ \ No newline at end of file diff --git a/napi/encoding.py b/napi/encoding.py index 0ae8dcb..70a099d 100644 --- a/napi/encoding.py +++ b/napi/encoding.py @@ -1,46 +1,45 @@ import locale -from typing import Tuple, Optional - -DECODING_ORDER = [ - "windows-1250", - "windows-1251", - "windows-1252", - "windows-1253", - "windows-1254", - "utf-8", -] -SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 = [ - "Ĺş", - "ĹĽ", - "Ĺ‚", - "Ĺ›", - "ć", - "Ä…", - "Ä™", - "Ăł", - "Ĺ„", -] -POLISH_DIACRITICS = ["ź", "ż", "ł", "ś", "ć", "ą", "ę", "ó", "ń"] -CHECK_IN_WORD_COUNT = 1000 - - -def _diacritics_count_in_word(word: str) -> int: - return len([pd for pd in POLISH_DIACRITICS if pd.lower() in word.lower()]) - - -def _err_symbol_count_in_word(word: str) -> int: - return len([err_sym for err_sym in SYMBOLS_WHEN_ENCODING_UTF8_AS_WIN1250 if err_sym.lower() in word.lower()]) +from typing import Optional, Tuple + +import chardet + +DECODING_ORDER = ["utf-16", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "utf-8"] +CHECK_NUM_CHARS = 5000 +AUTO_DETECT_THRESHOLD = 0.9 + + +def _is_ascii(c: str) -> bool: + return ord(c) < 128 + + +def _is_polish_diacritic(c: str) -> bool: + return c in "ąćęłńóśżźĄĆĘŁŃÓŚŻŹ" def _is_correct_encoding(subs: str) -> bool: err_symbols, diacritics = 0, 0 - for word in subs.split()[:CHECK_IN_WORD_COUNT]: - diacritics += _diacritics_count_in_word(word) - err_symbols += _err_symbol_count_in_word(word) + for char in subs[:CHECK_NUM_CHARS]: + if _is_polish_diacritic(char): + diacritics += 1 + elif not _is_ascii(char): + err_symbols += 1 + return err_symbols < diacritics +def _detect_encoding(subs: bytes) -> Tuple[Optional[str], float]: + result = chardet.detect(subs) + return result["encoding"], result["confidence"] + + def _try_decode(subs: bytes) -> Tuple[str, str]: + encoding, confidence = _detect_encoding(subs) + if encoding and confidence > AUTO_DETECT_THRESHOLD: + try: + return encoding, subs.decode(encoding) + except UnicodeDecodeError: + pass + last_exc = None for i, enc in enumerate(DECODING_ORDER): try: diff --git a/poetry.lock b/poetry.lock index 453f1ea..0c394dd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,45 +1,58 @@ +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. + [[package]] name = "appdirs" version = "1.4.4" description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -category = "dev" optional = false python-versions = "*" +files = [ + {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, + {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, +] [[package]] name = "atomicwrites" version = "1.4.0" description = "Atomic file writes." -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, + {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, +] [[package]] name = "attrs" version = "21.2.0" description = "Classes Without Boilerplate" -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +files = [ + {file = "attrs-21.2.0-py2.py3-none-any.whl", hash = "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1"}, + {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"}, +] [package.extras] -dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit"] -docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] -tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface"] -tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins"] +dev = ["coverage[toml] (>=5.0.2)", "furo", "hypothesis", "mypy", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six", "sphinx", "sphinx-notfound-page", "zope.interface"] +docs = ["furo", "sphinx", "sphinx-notfound-page", "zope.interface"] +tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "mypy", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six", "zope.interface"] +tests-no-zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "mypy", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six"] [[package]] name = "black" version = "21.6b0" description = "The uncompromising code formatter." -category = "dev" optional = false python-versions = ">=3.6.2" +files = [ + {file = "black-21.6b0-py3-none-any.whl", hash = "sha256:dfb8c5a069012b2ab1e972e7b908f5fb42b6bbabcba0a788b86dc05067c7d9c7"}, + {file = "black-21.6b0.tar.gz", hash = "sha256:dc132348a88d103016726fe360cb9ede02cecf99b76e3660ce6c596be132ce04"}, +] [package.dependencies] appdirs = "*" click = ">=7.1.2" -dataclasses = {version = ">=0.6", markers = "python_version < \"3.7\""} mypy-extensions = ">=0.4.3" pathspec = ">=0.8.1,<1" regex = ">=2020.1.8" @@ -53,13 +66,27 @@ d = ["aiohttp (>=3.6.0)", "aiohttp-cors (>=0.4.0)"] python2 = ["typed-ast (>=1.4.2)"] uvloop = ["uvloop (>=0.15.2)"] +[[package]] +name = "chardet" +version = "5.2.0" +description = "Universal encoding detector for Python 3" +optional = false +python-versions = ">=3.7" +files = [ + {file = "chardet-5.2.0-py3-none-any.whl", hash = "sha256:e1cf59446890a00105fe7b7912492ea04b6e6f06d4b742b2c788469e34c82970"}, + {file = "chardet-5.2.0.tar.gz", hash = "sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7"}, +] + [[package]] name = "click" version = "8.0.1" description = "Composable command line interface toolkit" -category = "dev" optional = false python-versions = ">=3.6" +files = [ + {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"}, + {file = "click-8.0.1.tar.gz", hash = "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"}, +] [package.dependencies] colorama = {version = "*", markers = "platform_system == \"Windows\""} @@ -69,49 +96,73 @@ importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} name = "colorama" version = "0.4.4" description = "Cross-platform colored terminal text." -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" - -[[package]] -name = "dataclasses" -version = "0.8" -description = "A backport of the dataclasses module for Python 3.6" -category = "dev" -optional = false -python-versions = ">=3.6, <3.7" +files = [ + {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, + {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, +] [[package]] name = "importlib-metadata" version = "4.5.0" description = "Read metadata from Python packages" -category = "dev" optional = false python-versions = ">=3.6" +files = [ + {file = "importlib_metadata-4.5.0-py3-none-any.whl", hash = "sha256:833b26fb89d5de469b24a390e9df088d4e52e4ba33b01dc5e0e4f41b81a16c00"}, + {file = "importlib_metadata-4.5.0.tar.gz", hash = "sha256:b142cc1dd1342f31ff04bb7d022492b09920cb64fed867cd3ea6f80fe3ebd139"}, +] [package.dependencies] typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} zipp = ">=0.5" [package.extras] -docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] -testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] +docs = ["jaraco.packaging (>=8.2)", "rst.linker (>=1.9)", "sphinx"] +testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pep517", "pyfakefs", "pytest (>=4.6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.0.1)", "pytest-flake8", "pytest-mypy"] [[package]] name = "iniconfig" version = "1.1.1" description = "iniconfig: brain-dead simple config-ini parsing" -category = "dev" optional = false python-versions = "*" +files = [ + {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, + {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, +] [[package]] name = "mypy" version = "0.812" description = "Optional static typing for Python" -category = "dev" optional = false python-versions = ">=3.5" +files = [ + {file = "mypy-0.812-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:a26f8ec704e5a7423c8824d425086705e381b4f1dfdef6e3a1edab7ba174ec49"}, + {file = "mypy-0.812-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:28fb5479c494b1bab244620685e2eb3c3f988d71fd5d64cc753195e8ed53df7c"}, + {file = "mypy-0.812-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:9743c91088d396c1a5a3c9978354b61b0382b4e3c440ce83cf77994a43e8c521"}, + {file = "mypy-0.812-cp35-cp35m-win_amd64.whl", hash = "sha256:d7da2e1d5f558c37d6e8c1246f1aec1e7349e4913d8fb3cb289a35de573fe2eb"}, + {file = "mypy-0.812-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:4eec37370483331d13514c3f55f446fc5248d6373e7029a29ecb7b7494851e7a"}, + {file = "mypy-0.812-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:d65cc1df038ef55a99e617431f0553cd77763869eebdf9042403e16089fe746c"}, + {file = "mypy-0.812-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:61a3d5b97955422964be6b3baf05ff2ce7f26f52c85dd88db11d5e03e146a3a6"}, + {file = "mypy-0.812-cp36-cp36m-win_amd64.whl", hash = "sha256:25adde9b862f8f9aac9d2d11971f226bd4c8fbaa89fb76bdadb267ef22d10064"}, + {file = "mypy-0.812-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:552a815579aa1e995f39fd05dde6cd378e191b063f031f2acfe73ce9fb7f9e56"}, + {file = "mypy-0.812-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:499c798053cdebcaa916eef8cd733e5584b5909f789de856b482cd7d069bdad8"}, + {file = "mypy-0.812-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:5873888fff1c7cf5b71efbe80e0e73153fe9212fafdf8e44adfe4c20ec9f82d7"}, + {file = "mypy-0.812-cp37-cp37m-win_amd64.whl", hash = "sha256:9f94aac67a2045ec719ffe6111df543bac7874cee01f41928f6969756e030564"}, + {file = "mypy-0.812-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d23e0ea196702d918b60c8288561e722bf437d82cb7ef2edcd98cfa38905d506"}, + {file = "mypy-0.812-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:674e822aa665b9fd75130c6c5f5ed9564a38c6cea6a6432ce47eafb68ee578c5"}, + {file = "mypy-0.812-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:abf7e0c3cf117c44d9285cc6128856106183938c68fd4944763003decdcfeb66"}, + {file = "mypy-0.812-cp38-cp38-win_amd64.whl", hash = "sha256:0d0a87c0e7e3a9becdfbe936c981d32e5ee0ccda3e0f07e1ef2c3d1a817cf73e"}, + {file = "mypy-0.812-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7ce3175801d0ae5fdfa79b4f0cfed08807af4d075b402b7e294e6aa72af9aa2a"}, + {file = "mypy-0.812-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:b09669bcda124e83708f34a94606e01b614fa71931d356c1f1a5297ba11f110a"}, + {file = "mypy-0.812-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:33f159443db0829d16f0a8d83d94df3109bb6dd801975fe86bacb9bf71628e97"}, + {file = "mypy-0.812-cp39-cp39-win_amd64.whl", hash = "sha256:3f2aca7f68580dc2508289c729bd49ee929a436208d2b2b6aab15745a70a57df"}, + {file = "mypy-0.812-py3-none-any.whl", hash = "sha256:2f9b3407c58347a452fc0736861593e105139b905cca7d097e413453a1d650b4"}, + {file = "mypy-0.812.tar.gz", hash = "sha256:cd07039aa5df222037005b08fbbfd69b3ab0b0bd7a07d7906de75ae52c4e3119"}, +] [package.dependencies] mypy-extensions = ">=0.4.3,<0.5.0" @@ -125,17 +176,23 @@ dmypy = ["psutil (>=4.0)"] name = "mypy-extensions" version = "0.4.3" description = "Experimental type system extensions for programs checked with the mypy typechecker." -category = "dev" optional = false python-versions = "*" +files = [ + {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, + {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, +] [[package]] name = "packaging" version = "20.9" description = "Core utilities for Python packages" -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "packaging-20.9-py2.py3-none-any.whl", hash = "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"}, + {file = "packaging-20.9.tar.gz", hash = "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"}, +] [package.dependencies] pyparsing = ">=2.0.2" @@ -144,17 +201,23 @@ pyparsing = ">=2.0.2" name = "pathspec" version = "0.8.1" description = "Utility library for gitignore style pattern matching of file paths." -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +files = [ + {file = "pathspec-0.8.1-py2.py3-none-any.whl", hash = "sha256:aa0cb481c4041bf52ffa7b0d8fa6cd3e88a2ca4879c533c9153882ee2556790d"}, + {file = "pathspec-0.8.1.tar.gz", hash = "sha256:86379d6b86d75816baba717e64b1a3a3469deb93bb76d613c9ce79edc5cb68fd"}, +] [[package]] name = "pluggy" version = "0.13.1" description = "plugin and hook calling mechanisms for python" -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, + {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, +] [package.dependencies] importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} @@ -166,33 +229,44 @@ dev = ["pre-commit", "tox"] name = "py" version = "1.10.0" description = "library with cross-python path, ini-parsing, io, code, log facilities" -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "py-1.10.0-py2.py3-none-any.whl", hash = "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"}, + {file = "py-1.10.0.tar.gz", hash = "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3"}, +] [[package]] name = "pylzma" version = "0.5.0" description = "Python bindings for the LZMA library by Igor Pavlov." -category = "main" optional = false python-versions = "*" +files = [ + {file = "pylzma-0.5.0.tar.gz", hash = "sha256:b874172afbf37770e643bf2dc9d9b6b03eb95d8f8162e157145b3fe9e1b68a1c"}, +] [[package]] name = "pyparsing" version = "2.4.7" description = "Python parsing module" -category = "dev" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, + {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, +] [[package]] name = "pytest" version = "6.2.4" description = "pytest: simple powerful testing with Python" -category = "dev" optional = false python-versions = ">=3.6" +files = [ + {file = "pytest-6.2.4-py3-none-any.whl", hash = "sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890"}, + {file = "pytest-6.2.4.tar.gz", hash = "sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b"}, +] [package.dependencies] atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} @@ -212,144 +286,9 @@ testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xm name = "regex" version = "2021.4.4" description = "Alternative regular expression module, to replace re." -category = "dev" optional = false python-versions = "*" - -[[package]] -name = "toml" -version = "0.10.2" -description = "Python Library for Tom's Obvious, Minimal Language" -category = "dev" -optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" - -[[package]] -name = "typed-ast" -version = "1.4.3" -description = "a fork of Python 2 and 3 ast modules with type comment support" -category = "dev" -optional = false -python-versions = "*" - -[[package]] -name = "typing-extensions" -version = "3.10.0.0" -description = "Backported and Experimental Type Hints for Python 3.5+" -category = "dev" -optional = false -python-versions = "*" - -[[package]] -name = "zipp" -version = "3.4.1" -description = "Backport of pathlib-compatible object wrapper for zip files" -category = "dev" -optional = false -python-versions = ">=3.6" - -[package.extras] -docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] -testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "pytest-enabler", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"] - -[metadata] -lock-version = "1.1" -python-versions = "^3.6.2" -content-hash = "cee1ee354530fd9f6ff760e52d0768b674d54d65a766a53711e21b0bd26404bf" - -[metadata.files] -appdirs = [ - {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, - {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, -] -atomicwrites = [ - {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, - {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, -] -attrs = [ - {file = "attrs-21.2.0-py2.py3-none-any.whl", hash = "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1"}, - {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"}, -] -black = [ - {file = "black-21.6b0-py3-none-any.whl", hash = "sha256:dfb8c5a069012b2ab1e972e7b908f5fb42b6bbabcba0a788b86dc05067c7d9c7"}, - {file = "black-21.6b0.tar.gz", hash = "sha256:dc132348a88d103016726fe360cb9ede02cecf99b76e3660ce6c596be132ce04"}, -] -click = [ - {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"}, - {file = "click-8.0.1.tar.gz", hash = "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"}, -] -colorama = [ - {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, - {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, -] -dataclasses = [ - {file = "dataclasses-0.8-py3-none-any.whl", hash = "sha256:0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf"}, - {file = "dataclasses-0.8.tar.gz", hash = "sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97"}, -] -importlib-metadata = [ - {file = "importlib_metadata-4.5.0-py3-none-any.whl", hash = "sha256:833b26fb89d5de469b24a390e9df088d4e52e4ba33b01dc5e0e4f41b81a16c00"}, - {file = "importlib_metadata-4.5.0.tar.gz", hash = "sha256:b142cc1dd1342f31ff04bb7d022492b09920cb64fed867cd3ea6f80fe3ebd139"}, -] -iniconfig = [ - {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, - {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, -] -mypy = [ - {file = "mypy-0.812-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:a26f8ec704e5a7423c8824d425086705e381b4f1dfdef6e3a1edab7ba174ec49"}, - {file = "mypy-0.812-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:28fb5479c494b1bab244620685e2eb3c3f988d71fd5d64cc753195e8ed53df7c"}, - {file = "mypy-0.812-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:9743c91088d396c1a5a3c9978354b61b0382b4e3c440ce83cf77994a43e8c521"}, - {file = "mypy-0.812-cp35-cp35m-win_amd64.whl", hash = "sha256:d7da2e1d5f558c37d6e8c1246f1aec1e7349e4913d8fb3cb289a35de573fe2eb"}, - {file = "mypy-0.812-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:4eec37370483331d13514c3f55f446fc5248d6373e7029a29ecb7b7494851e7a"}, - {file = "mypy-0.812-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:d65cc1df038ef55a99e617431f0553cd77763869eebdf9042403e16089fe746c"}, - {file = "mypy-0.812-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:61a3d5b97955422964be6b3baf05ff2ce7f26f52c85dd88db11d5e03e146a3a6"}, - {file = "mypy-0.812-cp36-cp36m-win_amd64.whl", hash = "sha256:25adde9b862f8f9aac9d2d11971f226bd4c8fbaa89fb76bdadb267ef22d10064"}, - {file = "mypy-0.812-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:552a815579aa1e995f39fd05dde6cd378e191b063f031f2acfe73ce9fb7f9e56"}, - {file = "mypy-0.812-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:499c798053cdebcaa916eef8cd733e5584b5909f789de856b482cd7d069bdad8"}, - {file = "mypy-0.812-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:5873888fff1c7cf5b71efbe80e0e73153fe9212fafdf8e44adfe4c20ec9f82d7"}, - {file = "mypy-0.812-cp37-cp37m-win_amd64.whl", hash = "sha256:9f94aac67a2045ec719ffe6111df543bac7874cee01f41928f6969756e030564"}, - {file = "mypy-0.812-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d23e0ea196702d918b60c8288561e722bf437d82cb7ef2edcd98cfa38905d506"}, - {file = "mypy-0.812-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:674e822aa665b9fd75130c6c5f5ed9564a38c6cea6a6432ce47eafb68ee578c5"}, - {file = "mypy-0.812-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:abf7e0c3cf117c44d9285cc6128856106183938c68fd4944763003decdcfeb66"}, - {file = "mypy-0.812-cp38-cp38-win_amd64.whl", hash = "sha256:0d0a87c0e7e3a9becdfbe936c981d32e5ee0ccda3e0f07e1ef2c3d1a817cf73e"}, - {file = "mypy-0.812-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7ce3175801d0ae5fdfa79b4f0cfed08807af4d075b402b7e294e6aa72af9aa2a"}, - {file = "mypy-0.812-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:b09669bcda124e83708f34a94606e01b614fa71931d356c1f1a5297ba11f110a"}, - {file = "mypy-0.812-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:33f159443db0829d16f0a8d83d94df3109bb6dd801975fe86bacb9bf71628e97"}, - {file = "mypy-0.812-cp39-cp39-win_amd64.whl", hash = "sha256:3f2aca7f68580dc2508289c729bd49ee929a436208d2b2b6aab15745a70a57df"}, - {file = "mypy-0.812-py3-none-any.whl", hash = "sha256:2f9b3407c58347a452fc0736861593e105139b905cca7d097e413453a1d650b4"}, - {file = "mypy-0.812.tar.gz", hash = "sha256:cd07039aa5df222037005b08fbbfd69b3ab0b0bd7a07d7906de75ae52c4e3119"}, -] -mypy-extensions = [ - {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, - {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, -] -packaging = [ - {file = "packaging-20.9-py2.py3-none-any.whl", hash = "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"}, - {file = "packaging-20.9.tar.gz", hash = "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"}, -] -pathspec = [ - {file = "pathspec-0.8.1-py2.py3-none-any.whl", hash = "sha256:aa0cb481c4041bf52ffa7b0d8fa6cd3e88a2ca4879c533c9153882ee2556790d"}, - {file = "pathspec-0.8.1.tar.gz", hash = "sha256:86379d6b86d75816baba717e64b1a3a3469deb93bb76d613c9ce79edc5cb68fd"}, -] -pluggy = [ - {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, - {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, -] -py = [ - {file = "py-1.10.0-py2.py3-none-any.whl", hash = "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"}, - {file = "py-1.10.0.tar.gz", hash = "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3"}, -] -pylzma = [ - {file = "pylzma-0.5.0.tar.gz", hash = "sha256:b874172afbf37770e643bf2dc9d9b6b03eb95d8f8162e157145b3fe9e1b68a1c"}, -] -pyparsing = [ - {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, - {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, -] -pytest = [ - {file = "pytest-6.2.4-py3-none-any.whl", hash = "sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890"}, - {file = "pytest-6.2.4.tar.gz", hash = "sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b"}, -] -regex = [ +files = [ {file = "regex-2021.4.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:619d71c59a78b84d7f18891fe914446d07edd48dc8328c8e149cbe0929b4e000"}, {file = "regex-2021.4.4-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:47bf5bf60cf04d72bf6055ae5927a0bd9016096bf3d742fa50d9bf9f45aa0711"}, {file = "regex-2021.4.4-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:281d2fd05555079448537fe108d79eb031b403dac622621c78944c235f3fcf11"}, @@ -392,11 +331,25 @@ regex = [ {file = "regex-2021.4.4-cp39-cp39-win_amd64.whl", hash = "sha256:97f29f57d5b84e73fbaf99ab3e26134e6687348e95ef6b48cfd2c06807005a07"}, {file = "regex-2021.4.4.tar.gz", hash = "sha256:52ba3d3f9b942c49d7e4bc105bb28551c44065f139a65062ab7912bef10c9afb"}, ] -toml = [ + +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, ] -typed-ast = [ + +[[package]] +name = "typed-ast" +version = "1.4.3" +description = "a fork of Python 2 and 3 ast modules with type comment support" +optional = false +python-versions = "*" +files = [ {file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:2068531575a125b87a41802130fa7e29f26c09a2833fea68d9a40cf33902eba6"}, {file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:c907f561b1e83e93fad565bac5ba9c22d96a54e7ea0267c708bffe863cbe4075"}, {file = "typed_ast-1.4.3-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:1b3ead4a96c9101bef08f9f7d1217c096f31667617b58de957f690c92378b528"}, @@ -428,12 +381,35 @@ typed-ast = [ {file = "typed_ast-1.4.3-cp39-cp39-win_amd64.whl", hash = "sha256:9c6d1a54552b5330bc657b7ef0eae25d00ba7ffe85d9ea8ae6540d2197a3788c"}, {file = "typed_ast-1.4.3.tar.gz", hash = "sha256:fb1bbeac803adea29cedd70781399c99138358c26d05fcbd23c13016b7f5ec65"}, ] -typing-extensions = [ + +[[package]] +name = "typing-extensions" +version = "3.10.0.0" +description = "Backported and Experimental Type Hints for Python 3.5+" +optional = false +python-versions = "*" +files = [ {file = "typing_extensions-3.10.0.0-py2-none-any.whl", hash = "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497"}, {file = "typing_extensions-3.10.0.0-py3-none-any.whl", hash = "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84"}, {file = "typing_extensions-3.10.0.0.tar.gz", hash = "sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342"}, ] -zipp = [ + +[[package]] +name = "zipp" +version = "3.4.1" +description = "Backport of pathlib-compatible object wrapper for zip files" +optional = false +python-versions = ">=3.6" +files = [ {file = "zipp-3.4.1-py3-none-any.whl", hash = "sha256:51cb66cc54621609dd593d1787f286ee42a5c0adbb4b29abea5a63edc3e03098"}, {file = "zipp-3.4.1.tar.gz", hash = "sha256:3607921face881ba3e026887d8150cca609d517579abe052ac81fc5aeffdbd76"}, ] + +[package.extras] +docs = ["jaraco.packaging (>=8.2)", "rst.linker (>=1.9)", "sphinx"] +testing = ["func-timeout", "jaraco.itertools", "pytest (>=4.6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=1.2.3)", "pytest-cov", "pytest-enabler", "pytest-flake8", "pytest-mypy"] + +[metadata] +lock-version = "2.0" +python-versions = "^3.7" +content-hash = "30561353432b96b1526fd123e422c2d3d2a7455f72e67c826191f52ecbf68179" diff --git a/pyproject.toml b/pyproject.toml index dd39ef8..248a2b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "napi-py" -version = "0.2.2" +version = "0.2.3" description = "CLI tool for downloading subtitles from napiprojekt.pl" authors = ["emkor93 "] license = "GPL-3.0 License" @@ -8,13 +8,12 @@ readme = "README.md" homepage = "https://github.com/emkor/napi-py" repository = "https://github.com/emkor/napi-py" keywords = ["napiprojekt", "subs", "subtitles", "movie", "film"] -packages = [ - { include = "napi" }, -] +packages = [{ include = "napi" }] [tool.poetry.dependencies] -python = "^3.6.2" +python = "^3.7" pylzma = "^0.5.0" +chardet = "^5.2.0" [tool.poetry.dev-dependencies] mypy = "^0.812" @@ -30,4 +29,4 @@ build-backend = "poetry.core.masonry.api" [tool.black] line-length = 120 -target-version = ['py36', 'py37', 'py38', 'py39'] \ No newline at end of file +target-version = ['py36', 'py37', 'py38', 'py39'] diff --git a/test/acceptance/test_acceptance_lib.py b/test/acceptance/test_acceptance_lib.py index 0f0e1c8..1510e9b 100644 --- a/test/acceptance/test_acceptance_lib.py +++ b/test/acceptance/test_acceptance_lib.py @@ -5,7 +5,7 @@ def test_should_download_correctly_encoded_subs(): movie_hash = '25b1087d997bfbf8a4be462255e05a05' napi = NapiPy() src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash) - assert src_enc == "utf-8" + assert src_enc == 'UTF-8-SIG' with open(tmp_file) as subs_file: subs = subs_file.read() @@ -35,3 +35,17 @@ def test_should_download_subs_with_forced_encoding(): expected_phrases = ['ciąży', 'artykułów', 'Właśnie', 'wyjść', 'wciąż'] for expected_phrase in expected_phrases: assert expected_phrase in subs + + +def test_should_download_subs_in_utf_16(): + movie_hash = 'f517eb7e09d270a3b83b14403712ab96' + napi = NapiPy() + src_enc, tgt_enc, tmp_file = napi.download_subs(movie_hash) + assert src_enc == 'UTF-16' + + with open(tmp_file) as subs_file: + subs = subs_file.read() + + expected_phrases = ['Łaskawy', 'powrócili', 'londyńskiej', 'rozbłyśnie', 'wyróżniająca'] + for expected_phrase in expected_phrases: + assert expected_phrase in subs From b9ca62b1b6d7e731cfdcd396db73bc83b0a246b2 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sat, 15 Jun 2024 21:49:42 +0200 Subject: [PATCH 74/77] remove support for python 3.6, add support for 3.10 --- .github/workflows/main.yml | 8 ++++---- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0b0d524..f39bee6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,10 +6,10 @@ jobs: test: name: Test with Python ${{ matrix.python-version }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: matrix: - python-version: [ 3.6, 3.7, 3.8, 3.9 ] + python-version: [ "3.7", "3.8", "3.9", "3.10" ] steps: - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 @@ -30,12 +30,12 @@ jobs: name: Publish the package needs: test if: ${{ github.ref == 'refs/heads/master' }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: "3.10" - name: Checkout code uses: actions/checkout@v2 - name: Install poetry diff --git a/pyproject.toml b/pyproject.toml index 248a2b1..0ff939d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,4 +29,4 @@ build-backend = "poetry.core.masonry.api" [tool.black] line-length = 120 -target-version = ['py36', 'py37', 'py38', 'py39'] +target-version = ['py37', 'py38', 'py39', 'py310'] From 8ccf8788f9088420110308a78b6364592d370c17 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sat, 15 Jun 2024 22:10:54 +0200 Subject: [PATCH 75/77] update dev dependencies --- poetry.lock | 445 ++++++++++++++++++++++--------------------------- pyproject.toml | 6 +- 2 files changed, 198 insertions(+), 253 deletions(-) diff --git a/poetry.lock b/poetry.lock index 0c394dd..362a117 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,69 +1,39 @@ # This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. -[[package]] -name = "appdirs" -version = "1.4.4" -description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -optional = false -python-versions = "*" -files = [ - {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, - {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, -] - -[[package]] -name = "atomicwrites" -version = "1.4.0" -description = "Atomic file writes." -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -files = [ - {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, - {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, -] - -[[package]] -name = "attrs" -version = "21.2.0" -description = "Classes Without Boilerplate" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" -files = [ - {file = "attrs-21.2.0-py2.py3-none-any.whl", hash = "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1"}, - {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"}, -] - -[package.extras] -dev = ["coverage[toml] (>=5.0.2)", "furo", "hypothesis", "mypy", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six", "sphinx", "sphinx-notfound-page", "zope.interface"] -docs = ["furo", "sphinx", "sphinx-notfound-page", "zope.interface"] -tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "mypy", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six", "zope.interface"] -tests-no-zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "mypy", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six"] - [[package]] name = "black" -version = "21.6b0" +version = "22.12.0" description = "The uncompromising code formatter." optional = false -python-versions = ">=3.6.2" +python-versions = ">=3.7" files = [ - {file = "black-21.6b0-py3-none-any.whl", hash = "sha256:dfb8c5a069012b2ab1e972e7b908f5fb42b6bbabcba0a788b86dc05067c7d9c7"}, - {file = "black-21.6b0.tar.gz", hash = "sha256:dc132348a88d103016726fe360cb9ede02cecf99b76e3660ce6c596be132ce04"}, + {file = "black-22.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9eedd20838bd5d75b80c9f5487dbcb06836a43833a37846cf1d8c1cc01cef59d"}, + {file = "black-22.12.0-cp310-cp310-win_amd64.whl", hash = "sha256:159a46a4947f73387b4d83e87ea006dbb2337eab6c879620a3ba52699b1f4351"}, + {file = "black-22.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d30b212bffeb1e252b31dd269dfae69dd17e06d92b87ad26e23890f3efea366f"}, + {file = "black-22.12.0-cp311-cp311-win_amd64.whl", hash = "sha256:7412e75863aa5c5411886804678b7d083c7c28421210180d67dfd8cf1221e1f4"}, + {file = "black-22.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c116eed0efb9ff870ded8b62fe9f28dd61ef6e9ddd28d83d7d264a38417dcee2"}, + {file = "black-22.12.0-cp37-cp37m-win_amd64.whl", hash = "sha256:1f58cbe16dfe8c12b7434e50ff889fa479072096d79f0a7f25e4ab8e94cd8350"}, + {file = "black-22.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:77d86c9f3db9b1bf6761244bc0b3572a546f5fe37917a044e02f3166d5aafa7d"}, + {file = "black-22.12.0-cp38-cp38-win_amd64.whl", hash = "sha256:82d9fe8fee3401e02e79767016b4907820a7dc28d70d137eb397b92ef3cc5bfc"}, + {file = "black-22.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:101c69b23df9b44247bd88e1d7e90154336ac4992502d4197bdac35dd7ee3320"}, + {file = "black-22.12.0-cp39-cp39-win_amd64.whl", hash = "sha256:559c7a1ba9a006226f09e4916060982fd27334ae1998e7a38b3f33a37f7a2148"}, + {file = "black-22.12.0-py3-none-any.whl", hash = "sha256:436cc9167dd28040ad90d3b404aec22cedf24a6e4d7de221bec2730ec0c97bcf"}, + {file = "black-22.12.0.tar.gz", hash = "sha256:229351e5a18ca30f447bf724d007f890f97e13af070bb6ad4c0a441cd7596a2f"}, ] [package.dependencies] -appdirs = "*" -click = ">=7.1.2" +click = ">=8.0.0" mypy-extensions = ">=0.4.3" -pathspec = ">=0.8.1,<1" -regex = ">=2020.1.8" -toml = ">=0.10.1" -typed-ast = {version = ">=1.4.2", markers = "python_version < \"3.8\""} -typing-extensions = {version = ">=3.7.4", markers = "python_version < \"3.8\""} +pathspec = ">=0.9.0" +platformdirs = ">=2" +tomli = {version = ">=1.1.0", markers = "python_full_version < \"3.11.0a7\""} +typed-ast = {version = ">=1.4.2", markers = "python_version < \"3.8\" and implementation_name == \"cpython\""} +typing-extensions = {version = ">=3.10.0.0", markers = "python_version < \"3.10\""} [package.extras] colorama = ["colorama (>=0.4.3)"] -d = ["aiohttp (>=3.6.0)", "aiohttp-cors (>=0.4.0)"] -python2 = ["typed-ast (>=1.4.2)"] +d = ["aiohttp (>=3.7.4)"] +jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] uvloop = ["uvloop (>=0.15.2)"] [[package]] @@ -79,13 +49,13 @@ files = [ [[package]] name = "click" -version = "8.0.1" +version = "8.1.7" description = "Composable command line interface toolkit" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"}, - {file = "click-8.0.1.tar.gz", hash = "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"}, + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, ] [package.dependencies] @@ -94,24 +64,38 @@ importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} [[package]] name = "colorama" -version = "0.4.4" +version = "0.4.6" description = "Cross-platform colored terminal text." optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "exceptiongroup" +version = "1.2.1" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" files = [ - {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, - {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, + {file = "exceptiongroup-1.2.1-py3-none-any.whl", hash = "sha256:5258b9ed329c5bbdd31a309f53cbfb0b155341807f6ff7606a1e801a891b29ad"}, + {file = "exceptiongroup-1.2.1.tar.gz", hash = "sha256:a4785e48b045528f5bfe627b6ad554ff32def154f42372786903b7abcfe1aa16"}, ] +[package.extras] +test = ["pytest (>=6)"] + [[package]] name = "importlib-metadata" -version = "4.5.0" +version = "6.7.0" description = "Read metadata from Python packages" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "importlib_metadata-4.5.0-py3-none-any.whl", hash = "sha256:833b26fb89d5de469b24a390e9df088d4e52e4ba33b01dc5e0e4f41b81a16c00"}, - {file = "importlib_metadata-4.5.0.tar.gz", hash = "sha256:b142cc1dd1342f31ff04bb7d022492b09920cb64fed867cd3ea6f80fe3ebd139"}, + {file = "importlib_metadata-6.7.0-py3-none-any.whl", hash = "sha256:cb52082e659e97afc5dac71e79de97d8681de3aa07ff18578330904a9d18e5b5"}, + {file = "importlib_metadata-6.7.0.tar.gz", hash = "sha256:1aaf550d4f73e5d6783e7acb77aec43d49da8017410afae93822cc9cca98c4d4"}, ] [package.dependencies] @@ -119,123 +103,137 @@ typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} zipp = ">=0.5" [package.extras] -docs = ["jaraco.packaging (>=8.2)", "rst.linker (>=1.9)", "sphinx"] -testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pep517", "pyfakefs", "pytest (>=4.6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.0.1)", "pytest-flake8", "pytest-mypy"] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +perf = ["ipython"] +testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)", "pytest-ruff"] [[package]] name = "iniconfig" -version = "1.1.1" -description = "iniconfig: brain-dead simple config-ini parsing" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" optional = false -python-versions = "*" +python-versions = ">=3.7" files = [ - {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, - {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] [[package]] name = "mypy" -version = "0.812" +version = "1.4.1" description = "Optional static typing for Python" optional = false -python-versions = ">=3.5" +python-versions = ">=3.7" files = [ - {file = "mypy-0.812-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:a26f8ec704e5a7423c8824d425086705e381b4f1dfdef6e3a1edab7ba174ec49"}, - {file = "mypy-0.812-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:28fb5479c494b1bab244620685e2eb3c3f988d71fd5d64cc753195e8ed53df7c"}, - {file = "mypy-0.812-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:9743c91088d396c1a5a3c9978354b61b0382b4e3c440ce83cf77994a43e8c521"}, - {file = "mypy-0.812-cp35-cp35m-win_amd64.whl", hash = "sha256:d7da2e1d5f558c37d6e8c1246f1aec1e7349e4913d8fb3cb289a35de573fe2eb"}, - {file = "mypy-0.812-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:4eec37370483331d13514c3f55f446fc5248d6373e7029a29ecb7b7494851e7a"}, - {file = "mypy-0.812-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:d65cc1df038ef55a99e617431f0553cd77763869eebdf9042403e16089fe746c"}, - {file = "mypy-0.812-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:61a3d5b97955422964be6b3baf05ff2ce7f26f52c85dd88db11d5e03e146a3a6"}, - {file = "mypy-0.812-cp36-cp36m-win_amd64.whl", hash = "sha256:25adde9b862f8f9aac9d2d11971f226bd4c8fbaa89fb76bdadb267ef22d10064"}, - {file = "mypy-0.812-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:552a815579aa1e995f39fd05dde6cd378e191b063f031f2acfe73ce9fb7f9e56"}, - {file = "mypy-0.812-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:499c798053cdebcaa916eef8cd733e5584b5909f789de856b482cd7d069bdad8"}, - {file = "mypy-0.812-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:5873888fff1c7cf5b71efbe80e0e73153fe9212fafdf8e44adfe4c20ec9f82d7"}, - {file = "mypy-0.812-cp37-cp37m-win_amd64.whl", hash = "sha256:9f94aac67a2045ec719ffe6111df543bac7874cee01f41928f6969756e030564"}, - {file = "mypy-0.812-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d23e0ea196702d918b60c8288561e722bf437d82cb7ef2edcd98cfa38905d506"}, - {file = "mypy-0.812-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:674e822aa665b9fd75130c6c5f5ed9564a38c6cea6a6432ce47eafb68ee578c5"}, - {file = "mypy-0.812-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:abf7e0c3cf117c44d9285cc6128856106183938c68fd4944763003decdcfeb66"}, - {file = "mypy-0.812-cp38-cp38-win_amd64.whl", hash = "sha256:0d0a87c0e7e3a9becdfbe936c981d32e5ee0ccda3e0f07e1ef2c3d1a817cf73e"}, - {file = "mypy-0.812-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7ce3175801d0ae5fdfa79b4f0cfed08807af4d075b402b7e294e6aa72af9aa2a"}, - {file = "mypy-0.812-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:b09669bcda124e83708f34a94606e01b614fa71931d356c1f1a5297ba11f110a"}, - {file = "mypy-0.812-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:33f159443db0829d16f0a8d83d94df3109bb6dd801975fe86bacb9bf71628e97"}, - {file = "mypy-0.812-cp39-cp39-win_amd64.whl", hash = "sha256:3f2aca7f68580dc2508289c729bd49ee929a436208d2b2b6aab15745a70a57df"}, - {file = "mypy-0.812-py3-none-any.whl", hash = "sha256:2f9b3407c58347a452fc0736861593e105139b905cca7d097e413453a1d650b4"}, - {file = "mypy-0.812.tar.gz", hash = "sha256:cd07039aa5df222037005b08fbbfd69b3ab0b0bd7a07d7906de75ae52c4e3119"}, + {file = "mypy-1.4.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:566e72b0cd6598503e48ea610e0052d1b8168e60a46e0bfd34b3acf2d57f96a8"}, + {file = "mypy-1.4.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ca637024ca67ab24a7fd6f65d280572c3794665eaf5edcc7e90a866544076878"}, + {file = "mypy-1.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0dde1d180cd84f0624c5dcaaa89c89775550a675aff96b5848de78fb11adabcd"}, + {file = "mypy-1.4.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:8c4d8e89aa7de683e2056a581ce63c46a0c41e31bd2b6d34144e2c80f5ea53dc"}, + {file = "mypy-1.4.1-cp310-cp310-win_amd64.whl", hash = "sha256:bfdca17c36ae01a21274a3c387a63aa1aafe72bff976522886869ef131b937f1"}, + {file = "mypy-1.4.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:7549fbf655e5825d787bbc9ecf6028731973f78088fbca3a1f4145c39ef09462"}, + {file = "mypy-1.4.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:98324ec3ecf12296e6422939e54763faedbfcc502ea4a4c38502082711867258"}, + {file = "mypy-1.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:141dedfdbfe8a04142881ff30ce6e6653c9685b354876b12e4fe6c78598b45e2"}, + {file = "mypy-1.4.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:8207b7105829eca6f3d774f64a904190bb2231de91b8b186d21ffd98005f14a7"}, + {file = "mypy-1.4.1-cp311-cp311-win_amd64.whl", hash = "sha256:16f0db5b641ba159eff72cff08edc3875f2b62b2fa2bc24f68c1e7a4e8232d01"}, + {file = "mypy-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:470c969bb3f9a9efcedbadcd19a74ffb34a25f8e6b0e02dae7c0e71f8372f97b"}, + {file = "mypy-1.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e5952d2d18b79f7dc25e62e014fe5a23eb1a3d2bc66318df8988a01b1a037c5b"}, + {file = "mypy-1.4.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:190b6bab0302cec4e9e6767d3eb66085aef2a1cc98fe04936d8a42ed2ba77bb7"}, + {file = "mypy-1.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9d40652cc4fe33871ad3338581dca3297ff5f2213d0df345bcfbde5162abf0c9"}, + {file = "mypy-1.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:01fd2e9f85622d981fd9063bfaef1aed6e336eaacca00892cd2d82801ab7c042"}, + {file = "mypy-1.4.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:2460a58faeea905aeb1b9b36f5065f2dc9a9c6e4c992a6499a2360c6c74ceca3"}, + {file = "mypy-1.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a2746d69a8196698146a3dbe29104f9eb6a2a4d8a27878d92169a6c0b74435b6"}, + {file = "mypy-1.4.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:ae704dcfaa180ff7c4cfbad23e74321a2b774f92ca77fd94ce1049175a21c97f"}, + {file = "mypy-1.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:43d24f6437925ce50139a310a64b2ab048cb2d3694c84c71c3f2a1626d8101dc"}, + {file = "mypy-1.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c482e1246726616088532b5e964e39765b6d1520791348e6c9dc3af25b233828"}, + {file = "mypy-1.4.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:43b592511672017f5b1a483527fd2684347fdffc041c9ef53428c8dc530f79a3"}, + {file = "mypy-1.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:34a9239d5b3502c17f07fd7c0b2ae6b7dd7d7f6af35fbb5072c6208e76295816"}, + {file = "mypy-1.4.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:5703097c4936bbb9e9bce41478c8d08edd2865e177dc4c52be759f81ee4dd26c"}, + {file = "mypy-1.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:e02d700ec8d9b1859790c0475df4e4092c7bf3272a4fd2c9f33d87fac4427b8f"}, + {file = "mypy-1.4.1-py3-none-any.whl", hash = "sha256:45d32cec14e7b97af848bddd97d85ea4f0db4d5a149ed9676caa4eb2f7402bb4"}, + {file = "mypy-1.4.1.tar.gz", hash = "sha256:9bbcd9ab8ea1f2e1c8031c21445b511442cc45c89951e49bbf852cbb70755b1b"}, ] [package.dependencies] -mypy-extensions = ">=0.4.3,<0.5.0" -typed-ast = ">=1.4.0,<1.5.0" -typing-extensions = ">=3.7.4" +mypy-extensions = ">=1.0.0" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +typed-ast = {version = ">=1.4.0,<2", markers = "python_version < \"3.8\""} +typing-extensions = ">=4.1.0" [package.extras] dmypy = ["psutil (>=4.0)"] +install-types = ["pip"] +python2 = ["typed-ast (>=1.4.0,<2)"] +reports = ["lxml"] [[package]] name = "mypy-extensions" -version = "0.4.3" -description = "Experimental type system extensions for programs checked with the mypy typechecker." +version = "1.0.0" +description = "Type system extensions for programs checked with the mypy type checker." optional = false -python-versions = "*" +python-versions = ">=3.5" files = [ - {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, - {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, + {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, + {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, ] [[package]] name = "packaging" -version = "20.9" +version = "24.0" description = "Core utilities for Python packages" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=3.7" files = [ - {file = "packaging-20.9-py2.py3-none-any.whl", hash = "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"}, - {file = "packaging-20.9.tar.gz", hash = "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"}, + {file = "packaging-24.0-py3-none-any.whl", hash = "sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5"}, + {file = "packaging-24.0.tar.gz", hash = "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9"}, ] -[package.dependencies] -pyparsing = ">=2.0.2" - [[package]] name = "pathspec" -version = "0.8.1" +version = "0.11.2" description = "Utility library for gitignore style pattern matching of file paths." optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.7" files = [ - {file = "pathspec-0.8.1-py2.py3-none-any.whl", hash = "sha256:aa0cb481c4041bf52ffa7b0d8fa6cd3e88a2ca4879c533c9153882ee2556790d"}, - {file = "pathspec-0.8.1.tar.gz", hash = "sha256:86379d6b86d75816baba717e64b1a3a3469deb93bb76d613c9ce79edc5cb68fd"}, + {file = "pathspec-0.11.2-py3-none-any.whl", hash = "sha256:1d6ed233af05e679efb96b1851550ea95bbb64b7c490b0f5aa52996c11e92a20"}, + {file = "pathspec-0.11.2.tar.gz", hash = "sha256:e0d8d0ac2f12da61956eb2306b69f9469b42f4deb0f3cb6ed47b9cce9996ced3"}, ] [[package]] -name = "pluggy" -version = "0.13.1" -description = "plugin and hook calling mechanisms for python" +name = "platformdirs" +version = "4.0.0" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=3.7" files = [ - {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, - {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, + {file = "platformdirs-4.0.0-py3-none-any.whl", hash = "sha256:118c954d7e949b35437270383a3f2531e99dd93cf7ce4dc8340d3356d30f173b"}, + {file = "platformdirs-4.0.0.tar.gz", hash = "sha256:cb633b2bcf10c51af60beb0ab06d2f1d69064b43abf4c185ca6b28865f3f9731"}, ] [package.dependencies] -importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} +typing-extensions = {version = ">=4.7.1", markers = "python_version < \"3.8\""} [package.extras] -dev = ["pre-commit", "tox"] +docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.1)", "sphinx-autodoc-typehints (>=1.24)"] +test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)"] [[package]] -name = "py" -version = "1.10.0" -description = "library with cross-python path, ini-parsing, io, code, log facilities" +name = "pluggy" +version = "1.2.0" +description = "plugin and hook calling mechanisms for python" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=3.7" files = [ - {file = "py-1.10.0-py2.py3-none-any.whl", hash = "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"}, - {file = "py-1.10.0.tar.gz", hash = "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3"}, + {file = "pluggy-1.2.0-py3-none-any.whl", hash = "sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849"}, + {file = "pluggy-1.2.0.tar.gz", hash = "sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3"}, ] +[package.dependencies] +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + [[package]] name = "pylzma" version = "0.5.0" @@ -246,170 +244,117 @@ files = [ {file = "pylzma-0.5.0.tar.gz", hash = "sha256:b874172afbf37770e643bf2dc9d9b6b03eb95d8f8162e157145b3fe9e1b68a1c"}, ] -[[package]] -name = "pyparsing" -version = "2.4.7" -description = "Python parsing module" -optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" -files = [ - {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, - {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, -] - [[package]] name = "pytest" -version = "6.2.4" +version = "7.4.4" description = "pytest: simple powerful testing with Python" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "pytest-6.2.4-py3-none-any.whl", hash = "sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890"}, - {file = "pytest-6.2.4.tar.gz", hash = "sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b"}, + {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, + {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, ] [package.dependencies] -atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} -attrs = ">=19.2.0" colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} iniconfig = "*" packaging = "*" -pluggy = ">=0.12,<1.0.0a1" -py = ">=1.8.2" -toml = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] -testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] - -[[package]] -name = "regex" -version = "2021.4.4" -description = "Alternative regular expression module, to replace re." -optional = false -python-versions = "*" -files = [ - {file = "regex-2021.4.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:619d71c59a78b84d7f18891fe914446d07edd48dc8328c8e149cbe0929b4e000"}, - {file = "regex-2021.4.4-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:47bf5bf60cf04d72bf6055ae5927a0bd9016096bf3d742fa50d9bf9f45aa0711"}, - {file = "regex-2021.4.4-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:281d2fd05555079448537fe108d79eb031b403dac622621c78944c235f3fcf11"}, - {file = "regex-2021.4.4-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:bd28bc2e3a772acbb07787c6308e00d9626ff89e3bfcdebe87fa5afbfdedf968"}, - {file = "regex-2021.4.4-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:7c2a1af393fcc09e898beba5dd59196edaa3116191cc7257f9224beaed3e1aa0"}, - {file = "regex-2021.4.4-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:c38c71df845e2aabb7fb0b920d11a1b5ac8526005e533a8920aea97efb8ec6a4"}, - {file = "regex-2021.4.4-cp36-cp36m-manylinux2014_i686.whl", hash = "sha256:96fcd1888ab4d03adfc9303a7b3c0bd78c5412b2bfbe76db5b56d9eae004907a"}, - {file = "regex-2021.4.4-cp36-cp36m-manylinux2014_x86_64.whl", hash = "sha256:ade17eb5d643b7fead300a1641e9f45401c98eee23763e9ed66a43f92f20b4a7"}, - {file = "regex-2021.4.4-cp36-cp36m-win32.whl", hash = "sha256:e8e5b509d5c2ff12f8418006d5a90e9436766133b564db0abaec92fd27fcee29"}, - {file = "regex-2021.4.4-cp36-cp36m-win_amd64.whl", hash = "sha256:11d773d75fa650cd36f68d7ca936e3c7afaae41b863b8c387a22aaa78d3c5c79"}, - {file = "regex-2021.4.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:d3029c340cfbb3ac0a71798100ccc13b97dddf373a4ae56b6a72cf70dfd53bc8"}, - {file = "regex-2021.4.4-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:18c071c3eb09c30a264879f0d310d37fe5d3a3111662438889ae2eb6fc570c31"}, - {file = "regex-2021.4.4-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:4c557a7b470908b1712fe27fb1ef20772b78079808c87d20a90d051660b1d69a"}, - {file = "regex-2021.4.4-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:01afaf2ec48e196ba91b37451aa353cb7eda77efe518e481707e0515025f0cd5"}, - {file = "regex-2021.4.4-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:3a9cd17e6e5c7eb328517969e0cb0c3d31fd329298dd0c04af99ebf42e904f82"}, - {file = "regex-2021.4.4-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:90f11ff637fe8798933fb29f5ae1148c978cccb0452005bf4c69e13db951e765"}, - {file = "regex-2021.4.4-cp37-cp37m-manylinux2014_i686.whl", hash = "sha256:919859aa909429fb5aa9cf8807f6045592c85ef56fdd30a9a3747e513db2536e"}, - {file = "regex-2021.4.4-cp37-cp37m-manylinux2014_x86_64.whl", hash = "sha256:339456e7d8c06dd36a22e451d58ef72cef293112b559010db3d054d5560ef439"}, - {file = "regex-2021.4.4-cp37-cp37m-win32.whl", hash = "sha256:67bdb9702427ceddc6ef3dc382455e90f785af4c13d495f9626861763ee13f9d"}, - {file = "regex-2021.4.4-cp37-cp37m-win_amd64.whl", hash = "sha256:32e65442138b7b76dd8173ffa2cf67356b7bc1768851dded39a7a13bf9223da3"}, - {file = "regex-2021.4.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1e1c20e29358165242928c2de1482fb2cf4ea54a6a6dea2bd7a0e0d8ee321500"}, - {file = "regex-2021.4.4-cp38-cp38-manylinux1_i686.whl", hash = "sha256:314d66636c494ed9c148a42731b3834496cc9a2c4251b1661e40936814542b14"}, - {file = "regex-2021.4.4-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:6d1b01031dedf2503631d0903cb563743f397ccaf6607a5e3b19a3d76fc10480"}, - {file = "regex-2021.4.4-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:741a9647fcf2e45f3a1cf0e24f5e17febf3efe8d4ba1281dcc3aa0459ef424dc"}, - {file = "regex-2021.4.4-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:4c46e22a0933dd783467cf32b3516299fb98cfebd895817d685130cc50cd1093"}, - {file = "regex-2021.4.4-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:e512d8ef5ad7b898cdb2d8ee1cb09a8339e4f8be706d27eaa180c2f177248a10"}, - {file = "regex-2021.4.4-cp38-cp38-manylinux2014_i686.whl", hash = "sha256:980d7be47c84979d9136328d882f67ec5e50008681d94ecc8afa8a65ed1f4a6f"}, - {file = "regex-2021.4.4-cp38-cp38-manylinux2014_x86_64.whl", hash = "sha256:ce15b6d103daff8e9fee13cf7f0add05245a05d866e73926c358e871221eae87"}, - {file = "regex-2021.4.4-cp38-cp38-win32.whl", hash = "sha256:a91aa8619b23b79bcbeb37abe286f2f408d2f2d6f29a17237afda55bb54e7aac"}, - {file = "regex-2021.4.4-cp38-cp38-win_amd64.whl", hash = "sha256:c0502c0fadef0d23b128605d69b58edb2c681c25d44574fc673b0e52dce71ee2"}, - {file = "regex-2021.4.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:598585c9f0af8374c28edd609eb291b5726d7cbce16be6a8b95aa074d252ee17"}, - {file = "regex-2021.4.4-cp39-cp39-manylinux1_i686.whl", hash = "sha256:ee54ff27bf0afaf4c3b3a62bcd016c12c3fdb4ec4f413391a90bd38bc3624605"}, - {file = "regex-2021.4.4-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:7d9884d86dd4dd489e981d94a65cd30d6f07203d90e98f6f657f05170f6324c9"}, - {file = "regex-2021.4.4-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:bf5824bfac591ddb2c1f0a5f4ab72da28994548c708d2191e3b87dd207eb3ad7"}, - {file = "regex-2021.4.4-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:563085e55b0d4fb8f746f6a335893bda5c2cef43b2f0258fe1020ab1dd874df8"}, - {file = "regex-2021.4.4-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:b9c3db21af35e3b3c05764461b262d6f05bbca08a71a7849fd79d47ba7bc33ed"}, - {file = "regex-2021.4.4-cp39-cp39-manylinux2014_i686.whl", hash = "sha256:3916d08be28a1149fb97f7728fca1f7c15d309a9f9682d89d79db75d5e52091c"}, - {file = "regex-2021.4.4-cp39-cp39-manylinux2014_x86_64.whl", hash = "sha256:fd45ff9293d9274c5008a2054ecef86a9bfe819a67c7be1afb65e69b405b3042"}, - {file = "regex-2021.4.4-cp39-cp39-win32.whl", hash = "sha256:fa4537fb4a98fe8fde99626e4681cc644bdcf2a795038533f9f711513a862ae6"}, - {file = "regex-2021.4.4-cp39-cp39-win_amd64.whl", hash = "sha256:97f29f57d5b84e73fbaf99ab3e26134e6687348e95ef6b48cfd2c06807005a07"}, - {file = "regex-2021.4.4.tar.gz", hash = "sha256:52ba3d3f9b942c49d7e4bc105bb28551c44065f139a65062ab7912bef10c9afb"}, -] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] [[package]] -name = "toml" -version = "0.10.2" -description = "Python Library for Tom's Obvious, Minimal Language" +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +python-versions = ">=3.7" files = [ - {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, - {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] [[package]] name = "typed-ast" -version = "1.4.3" +version = "1.5.5" description = "a fork of Python 2 and 3 ast modules with type comment support" optional = false -python-versions = "*" +python-versions = ">=3.6" files = [ - {file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:2068531575a125b87a41802130fa7e29f26c09a2833fea68d9a40cf33902eba6"}, - {file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:c907f561b1e83e93fad565bac5ba9c22d96a54e7ea0267c708bffe863cbe4075"}, - {file = "typed_ast-1.4.3-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:1b3ead4a96c9101bef08f9f7d1217c096f31667617b58de957f690c92378b528"}, - {file = "typed_ast-1.4.3-cp35-cp35m-win32.whl", hash = "sha256:dde816ca9dac1d9c01dd504ea5967821606f02e510438120091b84e852367428"}, - {file = "typed_ast-1.4.3-cp35-cp35m-win_amd64.whl", hash = "sha256:777a26c84bea6cd934422ac2e3b78863a37017618b6e5c08f92ef69853e765d3"}, - {file = "typed_ast-1.4.3-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f8afcf15cc511ada719a88e013cec87c11aff7b91f019295eb4530f96fe5ef2f"}, - {file = "typed_ast-1.4.3-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:52b1eb8c83f178ab787f3a4283f68258525f8d70f778a2f6dd54d3b5e5fb4341"}, - {file = "typed_ast-1.4.3-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:01ae5f73431d21eead5015997ab41afa53aa1fbe252f9da060be5dad2c730ace"}, - {file = "typed_ast-1.4.3-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:c190f0899e9f9f8b6b7863debfb739abcb21a5c054f911ca3596d12b8a4c4c7f"}, - {file = "typed_ast-1.4.3-cp36-cp36m-win32.whl", hash = "sha256:398e44cd480f4d2b7ee8d98385ca104e35c81525dd98c519acff1b79bdaac363"}, - {file = "typed_ast-1.4.3-cp36-cp36m-win_amd64.whl", hash = "sha256:bff6ad71c81b3bba8fa35f0f1921fb24ff4476235a6e94a26ada2e54370e6da7"}, - {file = "typed_ast-1.4.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0fb71b8c643187d7492c1f8352f2c15b4c4af3f6338f21681d3681b3dc31a266"}, - {file = "typed_ast-1.4.3-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:760ad187b1041a154f0e4d0f6aae3e40fdb51d6de16e5c99aedadd9246450e9e"}, - {file = "typed_ast-1.4.3-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:5feca99c17af94057417d744607b82dd0a664fd5e4ca98061480fd8b14b18d04"}, - {file = "typed_ast-1.4.3-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:95431a26309a21874005845c21118c83991c63ea800dd44843e42a916aec5899"}, - {file = "typed_ast-1.4.3-cp37-cp37m-win32.whl", hash = "sha256:aee0c1256be6c07bd3e1263ff920c325b59849dc95392a05f258bb9b259cf39c"}, - {file = "typed_ast-1.4.3-cp37-cp37m-win_amd64.whl", hash = "sha256:9ad2c92ec681e02baf81fdfa056fe0d818645efa9af1f1cd5fd6f1bd2bdfd805"}, - {file = "typed_ast-1.4.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:b36b4f3920103a25e1d5d024d155c504080959582b928e91cb608a65c3a49e1a"}, - {file = "typed_ast-1.4.3-cp38-cp38-manylinux1_i686.whl", hash = "sha256:067a74454df670dcaa4e59349a2e5c81e567d8d65458d480a5b3dfecec08c5ff"}, - {file = "typed_ast-1.4.3-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7538e495704e2ccda9b234b82423a4038f324f3a10c43bc088a1636180f11a41"}, - {file = "typed_ast-1.4.3-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:af3d4a73793725138d6b334d9d247ce7e5f084d96284ed23f22ee626a7b88e39"}, - {file = "typed_ast-1.4.3-cp38-cp38-win32.whl", hash = "sha256:f2362f3cb0f3172c42938946dbc5b7843c2a28aec307c49100c8b38764eb6927"}, - {file = "typed_ast-1.4.3-cp38-cp38-win_amd64.whl", hash = "sha256:dd4a21253f42b8d2b48410cb31fe501d32f8b9fbeb1f55063ad102fe9c425e40"}, - {file = "typed_ast-1.4.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:f328adcfebed9f11301eaedfa48e15bdece9b519fb27e6a8c01aa52a17ec31b3"}, - {file = "typed_ast-1.4.3-cp39-cp39-manylinux1_i686.whl", hash = "sha256:2c726c276d09fc5c414693a2de063f521052d9ea7c240ce553316f70656c84d4"}, - {file = "typed_ast-1.4.3-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:cae53c389825d3b46fb37538441f75d6aecc4174f615d048321b716df2757fb0"}, - {file = "typed_ast-1.4.3-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:b9574c6f03f685070d859e75c7f9eeca02d6933273b5e69572e5ff9d5e3931c3"}, - {file = "typed_ast-1.4.3-cp39-cp39-win32.whl", hash = "sha256:209596a4ec71d990d71d5e0d312ac935d86930e6eecff6ccc7007fe54d703808"}, - {file = "typed_ast-1.4.3-cp39-cp39-win_amd64.whl", hash = "sha256:9c6d1a54552b5330bc657b7ef0eae25d00ba7ffe85d9ea8ae6540d2197a3788c"}, - {file = "typed_ast-1.4.3.tar.gz", hash = "sha256:fb1bbeac803adea29cedd70781399c99138358c26d05fcbd23c13016b7f5ec65"}, + {file = "typed_ast-1.5.5-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:4bc1efe0ce3ffb74784e06460f01a223ac1f6ab31c6bc0376a21184bf5aabe3b"}, + {file = "typed_ast-1.5.5-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:5f7a8c46a8b333f71abd61d7ab9255440d4a588f34a21f126bbfc95f6049e686"}, + {file = "typed_ast-1.5.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:597fc66b4162f959ee6a96b978c0435bd63791e31e4f410622d19f1686d5e769"}, + {file = "typed_ast-1.5.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d41b7a686ce653e06c2609075d397ebd5b969d821b9797d029fccd71fdec8e04"}, + {file = "typed_ast-1.5.5-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:5fe83a9a44c4ce67c796a1b466c270c1272e176603d5e06f6afbc101a572859d"}, + {file = "typed_ast-1.5.5-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:d5c0c112a74c0e5db2c75882a0adf3133adedcdbfd8cf7c9d6ed77365ab90a1d"}, + {file = "typed_ast-1.5.5-cp310-cp310-win_amd64.whl", hash = "sha256:e1a976ed4cc2d71bb073e1b2a250892a6e968ff02aa14c1f40eba4f365ffec02"}, + {file = "typed_ast-1.5.5-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c631da9710271cb67b08bd3f3813b7af7f4c69c319b75475436fcab8c3d21bee"}, + {file = "typed_ast-1.5.5-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:b445c2abfecab89a932b20bd8261488d574591173d07827c1eda32c457358b18"}, + {file = "typed_ast-1.5.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cc95ffaaab2be3b25eb938779e43f513e0e538a84dd14a5d844b8f2932593d88"}, + {file = "typed_ast-1.5.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61443214d9b4c660dcf4b5307f15c12cb30bdfe9588ce6158f4a005baeb167b2"}, + {file = "typed_ast-1.5.5-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:6eb936d107e4d474940469e8ec5b380c9b329b5f08b78282d46baeebd3692dc9"}, + {file = "typed_ast-1.5.5-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e48bf27022897577d8479eaed64701ecaf0467182448bd95759883300ca818c8"}, + {file = "typed_ast-1.5.5-cp311-cp311-win_amd64.whl", hash = "sha256:83509f9324011c9a39faaef0922c6f720f9623afe3fe220b6d0b15638247206b"}, + {file = "typed_ast-1.5.5-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:44f214394fc1af23ca6d4e9e744804d890045d1643dd7e8229951e0ef39429b5"}, + {file = "typed_ast-1.5.5-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:118c1ce46ce58fda78503eae14b7664163aa735b620b64b5b725453696f2a35c"}, + {file = "typed_ast-1.5.5-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:be4919b808efa61101456e87f2d4c75b228f4e52618621c77f1ddcaae15904fa"}, + {file = "typed_ast-1.5.5-cp36-cp36m-musllinux_1_1_aarch64.whl", hash = "sha256:fc2b8c4e1bc5cd96c1a823a885e6b158f8451cf6f5530e1829390b4d27d0807f"}, + {file = "typed_ast-1.5.5-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:16f7313e0a08c7de57f2998c85e2a69a642e97cb32f87eb65fbfe88381a5e44d"}, + {file = "typed_ast-1.5.5-cp36-cp36m-win_amd64.whl", hash = "sha256:2b946ef8c04f77230489f75b4b5a4a6f24c078be4aed241cfabe9cbf4156e7e5"}, + {file = "typed_ast-1.5.5-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:2188bc33d85951ea4ddad55d2b35598b2709d122c11c75cffd529fbc9965508e"}, + {file = "typed_ast-1.5.5-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0635900d16ae133cab3b26c607586131269f88266954eb04ec31535c9a12ef1e"}, + {file = "typed_ast-1.5.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:57bfc3cf35a0f2fdf0a88a3044aafaec1d2f24d8ae8cd87c4f58d615fb5b6311"}, + {file = "typed_ast-1.5.5-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:fe58ef6a764de7b4b36edfc8592641f56e69b7163bba9f9c8089838ee596bfb2"}, + {file = "typed_ast-1.5.5-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:d09d930c2d1d621f717bb217bf1fe2584616febb5138d9b3e8cdd26506c3f6d4"}, + {file = "typed_ast-1.5.5-cp37-cp37m-win_amd64.whl", hash = "sha256:d40c10326893ecab8a80a53039164a224984339b2c32a6baf55ecbd5b1df6431"}, + {file = "typed_ast-1.5.5-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:fd946abf3c31fb50eee07451a6aedbfff912fcd13cf357363f5b4e834cc5e71a"}, + {file = "typed_ast-1.5.5-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:ed4a1a42df8a3dfb6b40c3d2de109e935949f2f66b19703eafade03173f8f437"}, + {file = "typed_ast-1.5.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:045f9930a1550d9352464e5149710d56a2aed23a2ffe78946478f7b5416f1ede"}, + {file = "typed_ast-1.5.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:381eed9c95484ceef5ced626355fdc0765ab51d8553fec08661dce654a935db4"}, + {file = "typed_ast-1.5.5-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:bfd39a41c0ef6f31684daff53befddae608f9daf6957140228a08e51f312d7e6"}, + {file = "typed_ast-1.5.5-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:8c524eb3024edcc04e288db9541fe1f438f82d281e591c548903d5b77ad1ddd4"}, + {file = "typed_ast-1.5.5-cp38-cp38-win_amd64.whl", hash = "sha256:7f58fabdde8dcbe764cef5e1a7fcb440f2463c1bbbec1cf2a86ca7bc1f95184b"}, + {file = "typed_ast-1.5.5-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:042eb665ff6bf020dd2243307d11ed626306b82812aba21836096d229fdc6a10"}, + {file = "typed_ast-1.5.5-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:622e4a006472b05cf6ef7f9f2636edc51bda670b7bbffa18d26b255269d3d814"}, + {file = "typed_ast-1.5.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1efebbbf4604ad1283e963e8915daa240cb4bf5067053cf2f0baadc4d4fb51b8"}, + {file = "typed_ast-1.5.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f0aefdd66f1784c58f65b502b6cf8b121544680456d1cebbd300c2c813899274"}, + {file = "typed_ast-1.5.5-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:48074261a842acf825af1968cd912f6f21357316080ebaca5f19abbb11690c8a"}, + {file = "typed_ast-1.5.5-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:429ae404f69dc94b9361bb62291885894b7c6fb4640d561179548c849f8492ba"}, + {file = "typed_ast-1.5.5-cp39-cp39-win_amd64.whl", hash = "sha256:335f22ccb244da2b5c296e6f96b06ee9bed46526db0de38d2f0e5a6597b81155"}, + {file = "typed_ast-1.5.5.tar.gz", hash = "sha256:94282f7a354f36ef5dbce0ef3467ebf6a258e370ab33d5b40c249fa996e590dd"}, ] [[package]] name = "typing-extensions" -version = "3.10.0.0" -description = "Backported and Experimental Type Hints for Python 3.5+" +version = "4.7.1" +description = "Backported and Experimental Type Hints for Python 3.7+" optional = false -python-versions = "*" +python-versions = ">=3.7" files = [ - {file = "typing_extensions-3.10.0.0-py2-none-any.whl", hash = "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497"}, - {file = "typing_extensions-3.10.0.0-py3-none-any.whl", hash = "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84"}, - {file = "typing_extensions-3.10.0.0.tar.gz", hash = "sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342"}, + {file = "typing_extensions-4.7.1-py3-none-any.whl", hash = "sha256:440d5dd3af93b060174bf433bccd69b0babc3b15b1a8dca43789fd7f61514b36"}, + {file = "typing_extensions-4.7.1.tar.gz", hash = "sha256:b75ddc264f0ba5615db7ba217daeb99701ad295353c45f9e95963337ceeeffb2"}, ] [[package]] name = "zipp" -version = "3.4.1" +version = "3.15.0" description = "Backport of pathlib-compatible object wrapper for zip files" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "zipp-3.4.1-py3-none-any.whl", hash = "sha256:51cb66cc54621609dd593d1787f286ee42a5c0adbb4b29abea5a63edc3e03098"}, - {file = "zipp-3.4.1.tar.gz", hash = "sha256:3607921face881ba3e026887d8150cca609d517579abe052ac81fc5aeffdbd76"}, + {file = "zipp-3.15.0-py3-none-any.whl", hash = "sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556"}, + {file = "zipp-3.15.0.tar.gz", hash = "sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b"}, ] [package.extras] -docs = ["jaraco.packaging (>=8.2)", "rst.linker (>=1.9)", "sphinx"] -testing = ["func-timeout", "jaraco.itertools", "pytest (>=4.6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=1.2.3)", "pytest-cov", "pytest-enabler", "pytest-flake8", "pytest-mypy"] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "30561353432b96b1526fd123e422c2d3d2a7455f72e67c826191f52ecbf68179" +content-hash = "301f27cf6e51d9a5a8c48276e2401355077117db790e7e7dc9acdd5fa050ab91" diff --git a/pyproject.toml b/pyproject.toml index 0ff939d..046a08a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,9 +16,9 @@ pylzma = "^0.5.0" chardet = "^5.2.0" [tool.poetry.dev-dependencies] -mypy = "^0.812" -pytest = "^6.2.4" -black = "^21.5b2" +mypy = "^1.4.0" +pytest = "^7.4.4" +black = "^22.3.0" [tool.poetry.scripts] napi-py = 'napi.main:cli_main' From f1b93ec431aafa8ef3d564eb77010f6f6cd66bc8 Mon Sep 17 00:00:00 2001 From: emkor93 Date: Sat, 15 Jun 2024 22:40:24 +0200 Subject: [PATCH 76/77] update README.md, correct version number --- README.md | 4 +--- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 83479df..f208f1f 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,7 @@ CLI tool for downloading subtitles from napiprojekt.pl, fork of [gabrys/napi.py](https://github.com/gabrys/napi.py) ## prerequisites -- Python 3.6.2 or newer -- on Linux, `python3-dev` package: - - for Debian-based systems, use `sudo apt-get install python3-dev` +- Python 3.7 or newer ## installation - `pip install napi-py` for user-wide installation diff --git a/pyproject.toml b/pyproject.toml index 046a08a..5369458 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "napi-py" -version = "0.2.3" +version = "1.2.3" description = "CLI tool for downloading subtitles from napiprojekt.pl" authors = ["emkor93 "] license = "GPL-3.0 License" From c2b3c0604bc2e836b68a1fb66edeb649d59790fd Mon Sep 17 00:00:00 2001 From: Mateusz Korzeniowski Date: Sun, 8 Sep 2024 19:14:11 +0200 Subject: [PATCH 77/77] Issue 4 test newer python (#5) * test with python 3.11 and 3.12 * bump dependencies --- .github/workflows/main.yml | 2 +- poetry.lock | 6 +++--- pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f39bee6..bb90dcb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - python-version: [ "3.7", "3.8", "3.9", "3.10" ] + python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ] steps: - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 diff --git a/poetry.lock b/poetry.lock index 362a117..fb8fc25 100644 --- a/poetry.lock +++ b/poetry.lock @@ -75,13 +75,13 @@ files = [ [[package]] name = "exceptiongroup" -version = "1.2.1" +version = "1.2.2" description = "Backport of PEP 654 (exception groups)" optional = false python-versions = ">=3.7" files = [ - {file = "exceptiongroup-1.2.1-py3-none-any.whl", hash = "sha256:5258b9ed329c5bbdd31a309f53cbfb0b155341807f6ff7606a1e801a891b29ad"}, - {file = "exceptiongroup-1.2.1.tar.gz", hash = "sha256:a4785e48b045528f5bfe627b6ad554ff32def154f42372786903b7abcfe1aa16"}, + {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"}, + {file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"}, ] [package.extras] diff --git a/pyproject.toml b/pyproject.toml index 5369458..1f62c46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "napi-py" -version = "1.2.3" +version = "1.2.4" description = "CLI tool for downloading subtitles from napiprojekt.pl" authors = ["emkor93 "] license = "GPL-3.0 License"