Skip to content

Commit

Permalink
release: v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed May 19, 2020
1 parent dbbc850 commit 57e89af
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
if: "!startsWith(needs.validate.outputs.commit, 'chore:')"
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt --user
python -m pip install -r requirements.txt
- name: lint
if: "!startsWith(needs.validate.outputs.commit, 'chore:')"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* [v1.0.0](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-1.0.0):
* Invalidate BSPlayer results cache when download links expire
* Extraction fallback: zip -> gzip -> raw

* [v0.0.30](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.30):
* Add service names in ad detection
* Removed the option to disable cleaning of ads
Expand Down
2 changes: 1 addition & 1 deletion a4kSubtitles/data/addic7ed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __download_data(url, etag, destpath):
'headers': {
'If-None-Match': etag
}
})
}, progress=False)
if response.status_code != 200:
return

Expand Down
17 changes: 11 additions & 6 deletions a4kSubtitles/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ def __extract_zip(core, archivepath, filename, episodeid):
sub_exts = ['.srt', '.sub']
sub_exts_secondary = ['.smi', '.ssa', '.aqt', '.jss', '.ass', '.rt', '.txt']

archivepath = core.utils.quote_plus(archivepath)
subfile = core.utils.find_file_in_archive(core, archivepath, sub_exts, episodeid)
archivepath_ = core.utils.quote_plus(archivepath)
subfile = core.utils.find_file_in_archive(core, archivepath_, sub_exts, episodeid)
if not subfile:
subfile = core.utils.find_file_in_archive(core, archivepath, sub_exts_secondary, episodeid)
if not subfile:
subfile = filename
subfile = core.utils.find_file_in_archive(core, archivepath_, sub_exts_secondary, episodeid)

src = 'archive://' + archivepath + '/' + subfile
dest = core.os.path.join(core.utils.temp_dir, filename)
if not subfile:
try:
return __extract_gzip(core, archivepath, filename)
except:
core.os.rename(archivepath, dest)
return dest

src = 'archive://' + archivepath_ + '/' + subfile
core.kodi.xbmcvfs.copy(src, dest)
return dest

Expand Down
4 changes: 2 additions & 2 deletions a4kSubtitles/lib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def execute(core, request):
def execute(core, request, progress=True):
try: default_timeout = get_int_setting('general.timeout')
except: default_timeout = 10
request.setdefault('timeout', default_timeout)

if core.progress_dialog and not core.progress_dialog.dialog:
if progress and core.progress_dialog and not core.progress_dialog.dialog:
core.progress_dialog.open()

validate = request.pop('validate', None)
Expand Down
37 changes: 26 additions & 11 deletions a4kSubtitles/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,46 @@ def __add_results(core, results): # pragma: no cover
% (core.kodi.addon_id, item['service_name'], action_args)
)

def __has_results(service_name, results):
return any(map(lambda r: r['service_name'] == service_name, results))

def __save_results(core, meta, results):
try:
if len(results) == 0:
return
meta_hash = core.cache.get_meta_hash(meta)
json_data = core.json.dumps({'hash': meta_hash, 'results': results}, indent=2)
json_data = core.json.dumps({
'hash': meta_hash,
'timestamp': core.time.time(),
'results': results
}, indent=2)
with open(core.cache.results_filepath, 'w') as f:
f.write(json_data)
except:
import traceback
traceback.print_exc()

def __get_last_results(core, meta):
force_search = []

try:
with open(core.cache.results_filepath, 'r') as f:
last_results = core.json.loads(f.read())

meta_hash = core.cache.get_meta_hash(meta)
if last_results['hash'] == meta_hash:
return last_results['results']
if last_results['hash'] != meta_hash:
return ([], [])

has_bsplayer_results = __has_results('bsplayer', last_results['results'])
has_bsplayer_results_expired = core.time.time() - last_results['timestamp'] > 3 * 60
if has_bsplayer_results and has_bsplayer_results_expired:
last_results['results'] = list(filter(lambda r: r['service_name'] != 'bsplayer', last_results['results']))
force_search.append('bsplayer')

return (last_results['results'], force_search)
except: pass

return []
return ([], [])

def __sanitize_results(core, meta, results):
temp_dict = {}
Expand Down Expand Up @@ -169,14 +186,12 @@ def search(core, params):
core.kodi.notification('IMDB ID is not provided')
return

last_query_results = __get_last_results(core, meta)
if len(last_query_results) > 0:
core.logger.notice('using cached results')
return __complete_search(core, last_query_results)

threads = []
results = []
(results, force_search) = __get_last_results(core, meta)
for service_name in core.services:
if len(results) > 0 and (__has_results(service_name, results) or service_name not in force_search):
continue

if not core.kodi.get_bool_setting(service_name, 'enabled'):
continue

Expand All @@ -193,7 +208,7 @@ def search(core, params):
threads.append((auth_thread, search_thread))

if len(threads) == 0:
return __complete_search(core, last_query_results)
return __complete_search(core, results)

core.progress_text = core.progress_text[:-1]
core.kodi.update_progress(core)
Expand Down
6 changes: 5 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.30"
version="1.0.0"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand All @@ -24,6 +24,10 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDB, Subscene, Addic7ed
<icon>icon.png</icon>
</assets>
<news>
[v1.0.0]:
* Invalidate BSPlayer results cache when download links expire
* Extraction fallback: zip -> gzip -> raw

[v0.0.30]:
* Add service names in ad detection
* Removed the option to disable cleaning of ads
Expand Down
6 changes: 5 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.30"
version="1.0.0"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand All @@ -27,6 +27,10 @@ Supports: OpenSubtitles, BSPlayer, Podnadpisi.NET, SubDB, Subscene, Addic7ed
<icon>icon.png</icon>
</assets>
<news>
[v1.0.0]:
* Invalidate BSPlayer results cache when download links expire
* Extraction fallback: zip -> gzip -> raw

[v0.0.30]:
* Add service names in ad detection
* Removed the option to disable cleaning of ads
Expand Down
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0d19fefdccc6fb52065e1e73d2ff156d4ce22c60
70056256360e744c75b6e7890f10f706a0757b17

0 comments on commit 57e89af

Please sign in to comment.