Skip to content

Commit

Permalink
release: v0.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed Apr 24, 2020
1 parent a7dc9a7 commit a4743bd
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* [v0.0.12](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.12):
* Removal of ads (Experimental)
* Fix extract issue when file contains unicode symbols

* [v0.0.11](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.11):
* Changelog in KODI

Expand Down
23 changes: 18 additions & 5 deletions a4kSubtitles/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,40 @@ def __download(core, filepath, request):
with open(filepath, 'wb') as f:
core.shutil.copyfileobj(r.raw, f)

def __extract(core, archivepath, filename, language):
def __extract(core, archivepath, filename, lang):
path = core.utils.quote_plus(archivepath)
ext = core.os.path.splitext(filename)[1].lower()
(dirs, files) = core.kodi.xbmcvfs.listdir('archive://%s' % path)

subfile = filename
for file in files:
if core.utils.PY2:
file = file.decode('utf8')
if file.lower().endswith(ext):
subfile = file
break

src = 'archive://' + path + '/' + subfile
subfile = __insert_language_code_in_filename(core, filename, language)
subfile = __insert_lang_code_in_filename(core, filename, lang)
dest = core.os.path.join(core.utils.temp_dir, subfile)
core.kodi.xbmcvfs.copy(src, dest)
return dest

def __insert_language_code_in_filename(core, filename, language_name):
def __insert_lang_code_in_filename(core, filename, lang):
filename_chunks = filename.split('.')
lang_code = core.kodi.xbmc.convertLanguage(language_name,
core.kodi.xbmc.ISO_639_1)
lang_code = core.kodi.xbmc.convertLanguage(lang, core.kodi.xbmc.ISO_639_1)
filename_chunks.insert(-1, lang_code)
return '.'.join(filename_chunks)

def __cleanup(core, filepath):
with open(filepath, 'r') as f:
sub_contents = f.read()

sub_contents = core.utils.cleanup_subtitles(sub_contents)

with open(filepath, 'w') as f:
f.write(sub_contents)

def download(core, params):
core.logger.debug(lambda: core.json.dumps(params, indent=2))

Expand All @@ -48,6 +58,9 @@ def download(core, params):
__download(core, archivepath, request)
filepath = __extract(core, archivepath, filename, language)

if core.kodi.get_bool_setting('general.remove_ads'):
__cleanup(core, filepath)

if core.api_mode_enabled:
return filepath
listitem = core.kodi.xbmcgui.ListItem(label=filepath)
Expand Down
46 changes: 46 additions & 0 deletions a4kSubtitles/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,64 @@

import os
import sys
import re
from .kodi import addon_profile
from . import logger

try:
from urlparse import unquote, parse_qsl
from urllib import quote_plus
except ImportError:
from urllib.parse import quote_plus, unquote, parse_qsl

__url_regex = r'(([a-zA-Z0-9][a-zA-Z0-9-]{1,5}[a-zA-Z0-9]\.[a-zA-Z]{2,20})|(opensubtitles))\.[a-zA-Z]{2,5}'

PY2 = sys.version_info[0] == 2
PY3 = not PY2

temp_dir = os.path.join(addon_profile, 'temp')

def get_all_relative_py_files(file):
files = os.listdir(os.path.dirname(file))
return [filename[:-3] for filename in files if not filename.startswith('__') and filename.endswith('.py')]

def cleanup_subtitles(sub_contents):
all_lines = sub_contents.split('\n')
cleaned_lines = []
buffer = []
garbage = False

if all_lines[0].strip() != '':
all_lines.insert(0, '')

if all_lines[-1].strip() != '':
all_lines.append('')

for line in all_lines:
line = line.strip()

if garbage and line != '':
continue

garbage = False

if line == '':
if len(buffer) > 0:
buffer.insert(0, '')
cleaned_lines.extend(buffer)
buffer = []
continue

if re.search(__url_regex, line, re.IGNORECASE):
logger.notice('(detected ad) %s' % line)
if not re.match(r'^\{\d+\}\{\d+\}', line):
garbage = True
buffer = []
continue

buffer.append(line)

if cleaned_lines[0] == '':
cleaned_lines.pop(0)

return '\n'.join(cleaned_lines)
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.11"
version="0.0.12"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand All @@ -24,6 +24,10 @@ Supports: OpenSubtitles
<icon>icon.png</icon>
</assets>
<news>
[v0.0.12]:
* Removal of ads (Experimental)
* Fix extract issue when file contains unicode symbols

[v0.0.11]:
* Changelog in KODI

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.11"
version="0.0.12"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand All @@ -27,6 +27,10 @@ Supports: OpenSubtitles
<icon>icon.png</icon>
</assets>
<news>
[v0.0.12]:
* Removal of ads (Experimental)
* Fix extract issue when file contains unicode symbols

[v0.0.11]:
* Changelog in KODI

Expand Down
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7ff84516b598715f4820edd98ddf126bed2d6cd9
fdcca76e16ba5e22b6bf308c5a57a5defb52011b
4 changes: 4 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ msgstr ""
msgctxt "#32105"
msgid "Enabled"
msgstr ""

msgctxt "#32106"
msgid "Remove ads (Experimental)"
msgstr ""
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<setting type="sep"/>
<setting id="general.timeout" type="slider" label="32103" option="int" range="10,20" default="15"/>
<setting id="general.results_limit" type="slider" label="32104" option="int" range="10,100" default="20"/>
<setting id="general.remove_ads" type="bool" label="32106" default="false"/>
</category>
<!-- Services -->
<category label="32012">
Expand Down
2 changes: 1 addition & 1 deletion scripts/validate_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

if is_pull_request:
os.system('git fetch --deepen=1 --no-tags --quiet')
sha = github['event'].get('after', github['event']['pull_request']['sha'])
sha = github['event']['pull_request']['head']['sha']
command_args = ['git', 'log', '--format=%B', '-n', '1', sha]
else:
command_args = ['git', 'show', '-s', '--format=%s']
Expand Down

0 comments on commit a4743bd

Please sign in to comment.