Skip to content

Commit

Permalink
release: v0.0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed May 6, 2020
1 parent b83a126 commit 55a96d7
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 18 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[run]
omit =
a4kSubtitles/lib/num2ordinal.py

[report]
exclude_lines =
pragma: no cover
if PY2
if core\.utils\.PY2
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* [v0.0.22](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.22):
* Fix meta string conversion issue

* [v0.0.21](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.21):
* TVShow year scrape from imdb when necessary

Expand Down
2 changes: 1 addition & 1 deletion a4kSubtitles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
api_mode_enabled = True
handle = None

def main(handle, paramstring):
def main(handle, paramstring): # pragma: no cover
core.api_mode_enabled = False
core.handle = handle

Expand Down
4 changes: 2 additions & 2 deletions a4kSubtitles/lib/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
mod = importlib.import_module(target)
setattr(kodi, target, mod)

else:
else: # pragma: no cover
import xbmc
import xbmcaddon
import xbmcplugin
Expand Down Expand Up @@ -60,7 +60,7 @@ def json_rpc(method, params, log_error=True):
def get_kodi_setting(setting, log_error=True):
return json_rpc('Settings.GetSettingValue', {"setting": setting}, log_error)

def create_listitem(item):
def create_listitem(item): # pragma: no cover
if item['lang'] == 'Brazilian':
item['lang'] = 'Portuguese (Brazil)'

Expand Down
2 changes: 1 addition & 1 deletion a4kSubtitles/lib/kodi_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from zipfile import ZipFile
from xml.etree import ElementTree

try:
try: # pragma: no cover
from urlparse import unquote
except ImportError:
from urllib.parse import unquote
Expand Down
8 changes: 6 additions & 2 deletions a4kSubtitles/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
from . import kodi
from . import logger

try:
try: # pragma: no cover
from urlparse import unquote, parse_qsl
from urllib import quote_plus
from StringIO import StringIO
except ImportError:
from urllib.parse import quote_plus, unquote, parse_qsl
from io import StringIO
unicode = None

__url_regex = r'(([a-z0-9][a-z0-9-]{1,5}[a-z0-9]\.[a-z0-9]{2,20})|(opensubtitles))\.[a-z]{2,5}'
__credit_part_regex = r'(sync|synced|fix|fixed|corrected|corrections)'
Expand All @@ -39,7 +40,10 @@ def get_all_relative_py_files(file):
return [filename[:-3] for filename in files if not filename.startswith('__') and filename.endswith('.py')]

def strip_non_ascii_and_unprintable(text):
if isinstance(text, int):
if not isinstance(text, str):
return str(text)

if PY2 and not isinstance(text, unicode):
return str(text)

result = ''.join(char for char in text if char in string.printable)
Expand Down
21 changes: 12 additions & 9 deletions a4kSubtitles/services/bsplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'Connection': 'close',
}

__subdomains = [1, 2, 4, 5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109]
__subdomains = [1, 2, 3, 4, 5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109]

def __get_url(core, service_name):
context = core.services[service_name].context
Expand All @@ -29,17 +29,13 @@ def __get_url(core, service_name):

return "http://s%s.api.bsplayer-subtitles.com/v1.php" % context.subdomain

def __validate_response(core, service_name, request, response):
context = core.services[service_name].context
if not context.tries:
context.tries = 1
else:
context.tries += 1
def __validate_response(core, service_name, request, response, retry=True):
if not retry:
return None

def get_retry_request():
core.time.sleep(2)
if context.tries <= 2:
request['validate'] = lambda response: __validate_response(core, service_name, request, response)
request['validate'] = lambda response: __validate_response(core, service_name, request, response, retry=False)
return request

if response is None:
Expand All @@ -59,6 +55,13 @@ def get_retry_request():
if status_code.text != '200' and status_code.text != '402':
return get_retry_request()

results = response.findall('data/item')
if not results:
return get_retry_request()

if len(results) == 0:
return get_retry_request()

return None

def __get_request(core, service_name, action, params):
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="0.0.21"
version="0.0.22"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand All @@ -24,6 +24,9 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDB, Subscene
<icon>icon.png</icon>
</assets>
<news>
[v0.0.22]:
* Fix meta string conversion issue

[v0.0.21]:
* TVShow year scrape from imdb when necessary

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="0.0.21"
version="0.0.22"
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
<icon>icon.png</icon>
</assets>
<news>
[v0.0.22]:
* Fix meta string conversion issue

[v0.0.21]:
* TVShow year scrape from imdb when necessary

Expand Down
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cb2c5a3c7846568f15ffc86dd3a3cc20dab27c70
0a73ff2defcf5aff6f157ed75e759508a1e24dce

0 comments on commit 55a96d7

Please sign in to comment.