Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[service.subtitles.opensubtitles-com] 1.0.5 #2639

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion service.subtitles.opensubtitles-com/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
OpenSubtitles.com KODI add-on
=============================
Search and download subtitles for movies and TV-Series from OpenSubtitles.com. Search in 75 languages, 4.000.000+ subtitles, daily updates.
Search and download subtitles for movies and TV-Series from OpenSubtitles.com. Search in 75 languages, 8.000.000+ subtitles, daily updates.

REST API implementation based on tomburke25 [python-opensubtitles-rest-api](https://github.com/tomburke25/python-opensubtitles-rest-api)

v1.0.5 (2024-07-30)
- fixed issue with portuguese file names
- added AI translated filter (thanks Kate6)

v1.0.4 (2024-01-15)
- Sanitize language query
- Improved sorting
Expand Down
8 changes: 6 additions & 2 deletions service.subtitles.opensubtitles-com/addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.subtitles.opensubtitles-com"
name="OpenSubtitles.com"
version="1.0.4"
version="1.0.5"
provider-name="amet, opensubtitles, juokelis, opensubtitlesdev">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
Expand All @@ -11,7 +11,7 @@
library="service.py" />
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">OpenSubtitles.com</summary>
<description lang="en_GB">Search and download subtitles for movies and TV-Series from OpenSubtitles.com. Search in 75 languages, 6.000.000+ subtitles, daily updates. Register/Import your account on OpenSubtitles.com before use.</description>
<description lang="en_GB">Search and download subtitles for movies and TV-Series from OpenSubtitles.com. Search in 75 languages, 8.000.000+ subtitles, daily updates. Register/Import your account on OpenSubtitles.com before use.</description>
<description lang="ast_ES">Pelis and Subtítulos TV en munches llingües, milenta de subtítulos traducíos y xubíos caldía. Descarga llibre dende la fonte, sofitu API, millones d'usuarios.</description>
<description lang="br_FR">Istitloù Filmoù ha TV e meur a yezh, miliadoù a istitloù troet hag uskarget bemdez. Pellgargadenn digoust diouzh ar vammenn, skoazell an API, millionoù a implijerien.</description>
<description lang="ca_ES">Subtítols de films i televisió en múltiples idiomes, milers de subtítols traduïts carregats diàriament. Descàrrega gratuïta des de la font, suport de l'API, amb milions d'usuaris.</description>
Expand Down Expand Up @@ -52,6 +52,10 @@
<description lang="zh_CN">多语种的电影及剧集字幕,每日更新千余条翻译好的字幕。免费下载,提供API接口,已拥有上百万的用户。</description>
<disclaimer lang="en_GB">Users need to provide OpenSubtitles.com username and password in add-on configuration. This is our new extension, old opensubtitles.org will not work on this, but the account can be easily imported on opensubtitles.com.</disclaimer>
<news>
v1.0.5 (2024-07-30)
- fixed issue with portuguese file names
- added AI translated filter (thanks Kate6)

v1.0.4 (2024-01-15)
- Sanitize language query
- Improved sorting
Expand Down
4 changes: 4 additions & 0 deletions service.subtitles.opensubtitles-com/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.0.5 (2024-07-30)
- fixed issue with portuguese file names
- added AI translated filter (thanks Kate6)

v1.0.4 (2024-01-17)
- Sanitize language query
- Improved sorting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ msgstr ""

msgctxt "#32214"
msgid "Bad username. Make sure you have entered your username and not your email in the username field."
msgstr ""

msgctxt "#32215"
msgid "AI Translated"
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ msgstr "Traduction automatique"

msgctxt "#32214"
msgid "Bad username. Make sure you have entered your username and not your email in the username field"
msgstr "Mauvais nom d'utilisateur. Assurez-vous d'avoir saisi votre nom d'utilisateur et non votre adresse email dans le champ du nom d'utilisateur."
msgstr "Mauvais nom d'utilisateur. Assurez-vous d'avoir saisi votre nom d'utilisateur et non votre adresse email dans le champ du nom d'utilisateur."

msgctxt "#32215"
msgid "Traductions AI"
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def get_language_data(params):
"hearing_impaired": __addon__.getSetting("hearing_impaired"),
"foreign_parts_only": __addon__.getSetting("foreign_parts_only"),
"machine_translated": __addon__.getSetting("machine_translated"),
"ai_translated": __addon__.getSetting("ai_translated"),
"languages": search_languages_str}

# for language in search_languages:
Expand All @@ -123,12 +124,19 @@ def get_language_data(params):


def convert_language(language, reverse=False):
# language_list = {
# "English": "en",
# "Portuguese (Brazil)": "pt-br",
# "Portuguese": "pt-pt",
# "Chinese (simplified)": "zh-cn",
# "Chinese (traditional)": "zh-tw"}
language_list = {
"English": "en",
"Portuguese (Brazil)": "pt-br",
"Portuguese": "pt-pt",
"Chinese (simplified)": "zh-cn",
"Chinese (traditional)": "zh-tw"}

reverse_language_list = {v: k for k, v in list(language_list.items())}

if reverse:
Expand All @@ -146,7 +154,9 @@ def convert_language(language, reverse=False):
def get_flag(language_code):
language_list = {
"pt-pt": "pt",
"pt-br": "pb"
"pt-br": "pb",
"zh-cn": "zh",
"zh-tw": "-"
}
return language_list.get(language_code.lower(), language_code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

def get_file_data(file_original_path):
item = {"temp": False, "rar": False, "file_original_path": file_original_path}
log(__name__, f"Processing item: {item}")


if file_original_path.find("http") > -1:
Expand All @@ -30,8 +31,11 @@ def get_file_data(file_original_path):
item["temp"] = True

elif file_original_path.find("rar://") > -1:
# item["rar"] = True
# item["file_original_path"] = os.path.dirname(file_original_path[6:])
item["rar"] = True
item["file_original_path"] = os.path.dirname(file_original_path[6:])
item["basename"] = os.path.basename(file_original_path)

elif file_original_path.find("stack://") > -1:
stack_path = file_original_path.split(" , ")
Expand All @@ -46,6 +50,8 @@ def get_file_data(file_original_path):


def hash_file(file_path, rar):
log(__name__, f"Processing file: {file_path} - Is RAR: {rar}")

if rar:
return hash_rar(file_path)

Expand Down Expand Up @@ -73,8 +79,43 @@ def hash_file(file_path, rar):
return_hash = "%016x" % hash_
return file_size, return_hash


def hash_rar(first_rar_file):
log(__name__, "Hash Rar file")
f = xbmcvfs.File(first_rar_file)
a = f.readBytes(4)
log(__name__, "Hash Rar a: %s" % a)
# Ensure comparison is done with a byte string
if a != b"Rar!":
raise Exception("ERROR: This is not rar file.")

seek = 0
for i in range(4):
f.seek(max(0, seek), 0)
a = f.readBytes(100)
type_, flag, size = struct.unpack("<BHH", a[2:2 + 5])

if 0x74 == type_:
if 0x30 != struct.unpack("<B", a[25:25 + 1])[0]:
raise Exception("Bad compression method! Work only for 'store'.")

s_divide_body_start = seek + size
s_divide_body, s_unpack_size = struct.unpack("<II", a[7:7 + 2 * 4])

if flag & 0x0100:
s_unpack_size = (struct.unpack("<I", a[36:36 + 4])[0] << 32) + s_unpack_size
log(__name__, "Hash untested for files bigger that 2gb. May work or may generate bad hash.")

last_rar_file = get_last_split(first_rar_file, (s_unpack_size - 1) / s_divide_body)
hash_ = add_file_hash(first_rar_file, s_unpack_size, s_divide_body_start)
hash_ = add_file_hash(last_rar_file, hash_, (s_unpack_size % s_divide_body) + s_divide_body_start - 65536)
f.close()
return s_unpack_size, "%016x" % hash_

seek += size

raise Exception("ERROR: Not Body part in rar file.")

def hash_rar_orig(first_rar_file):
log(__name__, "Hash Rar file")
f = xbmcvfs.File(first_rar_file)
a = f.readBytes(4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class OpenSubtitlesSubtitlesRequest(OpenSubtitlesRequest):
def __init__(self, id_: int = None, imdb_id: int = None, tmdb_id: int = None, type_="all", query="", languages="",
moviehash="", user_id: int = None, hearing_impaired="include", foreign_parts_only="include",
trusted_sources="include", machine_translated="exclude", ai_translated="exclude", order_by="",
trusted_sources="include", machine_translated="exclude", ai_translated="include", order_by="",
order_direction="", parent_feature_id: int = None, parent_imdb_id: int = None,
parent_tmdb_id: int = None, season_number: int = None, episode_number: int = None, year: int = None,
moviehash_match="include", page: int = None, **catch_overflow):
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, id_: int = None, imdb_id: int = None, tmdb_id: int = None, ty
super().__init__()

# ordered request params with defaults
self.DEFAULT_LIST = dict(ai_translated="exclude", episode_number=None, foreign_parts_only="include",
self.DEFAULT_LIST = dict(ai_translated="include", episode_number=None, foreign_parts_only="include",
hearing_impaired="include", id=None, imdb_id=None, languages="",
machine_translated="exclude", moviehash="", moviehash_match="include", order_by="",
order_direction="desc", page=None, parent_feature_id=None, parent_imdb_id=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, api_key, username, password):
logging(f"Username: {self.username}, Password: {self.password}")


self.request_headers = {"Api-Key": self.api_key, "User-Agent": "Opensubtitles.com Kodi plugin v1.0.4" ,"Content-Type": CONTENT_TYPE, "Accept": CONTENT_TYPE}
self.request_headers = {"Api-Key": self.api_key, "User-Agent": "Opensubtitles.com Kodi plugin v1.0.5" ,"Content-Type": CONTENT_TYPE, "Accept": CONTENT_TYPE}

self.session = Session()
self.session.headers = self.request_headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import os
import shutil
import sys
import uuid
import xbmc



import xbmcaddon
import xbmcgui
Expand Down Expand Up @@ -114,8 +116,29 @@ def download(self):
error(__name__, 32001, e)
valid = 0

subtitle_path = os.path.join(__temp__, f"{str(uuid.uuid4())}.{self.sub_format}")

#subtitle_path = os.path.join(__temp__, f"{str(uuid.uuid4())}.{self.sub_format}")
try: # kodi > k19
dir_path = xbmcvfs.translatePath('special://temp/oss')
except: # kodi < k19
dir_path = xbmc.translatePath('special://temp/oss')

# Kodi lang-code difference vs OS.com API langcodes return
if self.params["language"].lower() == 'pt-pt': self.params["language"] = 'pt'
elif self.params["language"].lower() == 'pt-pb': self.params["language"] = 'pb'

if xbmcvfs.exists(dir_path): # lets clean files from last usage
dirs, files = xbmcvfs.listdir(dir_path)
for file in files:
xbmcvfs.delete(os.path.join(dir_path, file))

if not xbmcvfs.exists(dir_path): # lets create custom OSS sub directory if not exists
xbmcvfs.mkdir(dir_path)

subtitle_path = os.path.join(dir_path, "{0}.{1}.{2}".format('TempSubtitle', self.params["language"], self.sub_format))

log(__name__, "XYXYXX download subtitle_path: {}".format(subtitle_path))


if (valid==1):
tmp_file = open(subtitle_path, "w" + "b")
tmp_file.write(self.file["content"])
Expand Down Expand Up @@ -151,10 +174,19 @@ def list_subtitles(self):
list_item.setArt({
"icon": str(int(round(float(attributes["ratings"]) / 2))),
"thumb": get_flag(attributes["language"])})
# list_item.setArt({
# "icon": str(int(round(float(attributes["ratings"]) / 2))),
# "thumb": get_flag(language)})

log(__name__, "XYXYXX download get_flag: language in url {}".format(get_flag(attributes["language"])))


list_item.setProperty("sync", "true" if ("moviehash_match" in attributes and attributes["moviehash_match"]) else "false")
list_item.setProperty("hearing_imp", "true" if attributes["hearing_impaired"] else "false")
"""TODO take care of multiple cds id&id or something"""
url = f"plugin://{__scriptid__}/?action=download&id={attributes['files'][0]['file_id']}"
#url = f"plugin://{__scriptid__}/?action=download&id={attributes['files'][0]['file_id']}"
url = f"plugin://{__scriptid__}/?action=download&id={attributes['files'][0]['file_id']}&language={language}"
log(__name__, "XYXYXX download list_subtitles: language in url {url}")

xbmcplugin.addDirectoryItem(handle=self.handle, url=url, listitem=list_item, isFolder=False)
xbmcplugin.endOfDirectory(self.handle)
14 changes: 14 additions & 0 deletions service.subtitles.opensubtitles-com/resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@
<heading>32213</heading>
</control>
</setting>
<setting id="ai_translated" type="string" label="32215">
<level>0</level>
<default>include</default>
<constraints>
<options>
<option label="include">include</option>
<option label="exclude">exclude</option>
<option label="only">only</option>
</options>
</constraints>
<control type="list" format="string">
<heading>32215</heading>
</control>
</setting>
</group>
</category>
</section>
Expand Down
Loading