Skip to content

Commit

Permalink
release: v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed May 30, 2020
1 parent 34f4418 commit 3e14cc8
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* [v1.6.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-1.6.0):
* Add option to auto download first subtitle result silently

* [v1.5.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-1.5.0):
* Auto open search dialog only on movie and tvshow videos

Expand Down
3 changes: 2 additions & 1 deletion a4kSubtitles/lib/kodi_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
xbmc = lambda: None
xbmc.translatePath = lambda p: p
xbmc.getInfoLabel = lambda t: ''
xbmc.executeJSONRPC = lambda _: '{ "result": { "value": true } }'
xbmc.executeJSONRPC = lambda _: '{ "result": { "value": [] } }'
xbmc.executebuiltin = lambda _: None
xbmc.getCleanMovieTitle = lambda t: t
xbmc.getCondVisibility = lambda _: False
Expand All @@ -27,6 +27,7 @@

__player = lambda: None
__player.getPlayingFile = lambda: ''
__player.setSubtitles = lambda s: None
xbmc.Player = lambda: __player

__monitor = lambda: None
Expand Down
24 changes: 22 additions & 2 deletions a4kSubtitles/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

def start(core):
def start(api):
core = api.core
monitor = core.kodi.xbmc.Monitor()
has_done_subs_check = False

Expand All @@ -26,6 +27,25 @@ def start(core):
has_subtitles_enabled = core.kodi.xbmc.getCondVisibility('VideoPlayer.SubtitlesEnabled')
has_subtitles = core.kodi.xbmc.getCondVisibility('VideoPlayer.HasSubtitles') and has_subtitles_enabled

if not has_subtitles:
if has_subtitles:
continue

if not core.kodi.get_bool_setting('general', 'auto_download'):
core.kodi.xbmc.executebuiltin('ActivateWindow(SubtitleSearch)')
continue

languages = core.kodi.get_kodi_setting('subtitles.languages')
preferredlang = core.kodi.get_kodi_setting('locale.subtitlelanguage')
params = {
'action': 'search',
'languages': ','.join(languages),
'preferredlanguage': preferredlang
}

results = api.search(params)
for result in results:
try:
subfile = api.download(result)
core.kodi.xbmc.Player().setSubtitles(subfile)
break
except: pass
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="1.5.0"
version="1.6.0"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand All @@ -28,6 +28,9 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDB, Subscene, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[v1.6.0]:
* Add option to auto download first subtitle result silently

[v1.5.0]:
* Auto open search dialog only on movie and tvshow videos

Expand Down
4 changes: 1 addition & 3 deletions main_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
from a4kSubtitles import api, service

if __name__ == '__main__':
os.environ.pop(api.api_mode_env_name, '')
core = importlib.import_module('a4kSubtitles.core')
service.start(core)
service.start(api.A4kSubtitlesApi())
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="1.5.0"
version="1.6.0"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand All @@ -31,6 +31,9 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDB, Subscene, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[v1.6.0]:
* Add option to auto download first subtitle result silently

[v1.5.0]:
* Auto open search dialog only on movie and tvshow videos

Expand Down
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
da66c1a421c613825773c5f2066a4366d0d7cb2a
46edf7974229f26ca41fe6ce2e6fdd7378a6fbb0
10 changes: 7 additions & 3 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ msgstr ""

# General
msgctxt "#33101"
msgid "Request Timeout"
msgid "Request timeout"
msgstr ""

msgctxt "#33102"
msgid "Results Limit"
msgid "Results limit"
msgstr ""

msgctxt "#33103"
msgid "Auto Search (Will not trigger if subs are available)"
msgid "Auto search"
msgstr ""

msgctxt "#33104"
msgid "Auto download first subtitle silently"
msgstr ""

# Services
Expand Down
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<setting id="general.timeout" label="33101" type="slider" default="15" option="int" range="5,20"/>
<setting id="general.results_limit" label="33102" type="slider" default="20" option="int" range="10,100"/>
<setting id="general.auto_search" label="33103" type="bool" default="false"/>
<setting id="general.auto_download" label="33104" type="bool" default="false" enable="eq(-1,true)"/>
</category>
<!-- Services -->
<category label="33002">
Expand Down
60 changes: 53 additions & 7 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ def restore():
api.core.kodi.xbmc.getCondVisibility = default
return restore

def __mock_api_search(api):
default = api.search
api.search = lambda p: [{}]
def restore():
api.search = default
return restore

def __mock_api_download(api, result=None):
default = api.download
api.download = lambda p: result
def restore():
api.download = default
return restore

def __mock(api, settings):
restore_monitor = __mock_monitor(api)
restore_settings = api.mock_settings(settings)
Expand All @@ -43,7 +57,7 @@ def test_service_start_when_disabled():
})
get_cond_visibility_spy = utils.spy_fn(a4ksubtitles_api.core.kodi.xbmc, 'getCondVisibility')

service.start(a4ksubtitles_api.core)
service.start(a4ksubtitles_api)

restore()
get_cond_visibility_spy.restore()
Expand All @@ -58,7 +72,7 @@ def test_service_start_when_enabled():
})
get_cond_visibility_spy = utils.spy_fn(a4ksubtitles_api.core.kodi.xbmc, 'getCondVisibility')

service.start(a4ksubtitles_api.core)
service.start(a4ksubtitles_api)

restore()
get_cond_visibility_spy.restore()
Expand All @@ -80,7 +94,7 @@ def test_service_when_video_has_subtitles():

executebuiltin_spy = utils.spy_fn(a4ksubtitles_api.core.kodi.xbmc, 'executebuiltin')

service.start(a4ksubtitles_api.core)
service.start(a4ksubtitles_api)

restore()
restore_get_cond_visibility()
Expand All @@ -103,7 +117,7 @@ def test_service_when_video_does_not_have_subtitles():

executebuiltin_spy = utils.spy_fn(a4ksubtitles_api.core.kodi.xbmc, 'executebuiltin')

service.start(a4ksubtitles_api.core)
service.start(a4ksubtitles_api)

restore()
restore_get_cond_visibility()
Expand All @@ -126,7 +140,7 @@ def test_service_when_video_has_disabled_subtitles():

executebuiltin_spy = utils.spy_fn(a4ksubtitles_api.core.kodi.xbmc, 'executebuiltin')

service.start(a4ksubtitles_api.core)
service.start(a4ksubtitles_api)

restore()
restore_get_cond_visibility()
Expand All @@ -149,7 +163,7 @@ def test_service_when_subs_check_done():

executebuiltin_spy = utils.spy_fn(a4ksubtitles_api.core.kodi.xbmc, 'executebuiltin')

service.start(a4ksubtitles_api.core)
service.start(a4ksubtitles_api)

restore()
restore_get_cond_visibility()
Expand All @@ -172,10 +186,42 @@ def test_service_when_does_not_have_video_duration():

executebuiltin_spy = utils.spy_fn(a4ksubtitles_api.core.kodi.xbmc, 'executebuiltin')

service.start(a4ksubtitles_api.core)
service.start(a4ksubtitles_api)

restore()
restore_get_cond_visibility()
executebuiltin_spy.restore()

assert executebuiltin_spy.call_count == 0

def test_service_auto_download():
a4ksubtitles_api = api.A4kSubtitlesApi({'kodi': True})

restore = __mock(a4ksubtitles_api, {
'general.auto_search': 'true',
'general.auto_download': 'true',
})
restore_get_cond_visibility = __mock_get_cond_visibility(a4ksubtitles_api, {
'VideoPlayer.Content(movies)': True,
'Player.HasDuration': True,
'VideoPlayer.HasSubtitles': False,
'VideoPlayer.SubtitlesEnabled': False,
})
restore_api_search = __mock_api_search(a4ksubtitles_api)
expected_download_result = 'test_download_result'
restore_api_download = __mock_api_download(a4ksubtitles_api, expected_download_result)

executebuiltin_spy = utils.spy_fn(a4ksubtitles_api.core.kodi.xbmc, 'executebuiltin')
setsubtitles_spy = utils.spy_fn(a4ksubtitles_api.core.kodi.xbmc.Player(), 'setSubtitles')

service.start(a4ksubtitles_api)

restore()
restore_get_cond_visibility()
restore_api_search()
restore_api_download()
executebuiltin_spy.restore()

assert executebuiltin_spy.call_count == 0
assert setsubtitles_spy.call_count == 1
setsubtitles_spy.called_with(expected_download_result)

0 comments on commit 3e14cc8

Please sign in to comment.