[packages/pynapi] - 0.21; napiprojekt broke old api - use new one for subtitles
arekm
arekm at pld-linux.org
Sun Nov 8 23:03:43 CET 2015
commit fef1d0dbc12de1adbaee0ddc837e36693b653e05
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sun Nov 8 23:03:36 2015 +0100
- 0.21; napiprojekt broke old api - use new one for subtitles
pynapi.py | 61 ++++++++++++++++++++++++++++++-------------------------------
pynapi.spec | 4 ++--
2 files changed, 32 insertions(+), 33 deletions(-)
---
diff --git a/pynapi.spec b/pynapi.spec
index e34e2a2..df4fcec 100644
--- a/pynapi.spec
+++ b/pynapi.spec
@@ -1,8 +1,8 @@
Summary: pynapi - Movie Subtitle Downloader
Summary(pl.UTF-8): pynapi - narzędzie do ściągania napisów do filmów
Name: pynapi
-Version: 0.20
-Release: 3
+Version: 0.21
+Release: 1
License: GPL v3+
Group: Applications/Multimedia
Source0: pynapi.py
diff --git a/pynapi.py b/pynapi.py
index b754f86..290d687 100644
--- a/pynapi.py
+++ b/pynapi.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#
-# Copyright (C) 2009 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+# Copyright (C) 2009-2015 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
#
# 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
@@ -23,6 +23,7 @@
#
import StringIO
+import base64
import re
import sys
import mimetypes
@@ -33,6 +34,7 @@ import os
import getopt
import socket
import struct
+import xml.etree.ElementTree as etree
import zipfile
try:
@@ -53,23 +55,6 @@ def calculate_digest(filename):
raise Exception('Hashing video file failed: %s' % ( e ))
return d.hexdigest()
-def napiprojekt_hash(z):
- 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]
-
- t = a + int(z[i], 16)
- v = int(z[t:t+2], 16)
- b.append( ("%x" % (v*m))[-1] )
-
- return ''.join(b)
-
def napisy24_hash(filename):
try:
longlongformat = '<q' # little-endian long long
@@ -222,8 +207,16 @@ def get_subtitle_napisy24(filename, digest=False, lang="pl"):
return sub
def get_subtitle_napiprojekt(digest, lang="PL"):
- url = "http://napiprojekt.pl/unit_napisy/dl.php?l=%s&f=%s&t=%s&v=pynapi&kolejka=false&nick=&pass=&napios=%s" % \
- (lang, digest, napiprojekt_hash(digest), os.name)
+ data = {
+ "downloaded_subtitles_id" : digest,
+ "mode" : "1",
+ "client" : "pynapi",
+ "client_ver": "0",
+ "downloaded_subtitles_lang" : lang,
+ "downloaded_subtitles_txt" : "1"
+ }
+
+ req = urllib2.Request("http://napiprojekt.pl/api/api-napiprojekt3.php", urllib.urlencode(data))
repeat = 3
sub = None
http_code = 200
@@ -231,10 +224,10 @@ def get_subtitle_napiprojekt(digest, lang="PL"):
while repeat > 0:
repeat = repeat - 1
try:
- sub = urllib2.urlopen(url)
+ subdata = urllib2.urlopen(req)
if hasattr(sub, 'getcode'):
- http_code = sub.getcode()
- sub = sub.read()
+ http_code = subdata.getcode()
+ subdata = subdata.read()
except (IOError, OSError), e:
error = error + " %s" % (e)
time.sleep(0.5)
@@ -244,14 +237,20 @@ def get_subtitle_napiprojekt(digest, lang="PL"):
error = error + ",HTTP code: %s" % (str(http_code))
time.sleep(0.5)
continue
-
- err_add = ''
- if not sub.startswith('NPc'):
- err_add = " (unknown error)"
- if len(sub.split('\n')) < 20:
- raise Exception('Subtitle NOT FOUND%s' % err_add)
-
- repeat = 0
+
+ try:
+ root = etree.fromstring(subdata)
+ status = root.find('status')
+ if status is not None and status.text == "success":
+ content = root.find('subtitles/content')
+ sub = base64.b64decode(content.text)
+ break
+ else:
+ raise Exception('Subtitle NOT FOUND')
+ except Exception, e:
+ error = error + ",XML parsing: %s" % e
+ time.sleep(0.5)
+ continue
if sub is None or sub == "":
raise Exception(error)
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/pynapi.git/commitdiff/fef1d0dbc12de1adbaee0ddc837e36693b653e05
More information about the pld-cvs-commit
mailing list