Skip to content

Commit

Permalink
Add support for Kodi 19
Browse files Browse the repository at this point in the history
  • Loading branch information
CaTzil committed Mar 5, 2021
1 parent 0120b4d commit 6596ee7
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 163 deletions.
23 changes: 16 additions & 7 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><addon id="service.subtitles.napiprojekt" name="Napiprojekt.pl" version="1.1.3" provider-name="CaTz">
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.subtitles.napiprojekt" name="Napiprojekt.pl" version="2.0.0" provider-name="CaTz">
<requires>
<import addon="xbmc.python" version="2.14.0"/>
<import addon="xbmc.python" version="3.0.0"/>
</requires>
<extension point="xbmc.subtitle.module" library="service.py"/>
<extension point="xbmc.addon.metadata">
<summary lang="en">Napiprojekt.pl</summary>
<description lang="en">Search and Download subtitles from napiprojekt.pl.</description>
<source>https://github.com/CaTzil/service.subtitles.napiprojekt</source>
<forum>http://forum.kodi.tv/showthread.php?tid=186665</forum>
<license>GNU GENERAL PUBLIC LICENSE. Version 2, June 1991</license>
<summary lang="en_GB">Napiprojekt.pl</summary>
<description lang="en_GB">Search and Download subtitles from napiprojekt.pl.</description>
<summary lang="pl_PL">Napiprojekt.pl</summary>
<description lang="pl_PL">Szukaj i pobieraj napisy z serwisu napiprojekt.pl.</description>
<source>https://github.com/CaTzil/service.subtitles.napiprojekt</source>
<language>pl</language>
<source>https://github.com/CaTzil/service.subtitles.napisy24pl</source>
<forum>https://forum.kodi.tv/showthread.php?tid=193829</forum>
<license>GPL-2.0-only</license>
<assets>
<icon>icon.png</icon>
<clearlogo>logo.png</clearlogo>
</assets>
</extension>
</addon>
19 changes: 0 additions & 19 deletions resources/language/English/strings.po

This file was deleted.

17 changes: 17 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
msgid ""
msgstr ""
"Project-Id-Version: KODI Main\n"
"Report-Msgid-Bugs-To: https://github.com/xbmc/xbmc/issues/\n"
"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Kodi Translation Team\n"
"Language-Team: English (United States) (http://www.transifex.com/projects/p/kodi-main/language/en_GB/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en_GB\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgctxt "#32001"
msgid "Failed to download the subtitle"
msgstr ""
17 changes: 17 additions & 0 deletions resources/language/resource.language.en_us/strings.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
msgid ""
msgstr ""
"Project-Id-Version: KODI Main\n"
"Report-Msgid-Bugs-To: https://github.com/xbmc/xbmc/issues/\n"
"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Kodi Translation Team\n"
"Language-Team: English (United States) (http://www.transifex.com/projects/p/kodi-main/language/en_US/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en_US\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgctxt "#32001"
msgid "Failed to download the subtitle"
msgstr ""
17 changes: 17 additions & 0 deletions resources/language/resource.language.pl_pl/strings.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
msgid ""
msgstr ""
"Project-Id-Version: KODI Main\n"
"Report-Msgid-Bugs-To: https://github.com/xbmc/xbmc/issues/\n"
"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Kodi Translation Team\n"
"Language-Team: Polish (Poland) (http://www.transifex.com/projects/p/kodi-main/language/pl_PL/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: pl_PL\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"

msgctxt "#32001"
msgid "Error searching for subtitles"
msgstr "Nie udało się pobrać napisów"
127 changes: 48 additions & 79 deletions resources/lib/NapiProjekt.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,57 @@
# *-* coding: utf-8 *-*

import urllib, urllib2, base64, StringIO, sys
import os
import base64
from urllib.parse import urlencode
from urllib.request import urlopen
from xml.dom import minidom
import xbmc
import xbmcvfs
import xbmcaddon
import xbmcgui

__addon__ = xbmcaddon.Addon()
__scriptid__ = __addon__.getAddonInfo('id')
__scriptname__ = __addon__.getAddonInfo('name')
__version__ = __addon__.getAddonInfo('version')
__language__ = __addon__.getLocalizedString
__profile__ = xbmcvfs.translatePath(__addon__.getAddonInfo('profile'))
__temp__ = xbmcvfs.translatePath(os.path.join(__profile__, 'temp', ''))


def log(msg):
xbmc.log((u"### [%s] - %s" % (__scriptname__, msg)), level=xbmc.LOGDEBUG)

def notify(msg_id):
xbmcgui.Dialog().notification(__scriptname__, __language__(msg_id))

class NapiProjektHelper:
def __init__(self, filename, md5hash):
def __init__(self, md5hash):
self.info = {}
self.filename = filename
self.url = "http://napiprojekt.pl/api/api-napiprojekt3.php"
self.md5hash = md5hash

def search(self, item, t):
def search(self, item, file_token):
subtitle_list = []

for language in item["3let_language"]:
language = "pl" if language == "pol" else language
params = {
"l": language.upper(),
"l": xbmc.convertLanguage(language, xbmc.ISO_639_1).upper(),
"f": self.md5hash,
"t": t,
"t": file_token,
"v": "other",
"kolejka": "false",
"nick": "",
"pass": "",
"napios": "Linux"
}

url = "http://napiprojekt.pl/unit_napisy/dl.php?" + urllib.urlencode(params)
subs = urllib.urlopen(url).read()
url = "http://napiprojekt.pl/unit_napisy/dl.php?" + urlencode(params)
log("Requesting: %s" % url)

if subs[0:3] != 'NPc':
subs = urlopen(url).read()

if subs[0:3] != b'NPc':
subtitle_list.append({"language": language, "is_preferred": language == item["preferredlanguage"]})

return sorted(subtitle_list, key=lambda x: (x['is_preferred']), reverse=True)
Expand All @@ -46,79 +67,27 @@ def download(self, language="PL"):
"downloaded_subtitles_lang": language
}

data = urllib.urlencode(values)
# req = urllib2.Request(self.url, data)
try:
# response = urllib2.urlopen(req)
response = urllib.urlopen(self.url, data)
except urllib2.URLError, e:
sys.stderr.write(e.message)
return False
subtitle_list = []

try:
DOMTree = minidom.parseString(response.read())
data = urlencode(values).encode("utf-8")
response = urlopen(self.url, data)

DOMTree = minidom.parseString(response.read())
cNodes = DOMTree.childNodes
if (cNodes[0].getElementsByTagName("status") != []):
self.text = base64.b64decode(
content = base64.b64decode(
cNodes[0].getElementsByTagName("subtitles")[0].getElementsByTagName("content")[0].childNodes[
0].data)
filename = self.filename[:self.filename.rfind(".")] + ".txt"
open(filename, "w").write(self.text)
return filename

except Exception, e:
return False

return False

def getMoreInfo(self):
values = {
"mode": "32770",
# "client":"NapiTux",
"client": "NapiProjektPython",
"client_ver": "0.1",
"downloaded_cover_id": self.md5hash,
"VideoFileInfoID": self.md5hash
}

data = urllib.urlencode(values)
# req = urllib2.Request(self.url, data)
try:
# response = urllib2.urlopen(req)
response = urllib.urlopen(self.url, data)
except urllib2.URLError, e:
sys.stderr.write(e.message)
return False

try:
DOMTree = minidom.parseString(response.read())
cNodes = DOMTree.childNodes[0].getElementsByTagName("movie")

if (cNodes[0].getElementsByTagName("status") != []):
self.info["title"] = cNodes[0].getElementsByTagName("title")[0].childNodes[0].data
self.info["year"] = cNodes[0].getElementsByTagName("year")[0].childNodes[0].data
self.info["country"] = \
cNodes[0].getElementsByTagName("country")[0].getElementsByTagName("pl")[0].childNodes[0].data
if (cNodes[0].getElementsByTagName("genre")[0].getElementsByTagName("pl")[0].childNodes != []):
self.info["genre"] = \
cNodes[0].getElementsByTagName("genre")[0].getElementsByTagName("pl")[0].childNodes[0].data
else:
self.info["genre"] = "Niepodany!"

self.info["filmweb"] = \
cNodes[0].getElementsByTagName("direct_links")[0].getElementsByTagName("filmweb_pl")[0].childNodes[
0].data
self.info["cover"] = StringIO.StringIO(
base64.b64decode(cNodes[0].getElementsByTagName("cover")[0].childNodes[0].data))

cNodes = DOMTree.childNodes[0].getElementsByTagName("file_info")

self.info["size"] = cNodes[0].getElementsByTagName("rozmiar_pliku_z_jednostka")[0].childNodes[0].data
self.info["duration"] = cNodes[0].getElementsByTagName("czas_trwania_sformatowany")[0].childNodes[
0].data
self.info["resolution"] = cNodes[0].getElementsByTagName("rozdz_X")[0].childNodes[0].data + "x" + \
cNodes[0].getElementsByTagName("rozdz_Y")[0].childNodes[0].data
except Exception, e:
sys.stderr.write(e.message)
return False
filename = self.md5hash + ".srt"
filepath = os.path.join(__temp__, filename)
vFile = xbmcvfs.File(filepath, 'w')
vFile.write(content)
vFile.close()
subtitle_list.append(filepath)

except Exception as e:
notify(32001)
log("Exception %s" % e)

return subtitle_list
1 change: 0 additions & 1 deletion resources/lib/__init__.py

This file was deleted.

Loading

0 comments on commit 6596ee7

Please sign in to comment.