Skip to content

Commit

Permalink
release: v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed May 27, 2020
1 parent e5cfc24 commit bb1be1b
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* [v1.3.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-1.3.0):
* Improve tvshow year scraping

* [v1.2.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-1.2.0):
* Use internal ZipFile for extraction with a fallback to vfs.libarchive

Expand Down
5 changes: 5 additions & 0 deletions a4kSubtitles/lib/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def __scrape_tvshow_year(core, meta):
return

show_year_match = re.search(r' %s \((.*?)\)"' % meta.tvshow, imdb_response.text)
if not show_year_match:
show_year_match = re.search(r'<title>.*?\(TV (?:Mini-)?Series (\d\d\d\d).*?</title>', imdb_response.text)
if not show_year_match:
show_year_match = re.search(r'<span class="parentDate">\((\d\d\d\d).*?\)</span>', imdb_response.text)

if show_year_match:
meta.tvshow_year = show_year_match.group(1).strip()

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="1.2.0"
version="1.3.0"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand All @@ -27,6 +27,9 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDB, Subscene, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[v1.3.0]:
* Improve tvshow year scraping

[v1.2.0]:
* Use internal ZipFile for extraction with a fallback to vfs.libarchive

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="1.2.0"
version="1.3.0"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand All @@ -30,6 +30,9 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDB, Subscene, Addic7ed
<screenshot>screenshot-03.png</screenshot>
</assets>
<news>
[v1.3.0]:
* Improve tvshow year scraping

[v1.2.0]:
* Use internal ZipFile for extraction with a fallback to vfs.libarchive

Expand Down
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d114c77b06cd3bc4c8e557687867387d148363d4
61ee54c24b8a4b1ee015abe153168a80843b7fc8
91 changes: 91 additions & 0 deletions tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"filehash": "d603a5b0e73d4b6b",
"subdb_hash": "2aec1b70afe702e67ab39a0af776ba5a",
}
__tvshow_expected_year = '2016'

__tvshow_unicode_video_meta = {
"year": "2019",
Expand All @@ -58,6 +59,28 @@
"subdb_hash": "b35c5f8e4afffd8ee09442e98f943410",
}

__tvshow_with_show_imdb_id_video_meta = __tvshow_video_meta.copy()
__tvshow_with_show_imdb_id_video_meta['imdb_id'] = 'tt0475784'
__tvshow_with_show_imdb_id_expected_year = '2016'

__tvshow_alt_title_video_meta = {
"year": "2016",
"title": "Episode 1",
"tvshow": "Midnight Diner: Tokyo Stories",
"imdb_id": "tt6190484",
"season": "1",
"episode": "1",
"filename": "Midnight.Diner.Tokyo.Stories.S01E01.1080p.NF.WEB-DL.DDP2.0.x264-Monkee.mkv",
"filesize": "808387637",
"filehash": "b3b923134834beee",
"subdb_hash": "8e2970e553d0b7b662b29b24ecbf1a10",
}
__tvshow_alt_title_expected_year = '2016'

__tvshow_with_show_imdb_id_alt_title_video_meta = __tvshow_alt_title_video_meta.copy()
__tvshow_with_show_imdb_id_alt_title_video_meta['imdb_id'] = 'tt6150576'
__tvshow_with_show_imdb_id_alt_title_expected_year = '2016'

def __remove_meta_cache(a4ksubtitles_api):
try:
os.remove(a4ksubtitles_api.core.cache.__meta_cache_filepath)
Expand Down Expand Up @@ -122,11 +145,26 @@ def __search_tvshow(a4ksubtitles_api, settings={}, video_meta={}):
tvshow_video_meta.update(video_meta)
return __search(a4ksubtitles_api, settings, tvshow_video_meta)

def __search_tvshow_alt_title(a4ksubtitles_api, settings={}, video_meta={}):
tvshow_video_meta = __tvshow_alt_title_video_meta.copy()
tvshow_video_meta.update(video_meta)
return __search(a4ksubtitles_api, settings, tvshow_video_meta)

def __search_unicode_tvshow(a4ksubtitles_api, settings={}, video_meta={}):
tvshow_video_meta = __tvshow_unicode_video_meta.copy()
tvshow_video_meta.update(video_meta)
return __search(a4ksubtitles_api, settings, tvshow_video_meta)

def __search_tvshow_with_show_imdb_id(a4ksubtitles_api, settings={}, video_meta={}):
tvshow_video_meta = __tvshow_with_show_imdb_id_video_meta.copy()
tvshow_video_meta.update(video_meta)
return __search(a4ksubtitles_api, settings, tvshow_video_meta)

def __search_tvshow_with_show_imdb_id_alt_title(a4ksubtitles_api, settings={}, video_meta={}):
tvshow_video_meta = __tvshow_with_show_imdb_id_alt_title_video_meta.copy()
tvshow_video_meta.update(video_meta)
return __search(a4ksubtitles_api, settings, tvshow_video_meta)

def test_api():
def get_error_msg(e):
return str(e.value).replace('\'', '')
Expand Down Expand Up @@ -166,8 +204,61 @@ def test_search_missing_imdb_id():
}
a4ksubtitles_api.search(params)

log_error_spy.restore()
log_error_spy.called_with('missing imdb id!')

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

get_meta_spy = utils.spy_fn(a4ksubtitles_api.core.video, 'get_meta', return_result=False)

try: __search_tvshow(a4ksubtitles_api, {'podnadpisi.enabled': 'true'})
except: pass

get_meta_spy.restore()
get_meta_spy.result[0].tvshow_year_thread.join()
assert get_meta_spy.result[0].tvshow_year == __tvshow_expected_year

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

get_meta_spy = utils.spy_fn(a4ksubtitles_api.core.video, 'get_meta', return_result=False)

try: __search_tvshow_alt_title(a4ksubtitles_api, {'podnadpisi.enabled': 'true'})
except: pass

get_meta_spy.restore()
get_meta_spy.result[0].tvshow_year_thread.join()
assert get_meta_spy.result[0].tvshow_year == __tvshow_alt_title_expected_year

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

get_meta_spy = utils.spy_fn(a4ksubtitles_api.core.video, 'get_meta', return_result=False)

try: __search_tvshow_with_show_imdb_id(a4ksubtitles_api, {'podnadpisi.enabled': 'true'})
except: pass

get_meta_spy.restore()
get_meta_spy.result[0].tvshow_year_thread.join()
assert get_meta_spy.result[0].tvshow_year == __tvshow_with_show_imdb_id_expected_year

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

get_meta_spy = utils.spy_fn(a4ksubtitles_api.core.video, 'get_meta', return_result=False)

try: __search_tvshow_with_show_imdb_id_alt_title(a4ksubtitles_api, {'podnadpisi.enabled': 'true'})
except: pass

get_meta_spy.restore()
get_meta_spy.result[0].tvshow_year_thread.join()
assert get_meta_spy.result[0].tvshow_year == __tvshow_with_show_imdb_id_alt_title_expected_year

def test_opensubtitles():
a4ksubtitles_api = api.A4kSubtitlesApi({'kodi': True})
__remove_all_cache(a4ksubtitles_api)
Expand Down
8 changes: 6 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ def called_with(self, *args, **kwargs):
assert self.args[0] == args
assert self.kwargs[0] == kwargs

def spy_fn(target, fn_name):
def spy_fn(target, fn_name, return_result=True):
spy = Spy()
fn = getattr(target, fn_name)

def fn_wrap(*args, **kwargs):
spy.args.append(args)
spy.kwargs.append(kwargs)
spy.result.append(fn(*args, **kwargs))
result = fn(*args, **kwargs)
spy.result.append(result)
spy.call_count += 1

if return_result:
return result

setattr(target, fn_name, fn_wrap)
spy.restore = lambda: setattr(target, fn_name, fn)

Expand Down

0 comments on commit bb1be1b

Please sign in to comment.