Skip to content

Commit

Permalink
release: v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed Jan 15, 2021
1 parent eefc0c4 commit 78ea465
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* [v2.2.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-2.2.0):
* Fix KODI 19 Matrix support

* [v2.1.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-2.1.0):
* Fix Persian search in Subscene

Expand Down
2 changes: 1 addition & 1 deletion a4kSubtitles/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ def download(core, params):
if core.api_mode_enabled:
return filepath

listitem = core.kodi.xbmcgui.ListItem(label=filepath)
listitem = core.kodi.xbmcgui.ListItem(label=filepath, offscreen=True)
core.kodi.xbmcplugin.addDirectoryItem(handle=core.handle, url=filepath, listitem=listitem, isFolder=False)
4 changes: 2 additions & 2 deletions a4kSubtitles/lib/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def __get_cache(filepath):
try:
with open(filepath, 'r') as f:
with utils.open_file_wrapper(filepath)() as f:
data = json.loads(f.read())
return utils.DictAsObject(data)
except:
Expand All @@ -22,7 +22,7 @@ def __get_cache(filepath):
def __save_cache(filepath, cache):
try:
json_data = json.dumps(cache, indent=2)
with open(filepath, 'w') as f:
with utils.open_file_wrapper(filepath, mode='w')() as f:
f.write(json_data)
except: pass

Expand Down
12 changes: 9 additions & 3 deletions a4kSubtitles/lib/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
addon_name = addon.getAddonInfo('name')
addon_version = addon.getAddonInfo('version')
addon_icon = addon.getAddonInfo('icon')
addon_profile = xbmc.translatePath(addon.getAddonInfo('profile'))
try:
addon_profile = xbmcvfs.translatePath(addon.getAddonInfo('profile'))
except:
addon_profile = xbmc.translatePath(addon.getAddonInfo('profile'))

def json_rpc(method, params, log_error=True): # pragma: no cover
try:
Expand Down Expand Up @@ -133,11 +136,14 @@ def create_listitem(item): # pragma: no cover
args = {
'label': item['lang'],
'label2': '%s ([B]%s[/B]) ([B][COLOR %s]%s[/COLOR][/B])' % (item_name, item_ext, item_color, item_service),
'iconImage': str(item['rating']),
'thumbnailImage': item['lang_code'],
'offscreen': True,
}

listitem = xbmcgui.ListItem(**args)
listitem.setArt({
'icon': str(item['rating']),
'thumb': item['lang_code'],
})
listitem.setProperty('sync', item['sync'])
listitem.setProperty('hearing_imp', item['impaired'])

Expand Down
7 changes: 6 additions & 1 deletion a4kSubtitles/lib/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ def __log(message, level=xbmc.LOGDEBUG):

xbmc.log('{0}: {1}'.format(addon_id, message), level)

try:
notice_type = xbmc.LOGNOTICE
except:
notice_type = xbmc.LOGINFO

def notice(message):
__log(message, xbmc.LOGNOTICE)
__log(message, notice_type)

def error(message):
__log(message, xbmc.LOGERROR)
Expand Down
7 changes: 6 additions & 1 deletion a4kSubtitles/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,18 @@ def cleanup_subtitles(core, sub_contents):

return '\n'.join(cleaned_lines)

def open_file_wrapper(file, mode='r', encoding='utf-8'):
if py2:
return lambda: open(file, mode)
return lambda: open(file, mode, encoding=encoding)

def get_json(path, filename):
path = path if os.path.isdir(path) else os.path.dirname(path)
if not filename.endswith('.json'):
filename += '.json'

json_path = os.path.join(path, filename)
with open(json_path) as json_result:
with open_file_wrapper(json_path)() as json_result:
return json.load(json_result)

def find_file_in_archive(core, namelist, exts, part_of_filename=''):
Expand Down
10 changes: 8 additions & 2 deletions a4kSubtitles/lib/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
__byte_size = struct.calcsize(__longlong_format_char)

def __sum_64k_bytes(file, result):
for _ in range(__64k / __byte_size):
chunk = file.read(__byte_size)
range_value = __64k / __byte_size
if utils.py3:
range_value = round(range_value)

for _ in range(range_value):
try: chunk = file.readBytes(__byte_size)
except: chunk = file.read(__byte_size)
(value,) = struct.unpack(__longlong_format_char, chunk)
result.filehash += value
result.filehash &= 0xFFFFFFFFFFFFFFFF
Expand Down Expand Up @@ -48,6 +53,7 @@ def __set_size_and_hash(core, meta, filepath):
__sum_64k_bytes(f, result)

meta.filehash = "%016x" % result.filehash
logger.notice(meta.filehash)
finally:
f.close()

Expand Down
5 changes: 4 additions & 1 deletion 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.a4ksubtitles"
name="a4kSubtitles"
version="2.1.0"
version="2.2.0"
provider-name="Unknown">
<requires>
<import addon="script.module.requests"/>
Expand All @@ -27,6 +27,9 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, Subscene, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[v2.2.0]:
* Fix KODI 19 Matrix support

[v2.1.0]:
* Fix Persian search in Subscene

Expand Down
5 changes: 4 additions & 1 deletion packages/addons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<addons>
<addon id="service.subtitles.a4ksubtitles"
name="a4kSubtitles"
version="2.1.0"
version="2.2.0"
provider-name="Unknown">
<requires>
<import addon="script.module.requests"/>
Expand All @@ -30,6 +30,9 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, Subscene, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[v2.2.0]:
* Fix KODI 19 Matrix support

[v2.1.0]:
* Fix Persian search in Subscene

Expand Down
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7c5a8672adc3cb80d72461335233f142c762fb24
76debceb64549a9e810cd1110ff064bbfd26a338
6 changes: 5 additions & 1 deletion tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
re,
time,
api,
utils
utils,
pytest,
)

__movie_video_meta = {
Expand Down Expand Up @@ -471,6 +472,7 @@ def test_podnadpisi_tvshow():

assert filepath != ''

@pytest.mark.skip(reason="cf bypass needed")
def test_subscene():
a4ksubtitles_api = api.A4kSubtitlesApi({'kodi': True})
__remove_all_cache(a4ksubtitles_api)
Expand All @@ -497,6 +499,7 @@ def test_subscene():

assert filepath != ''

@pytest.mark.skip(reason="cf bypass needed")
def test_subscene_tvshow():
a4ksubtitles_api = api.A4kSubtitlesApi({'kodi': True})
__remove_all_cache(a4ksubtitles_api)
Expand Down Expand Up @@ -527,6 +530,7 @@ def test_subscene_tvshow():

assert filepath != ''

@pytest.mark.skip(reason="cf bypass needed")
def test_subscene_tvshow_persian():
a4ksubtitles_api = api.A4kSubtitlesApi({'kodi': True})
__remove_all_cache(a4ksubtitles_api)
Expand Down

0 comments on commit 78ea465

Please sign in to comment.