Skip to content

Commit

Permalink
release: v0.0.28
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed May 10, 2020
1 parent ca851b8 commit 3bc0202
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 118 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* [v0.0.28](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.28):
* Attempt scrape of imdb id when missing
* Improve filename parsing
* Fix SubDB lang code

* [v0.0.27](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.27):
* Attempt to auto-fix a garbled cyrillic encoded subtitles
* Fix more encoding issues
Expand Down
9 changes: 5 additions & 4 deletions a4kSubtitles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
from xml.etree import ElementTree

from .lib import (
utils,
logger,
cache,
kodi,
video,
request,
logger,
num2ordinal,
request,
utils,
video,
)
from .services import services
from .search import search
Expand Down
58 changes: 58 additions & 0 deletions a4kSubtitles/lib/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-

import os
import json
import hashlib
from . import kodi
from . import utils

__meta_cache_filepath = os.path.join(kodi.addon_profile, 'last_meta.json')
__tvshow_years_cache_filepath = os.path.join(kodi.addon_profile, 'tvshow_years_cache.json')
__imdb_id_cache_filepath = os.path.join(kodi.addon_profile, 'imdb_id_cache.json')
results_filepath = os.path.join(kodi.addon_profile, 'last_results.json')

def __get_cache(filepath):
try:
with open(filepath, 'r') as f:
data = json.loads(f.read())
return utils.DictAsObject(data)
except:
return utils.DictAsObject({})

def __save_cache(filepath, cache):
try:
json_data = json.dumps(cache, indent=2)
with open(filepath, 'w') as f:
f.write(json_data)
except: pass

def hash_data(data):
json_data = json.dumps(data).encode(utils.default_encoding)
return hashlib.sha256(json_data).hexdigest()

def get_meta_hash(meta):
return hash_data({
'imdb_id': meta.imdb_id,
'filename': meta.filename,
})

def get_meta_cache():
meta_cache = __get_cache(__meta_cache_filepath)
meta_cache.setdefault('imdb_id', '')
meta_cache.setdefault('tvshow_year', '')
return meta_cache

def save_meta_cache(meta_cache):
return __save_cache(__meta_cache_filepath, meta_cache)

def get_tvshow_years_cache():
return __get_cache(__tvshow_years_cache_filepath)

def save_tvshow_years_cache(data):
return __save_cache(__tvshow_years_cache_filepath, data)

def get_imdb_id_cache():
return __get_cache(__imdb_id_cache_filepath)

def save_imdb_id_cache(data):
return __save_cache(__imdb_id_cache_filepath, data)
44 changes: 0 additions & 44 deletions a4kSubtitles/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
import re
import json
import hashlib
import string
from . import kodi
from . import logger
Expand Down Expand Up @@ -33,49 +32,6 @@
py3 = not py2

temp_dir = os.path.join(kodi.addon_profile, 'temp')
results_filepath = os.path.join(kodi.addon_profile, 'last_results.json')

__meta_cache_filepath = os.path.join(kodi.addon_profile, 'last_meta.json')
__tvshow_years_cache = os.path.join(kodi.addon_profile, 'tvshow_years_cache.json')

def __get_cache(filepath):
try:
with open(filepath, 'r') as f:
return json.loads(f.read())
except:
return {}

def __save_cache(filepath, cache):
try:
json_data = json.dumps(cache, indent=2)
with open(filepath, 'w') as f:
f.write(json_data)
except: pass

def get_meta_cache():
meta_cache = __get_cache(__meta_cache_filepath)
meta_cache.setdefault('imdb_id', '')
return meta_cache

def save_meta_cache(meta_cache):
return __save_cache(__meta_cache_filepath, meta_cache)

def get_tvshow_years_cache():
return __get_cache(__tvshow_years_cache)

def save_tvshow_years_cache(tvshow_years_cache):
return __save_cache(__tvshow_years_cache, tvshow_years_cache)

def get_tvshow_cache_key(imdb_id):
return '%s_tvshow_year' % imdb_id

def get_meta_hash(meta):
hash_data = {
'imdb_id': meta.imdb_id,
'filename': meta.filename,
}
json_data = json.dumps(hash_data).encode(default_encoding)
return hashlib.sha256(json_data).hexdigest()

class DictAsObject(dict):
def __getattr__(self, name):
Expand Down
Loading

0 comments on commit 3bc0202

Please sign in to comment.