mirror of
https://source.perfectable.org/nivertius/napi.git
synced 2025-07-01 21:15:21 +02:00
printing subtitle metadata on success
This commit is contained in:
parent
3174cf0b09
commit
0e3e1021e2
1 changed files with 20 additions and 10 deletions
30
napi
30
napi
|
@ -9,7 +9,7 @@ import sys
|
|||
import urllib
|
||||
import os
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
from xml.etree.ElementTree import XML
|
||||
|
||||
import base64
|
||||
import subprocess
|
||||
|
@ -50,14 +50,23 @@ for movie_filename in args:
|
|||
"client" : "NapiProjekt",
|
||||
"downloaded_subtitles_lang" : language
|
||||
}
|
||||
try:
|
||||
request_data = urllib.urlencode(request_data)
|
||||
response = urllib.urlopen(base_url, request_data)
|
||||
response_xml = ET.XML(response.read())
|
||||
content = response_xml.find("subtitles").find("content").text
|
||||
except:
|
||||
print "%s: No subtitles" % (movie_filename,)
|
||||
sys.exit(2)
|
||||
|
||||
request_data = urllib.urlencode(request_data)
|
||||
response = urllib.urlopen(base_url, request_data)
|
||||
response_data = response.read()
|
||||
response_xml = XML(response_data)
|
||||
if response_xml.find('status').text != 'success':
|
||||
print "%s: No subtitles found" % (movie_filename,)
|
||||
continue
|
||||
|
||||
subtitle_xml = response_xml.find("subtitles")
|
||||
|
||||
subtitle_uploader = subtitle_xml.find('uploader').text
|
||||
subtitle_author = subtitle_xml.find('author').text
|
||||
subtitle_date = subtitle_xml.find('upload_date').text
|
||||
|
||||
|
||||
content = subtitle_xml.find("content").text
|
||||
decoded_content = base64.b64decode(content)
|
||||
with open(input_filename, "w") as input_file:
|
||||
input_file.write(decoded_content)
|
||||
|
@ -81,6 +90,7 @@ for movie_filename in args:
|
|||
os.remove(subtitle_filename)
|
||||
sys.exit(3)
|
||||
|
||||
print "%s: Subtitles fetched successfully to %s" % (movie_filename, subtitle_filename)
|
||||
print "%s: downloaded subtitles: uploader '%s', author '%s', date '%s'" % (movie_filename,
|
||||
subtitle_uploader, subtitle_author, subtitle_date)
|
||||
os.remove(input_filename)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue