Auto-Renumeration + Test in Anime World^C
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# --------------------------------------------------------------------------------
|
||||
# autorenumber - Rinomina Automaticamente gli Episodi
|
||||
# --------------------------------------------------------------------------------
|
||||
|
||||
import os
|
||||
|
||||
try:
|
||||
import xbmcgui
|
||||
except:
|
||||
xbmcgui = None
|
||||
|
||||
from platformcode import config
|
||||
from core import jsontools, tvdb
|
||||
from core.item import Item
|
||||
from platformcode import platformtools
|
||||
from channels.support import typo, log
|
||||
|
||||
TAG_TVSHOW_RENUMERATE = "TVSHOW_AUTORENUMBER"
|
||||
TAG_SEASON_EPISODE = "season_episode"
|
||||
__channel__ = "autorenumber"
|
||||
|
||||
|
||||
def access():
|
||||
allow = False
|
||||
|
||||
if config.is_xbmc():
|
||||
allow = True
|
||||
|
||||
return allow
|
||||
|
||||
|
||||
def context():
|
||||
if access():
|
||||
_context = [{"title": config.get_localized_string(70585),
|
||||
"action": "config_item",
|
||||
"channel": "autorenumber"}]
|
||||
|
||||
return _context
|
||||
|
||||
|
||||
def config_item(item):
|
||||
log(item)
|
||||
tvdb.find_and_set_infoLabels(item)
|
||||
data = ''
|
||||
data = add_season(data)
|
||||
data.append(item.infoLabels['tvdb_id'])
|
||||
write_data(item.from_channel, item.show, data)
|
||||
|
||||
|
||||
def add_season(data=None):
|
||||
log("data= ", data)
|
||||
heading = config.get_localized_string(70686)
|
||||
season = platformtools.dialog_numeric(0, heading)
|
||||
|
||||
if season != "":
|
||||
heading = config.get_localized_string(70687)
|
||||
episode = platformtools.dialog_numeric(0, heading)
|
||||
if episode != "":
|
||||
return [int(season), int(episode)]
|
||||
|
||||
|
||||
def write_data(channel, show, data):
|
||||
log()
|
||||
dict_series = jsontools.get_node_from_file(channel, TAG_TVSHOW_RENUMERATE)
|
||||
tvshow = show.strip()
|
||||
list_season_episode = dict_series.get(tvshow, {}).get(TAG_SEASON_EPISODE, [])
|
||||
|
||||
if data:
|
||||
dict_renumerate = {TAG_SEASON_EPISODE: data}
|
||||
dict_series[tvshow] = dict_renumerate
|
||||
else:
|
||||
dict_series.pop(tvshow, None)
|
||||
|
||||
result, json_data = jsontools.update_node(dict_series, channel, TAG_TVSHOW_RENUMERATE)
|
||||
|
||||
if result:
|
||||
if data:
|
||||
message = config.get_localized_string(60446)
|
||||
else:
|
||||
message = config.get_localized_string(60444)
|
||||
else:
|
||||
message = config.get_localized_string(70593)
|
||||
|
||||
heading = show.strip()
|
||||
platformtools.dialog_notification(heading, message)
|
||||
|
||||
def renumber(itemlist, item='', typography=''):
|
||||
log()
|
||||
|
||||
if item:
|
||||
try:
|
||||
dict_series = jsontools.get_node_from_file(item.channel, TAG_TVSHOW_RENUMERATE)
|
||||
SERIES = dict_series[item.show]['season_episode']
|
||||
S = SERIES[0]
|
||||
E = SERIES[1]
|
||||
ID = SERIES[2]
|
||||
|
||||
logger.info(str(S) + '|' + str(E) + '|' + ID)
|
||||
|
||||
page = 1
|
||||
epList = []
|
||||
exist = True
|
||||
item.infoLabels['tvdb_id'] = ID
|
||||
tvdb.set_infoLabels_item(item)
|
||||
|
||||
while exist:
|
||||
data = tvdb.otvdb_global.get_list_episodes(ID,page)
|
||||
if data:
|
||||
for episodes in data['data']:
|
||||
if episodes['airedSeason'] >= S:
|
||||
if episodes['airedEpisodeNumber'] >= E:
|
||||
epList.append(str(episodes['airedSeason']) + 'x' + str(episodes['airedEpisodeNumber']))
|
||||
page = page + 1
|
||||
else:
|
||||
exist = False
|
||||
logger.info(str(epList))
|
||||
ep = 0
|
||||
for item in itemlist:
|
||||
item.title = typo(epList[ep] + ' - ', typography) + item.title
|
||||
ep = ep + 1
|
||||
except:
|
||||
return itemlist
|
||||
else:
|
||||
for item in itemlist:
|
||||
if item.contentType != 'movie':
|
||||
if item.context:
|
||||
context2 = item.context
|
||||
item.context = context() + context2
|
||||
else:
|
||||
item.context = context()
|
||||
|
||||
return itemlist
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user