Skip to content

Commit

Permalink
fixed #508 - kodi 19.4 with latest daily build;
Browse files Browse the repository at this point in the history
fixed #459 - restore Calendar;
fixed #458 - restore extra menu;
fixed #394;
fixed #372 - we are using vanilla route;
fixed #370 - a lot things changed already;
fixed #340 - we using this right now, this is v19 working;
fixed #323 - got workaround;
fixed #305 - most of them are there, when someone need more we will provide;
fixed #238 - we got favorites and cross that with Calendar;
  • Loading branch information
bigretromike committed May 26, 2022
1 parent f6d84a9 commit f4d91dc
Show file tree
Hide file tree
Showing 13 changed files with 953 additions and 12 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.nakamori" name="Nakamori" version="4.0.0" provider-name="BigRetroMike, SteveMavic, da3dsoul">
<addon id="plugin.video.nakamori" name="Nakamori" version="4.1.0" provider-name="BigRetroMike, SteveMavic, da3dsoul">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.routing" version="0.2.3"/>
Expand Down
3 changes: 0 additions & 3 deletions api/shoko/v2/api2.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,6 @@ def series_from_ep(self, opts: QueryOptions = QueryOptions()) -> Serie:
Return list of series"""
response = self.api_client.call(url='/api/serie/fromep', call_type=APIType.GET, query=opts.__dict__)
# _json = json.loads(response)
return Serie.Decoder(response)

def series_groups(self, opts: QueryOptions = QueryOptions()):
Expand All @@ -767,7 +766,6 @@ def series_groups(self, opts: QueryOptions = QueryOptions()):
Return list of series"""
response = self.api_client.call(url='/api/serie/groups', call_type=APIType.GET, query=opts.__dict__)
# _json = json.loads(response)
output: list[Group] = []
for group in response:
output.append(Group.Decoder(group))
Expand All @@ -780,7 +778,6 @@ def series_from_anidb(self, opts: QueryOptions = QueryOptions()) -> Serie:
Return list of series"""
response = self.api_client.call(url='/api/serie/fromaid', call_type=APIType.GET, query=opts.__dict__)
# _json = json.loads(response)
return Serie.Decoder(response)

#
Expand Down
Binary file added fonts/FiraMono-Bold.ttf
Binary file not shown.
Binary file added fonts/Migu.ttf
Binary file not shown.
Binary file added fonts/UbuntuMono-Bold.ttf
Binary file not shown.
201 changes: 201 additions & 0 deletions lib/external_calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# -*- coding: utf-8 -*-
import datetime
import time
import json
import os
import re
# import error_handler as eh
from urllib.error import HTTPError
from models.kodi_models import make_text_nice

import xbmc
import xbmcaddon
import xbmcvfs
from urllib import request

ADDON = xbmcaddon.Addon(id='plugin.video.nakamori')
x = xbmcvfs.translatePath(ADDON.getAddonInfo('profile'))
x = os.path.join(x, 'json')
x = os.path.join(x, '%s' % ADDON.getSetting('url_type'))
is_seasons = True
if ADDON.getSetting('url_type') == 'calendar':
is_seasons = False

if not os.path.exists(x):
os.makedirs(x)


def pack_json(new_list):
fake_json = dict()
fake_json['art'] = {'thumb': [], 'banner': [], 'fanart': []}
fake_json['id'] = 0
fake_json['name'] = 'Airing Soon'
fake_json['roles'] = None
fake_json['summary'] = ''
fake_json['tags'] = None
fake_json['type'] = 'group'
fake_json['url'] = ''
fake_json['series'] = new_list
fake_json['size'] = len(new_list)
return fake_json


def process_month(year, month, day, day_already_processed, url):
xbmc.log(f'== process_month == {year}/{month}/{day} : already = {day_already_processed} - url={url} ', xbmc.LOGINFO)
day_is = datetime.date(year, month, day)
week = day_is.isocalendar()[1]
if is_seasons:
y = os.path.join(x, '%s-%02d.json' % (year, month))
else:
y = os.path.join(x, '%s-%02d.json' % (year, week))

if os.path.exists(y):
# more than 24h
if int(time.time()) - int(os.path.getmtime(y)) > 86400:
os.remove(y)

if not os.path.exists(y) and not download_external_source(url, year, month, week):
return None
if not os.path.exists(y):
xbmc.log('=== 404 calendar and no file', xbmc.LOGINFO)
return None

content = open(y, 'r').read()
pre_body = json.loads(content)
body = []

for pre in pre_body:
# eh.spam('process_month.pre item: %s' % pre)
if int(pre['air'][8:10]) >= day:
if pre['air'] not in day_already_processed:
if len(day_already_processed) > 7:
break
day_already_processed.append(pre['air'])
body.append(pre)

return body


def return_only_few(when: str, offset: int = 0, url: str = '', day_limits: int = 7, go_back_in_time: bool = False):
# TODO do I need offset? should I use offset?
time_machine = 1
if go_back_in_time:
time_machine = -1
offset = int(offset)
when = str(when)
if len(when) == 8:
year = int(when[0:4])
month = int(when[4:6])
day = int(when[6:8])
else:
year = datetime.datetime.now().year
month = datetime.datetime.now().month
day = datetime.datetime.now().day

day_already_processed = []
body = process_month(year, month, day, day_already_processed, url)

if body is not None:
if len(day_already_processed) < day_limits:
# process next month
month += time_machine
day = 1
if month == 13:
month = 1
year += time_machine
next_body = process_month(year, month, day, day_already_processed, url)
if next_body is not None:
body = body + next_body
return json.dumps(pack_json(body))
else:
return None


def download_external_source(url, year=datetime.datetime.now().year, month=datetime.datetime.now().month, week=datetime.datetime.now().isocalendar()[1]):
# eh.spam('download_external_source(url=%s, year=%s, month=%s, weekofyear=%s)' % (url, year, month, week))
if is_seasons:
y = os.path.join(x, '%s-%02d-tmp.json' % (year, month))
url = url % (year, month)
z = os.path.join(x, '%s-%02d.json' % (year, month))
else:
y = os.path.join(x, '%s-%02d-tmp.json' % (year, week))
url = url % (year, week)
z = os.path.join(x, '%s-%02d.json' % (year, week))

xbmc.log('URL===> ' + url, xbmc.LOGINFO)
try:
content = request.urlopen(url).read().decode('utf-8')

if os.path.exists(y):
os.remove(y)
open(y, 'wb').write(content.encode('utf-8'))
try:
response = json.loads(content)
series_list = []
series_item = {}
for dates in response.get('calendar'):
for series in response['calendar'][dates]:
try:
img = ''
x1 = ''
number = 0
img_number = re.search(r'65x100\/(.*)\.jpg-thumb', str(series['image']))
if img_number is None:
if "images/150" in str(series['image']):
# "images/150/221366.jpg-thumb.jpg"
img_number = re.search(r'images\/150\/(.*)\.jpg-thumb', str(series['image']))
number = img_number.group(1)
x1 = 'images/65x100/' + number + '.jpg-thumb.jpg'
elif "thumbs/150" in str(series['image']):
img_number = re.search(r'thumbs\/150\/(.*)\.jpg-thumb', str(series['image']))
number = img_number.group(1)
x1 = 'thumbs/65x100/' + number + '.jpg-thumb.jpg'
if img_number is not None:
if number == 0:
number = img_number.group(1)
if x1 == '':
x1 = 'thumbs/65x100/' + number + '.jpg-thumb.jpg'
x2 = number + '.jpg'
img = str(series['image']).replace(x1, x2)

series_item['aid'] = series['aid']
series_item['air'] = dates
series_item['date'] = dates
series_item['art'] = {'thumb': [{'index': 0, 'url': img}], 'banner': [], 'fanart': []}
series_item['id'] = -1
series_item['ismovie'] = 0
series_item['name'] = series['name']
series_item['rating'] = 0
series_item['roles'] = []
series_item['size'] = 0
series_item['summary'] = make_text_nice(series['desc'])
series_item['tags'] = None
series_item['titles'] = [{'Language': 'x-jat', 'Title': series['name'], 'Type': 'main'},
{'Language': 'ja', 'Title': series['kanji'], 'Type': 'official'}]
series_item['type'] = 'serie'
series_item['votes'] = 0
series_item['year'] = year
# series['general']
series_list.append(series_item)
series_item = {} # do this because shit get duplicate ?!
except Exception as e:
# noinspection PyUnresolvedReferences
xbmc.log('Error in download_external_source.series: %s' % e, xbmc.LOGERROR)

if os.path.exists(z):
os.remove(z)
series_list = sorted(series_list, key=lambda i: (i['air'], i['name']))
con = json.dumps(series_list)
open(z, 'wb').write(con.encode('utf-8'))
# clean tmp
os.remove(y)
return True
except Exception as es:
xbmc.log('error: ' + str(es), xbmc.LOGERROR)
return False
except HTTPError as ex:
if ex.code == 404:
xbmc.log('calendar data was found more, 404', xbmc.LOGINFO)
return True
else:
return False
1 change: 1 addition & 0 deletions lib/windows/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
Loading

0 comments on commit f4d91dc

Please sign in to comment.