Formattazione Titoli in render_items + correzione di alcuni canali

This commit is contained in:
Alhaziel01
2021-06-05 15:51:46 +02:00
parent ab8136e326
commit 1868420425
10 changed files with 194 additions and 154 deletions
+88 -90
View File
@@ -131,7 +131,7 @@ def regexDbg(item, patron, headers, data=''):
webbrowser.open(url + "/r/" + permaLink)
def scrapeLang(scraped, lang, longtitle):
def scrapeLang(scraped, lang):
## Aggiunto/modificato per gestire i siti che hanno i video
## in ita e subita delle serie tv nella stessa pagina
# altrimenti dopo un sub-ita mette tutti quelli a seguire in sub-ita
@@ -143,14 +143,15 @@ def scrapeLang(scraped, lang, longtitle):
if 'sub' in scraped['lang'].lower(): language = 'Sub-' + language
if not language: language = lang
if language: longtitle += typo(language, '_ [] color kod')
return language, longtitle
# if language: longtitle += typo(language, '_ [] color kod')
return language
def cleantitle(title):
cleantitle = ''
if title:
if type(title) != str: title.decode('UTF-8')
title = scrapertools.unescape(title)
title = scrapertools.decodeHtmlentities(title)
cleantitle = title.replace('"', "'").replace('×', 'x').replace('', '-').strip()
return cleantitle
@@ -191,7 +192,10 @@ def scrapeBlock(item, args, block, patron, headers, action, pagination, debug, t
# lang = lingua del video. Es: ITA, Sub-ITA, Sub, SUB ITA.
# AVVERTENZE: Se il titolo è trovato nella ricerca TMDB/TVDB/Altro allora le locandine e altre info non saranno quelle recuperate nel sito.!!!!
stagione = '' # per quei siti che hanno la stagione nel blocco ma non nelle puntate
season = '' # per quei siti che hanno la stagione nel blocco ma non nelle puntate
episode = ''
second_episode = ''
extraInfo = ''
contents = []
for i, match in enumerate(matches):
@@ -221,8 +225,7 @@ def scrapeBlock(item, args, block, patron, headers, action, pagination, debug, t
title = cleantitle(scraped.get('title', ''))
if group and scraped.get('title', '') in contents and not item.grouped: # same title and grouping enabled
continue
if item.grouped and scraped.get('title',
'') != item.fulltitle: # inside a group different tvshow should not be included
if item.grouped and scraped.get('title', '') != item.fulltitle: # inside a group different tvshow should not be included
continue
contents.append(title)
title2 = cleantitle(scraped.get('title2', '')) if not group or item.grouped else ''
@@ -230,6 +233,7 @@ def scrapeBlock(item, args, block, patron, headers, action, pagination, debug, t
# Type = scraped['type'] if scraped['type'] else ''
plot = cleantitle(scraped.get("plot", ''))
# if title is set, probably this is a list of episodes or video sources
# necessaria l'aggiunta di == scraped["title"] altrimenti non prende i gruppi dopo le categorie
if item.infoLabels["title"] == scraped["title"]:
@@ -244,8 +248,7 @@ def scrapeBlock(item, args, block, patron, headers, action, pagination, debug, t
if scraped["plot"]:
infolabels['plot'] = plot
if scraped['duration']:
dur = scrapertools.find_multiple_matches(scraped['duration'],
r'([0-9])\s*?(?:[hH]|:|\.|,|\\|\/|\||\s)\s*?([0-9]+)')
dur = scrapertools.find_multiple_matches(scraped['duration'], r'([0-9])\s*?(?:[hH]|:|\.|,|\\|\/|\||\s)\s*?([0-9]+)')
for h, m in dur:
scraped['duration'] = int(h) * 60 + int(m)
if not dur:
@@ -260,55 +263,52 @@ def scrapeBlock(item, args, block, patron, headers, action, pagination, debug, t
if scraped["rating"]:
infolabels['rating'] = scrapertools.decodeHtmlentities(scraped["rating"])
episode = ''
if not group or item.grouped:
if scraped['season'] and scraped['episode']:
stagione = scraped['season']
ep = unifyEp(scraped['episode'])
# dbg()
ep = unifyEp(scraped['episode']) if scraped['episode'] else ''
se = scraped['season'] if scraped['season'].isdigit() else ''
if ep and se:
season = int(se)
if 'x' in ep:
episode = ep.split('x')[0].strip()
second_episode = ep.split('x')[1].strip()
ep_list = ep.split('x')
episode = ep_list.strip()
second_episode = ep_list[1:]
else:
episode = ep
second_episode = ''
infolabels['season'] = int(scraped['season'])
infolabels['episode'] = int(episode)
episode = str(int(scraped['season'])) +'x'+ str(int(episode)).zfill(2) + ('x' + str(int(second_episode)).zfill(2) if second_episode else '')
elif item.season:
infolabels['season'] = int(item.season)
infolabels['episode'] = int(scrapertools.find_single_match(scraped['episode'], r'(\d+)'))
episode = item.season +'x'+ scraped['episode'].zfill(2)
elif item.contentType == 'tvshow' and (scraped['episode'] == '' and scraped['season'] == '' and stagione == ''):
season = int(item.season)
if ep: episode = int(scrapertools.find_single_match(scraped['episode'], r'(\d+)'))
elif item.contentType == 'tvshow' and (scraped['episode'] == '' and scraped['season'] == '' and season == ''):
item.news = 'season_completed'
episode = ''
else:
episode = unifyEp(scraped['episode']) if scraped['episode'] else ''
try:
if 'x' in episode:
ep = episode.split('x')
episode = str(int(ep[0])).zfill(1) + 'x' + str(int(ep[1])).zfill(2)
infolabels['season'] = int(ep[0])
infolabels['episode'] = int(ep[1])
second_episode = scrapertools.find_single_match(episode, r'x\d+x-\d+)')
if second_episode: episode = re.sub(r'(\d+x\d+)x\d+',r'\1-', episode) + second_episode.zfill(2)
if 'x' in ep:
ep_list = ep.split('x')
episode = ep_list[1].strip()
season = ep_list[2].strip()
if len(ep_list) > 2:
second_episode = ep_list[2:]
else:
episode = ep
except:
logger.debug('invalid episode: ' + episode)
pass
if scraped['episode2']:
episode += '-' + scrapertools.find_single_match(scraped['episode2'], r'(\d+)')
ep2 = scrapertools.find_single_match(scraped['episode2'], r'(\d+)')
ep_list = ep2.split('x')
second_episode = ep_list
# make formatted Title [longtitle]
s = ' - '
# title = episode + (s if episode and title else '') + title
longtitle = episode + (s if episode and (title or title2) else '') + title + (s if title and title2 else '') + title2
if sceneTitle:
from lib.guessit import guessit
try:
parsedTitle = guessit(title)
title = longtitle = parsedTitle.get('title', '')
title = parsedTitle.get('title', '')
logger.debug('TITOLO',title)
if parsedTitle.get('source'):
quality = str(parsedTitle.get('source'))
@@ -316,43 +316,36 @@ def scrapeBlock(item, args, block, patron, headers, action, pagination, debug, t
quality += ' ' + str(parsedTitle.get('screen_size', ''))
if not scraped['year']:
if type(parsedTitle.get('year', '')) == list:
infolabels['year'] =parsedTitle.get('year', '')[0]
infolabels['year'] = parsedTitle.get('year', '')[0]
else:
infolabels['year'] = parsedTitle.get('year', '')
if parsedTitle.get('episode') and parsedTitle.get('season'):
longtitle = title + s
if type(parsedTitle.get('season')) == list:
longtitle += str(parsedTitle.get('season')[0]) + '-' + str(parsedTitle.get('season')[-1])
infolabels['season'] = parsedTitle.get('season')[0]
else:
longtitle += str(parsedTitle.get('season'))
infolabels['season'] = parsedTitle.get('season')
season = parsedTitle.get('season')[0]
elif parsedTitle.get('season'):
season = parsedTitle.get('season')
if type(parsedTitle.get('episode')) == list:
longtitle += 'x' + str(parsedTitle.get('episode')[0]).zfill(2) + '-' + str(parsedTitle.get('episode')[-1]).zfill(2)
infolabels['episode'] = parsedTitle.get('episode')[0]
episode = parsedTitle.get('episode')[0]
second_episode = parsedTitle.get('episode')[1:]
else:
longtitle += 'x' + str(parsedTitle.get('episode')).zfill(2)
infolabels['episode'] = parsedTitle.get('episode')
elif parsedTitle.get('season') and type(parsedTitle.get('season')) == list:
longtitle += s + config.get_localized_string(30140) + " " +str(parsedTitle.get('season')[0]) + '-' + str(parsedTitle.get('season')[-1])
extraInfo = '{}: {}-{}'.format(config.get_localized_string(30140), parsedTitle.get('season')[0], parsedTitle.get('season')[-1])
elif parsedTitle.get('season'):
longtitle += s + config.get_localized_string(60027) % str(parsedTitle.get('season'))
infolabels['season'] = parsedTitle.get('season')
season = parsedTitle.get('season')
if parsedTitle.get('episode_title'):
longtitle += s + parsedTitle.get('episode_title')
infolabels['episodeName'] = parsedTitle.get('episode_title')
extraInfo += parsedTitle.get('episode_title')
except:
import traceback
logger.error(traceback.format_exc())
longtitle = typo(longtitle, 'bold')
lang1, longtitle = scrapeLang(scraped, lang, longtitle)
longtitle += typo(quality, '_ [] color kod') if quality else ''
longtitle += typo(scraped['size'], '_ [] color kod') if scraped['size'] else ''
longtitle += typo(scraped['seed'] + ' SEEDS', '_ [] color kod') if scraped['seed'] else ''
if season: infolabels['season'] = int(season)
if episode: infolabels['episode'] = int(episode)
lang1 = scrapeLang(scraped, lang)
AC = CT = ''
if typeContentDict:
@@ -368,29 +361,33 @@ def scrapeBlock(item, args, block, patron, headers, action, pagination, debug, t
break
else: AC = action
if (not scraped['title'] or scraped["title"] not in blacklist) and (search.lower() in longtitle.lower()):
if (not scraped['title'] or scraped["title"] not in blacklist) and (search.lower() in title.lower()):
contentType = 'episode' if function == 'episodios' else CT if CT else item.contentType
it = Item(
channel=item.channel,
action=AC if AC else action,
contentType=contentType,
title=longtitle,
fulltitle=item.fulltitle if function == 'episodios' else title,
channel = item.channel,
action = AC if AC else action,
contentType = contentType,
title = title,
fulltitle = item.fulltitle if function == 'episodios' else title,
show=item.show if function == 'episodios' else title,
quality=quality,
url=scraped["url"] if scraped["url"] else item.url,
infoLabels=infolabels,
thumbnail=item.prevthumb if item.prevthumb else item.thumbnail if not scraped["thumb"] else scraped["thumb"],
args=item.args,
contentSerieName= title if 'movie' not in [contentType] and function != 'episodios' else item.contentSerieName,
contentTitle= title if 'movie' in [contentType] and function == 'peliculas' else item.contentTitle,
contentLanguage = lang1 if lang1 else item.contentLanguage,
contentSeason= infolabels.get('season', ''),
quality = quality,
url = scraped["url"] if scraped["url"] else item.url,
infoLabels = infolabels,
thumbnail = item.prevthumb if item.prevthumb else item.thumbnail if not scraped["thumb"] else scraped["thumb"],
args = item.args,
contentSerieName = title if 'movie' not in [contentType] and function != 'episodios' else item.contentSerieName,
contentTitle = title if 'movie' in [contentType] and function == 'peliculas' else item.contentTitle,
contentLanguage = lang1 if lang1 else item.contentLanguage if item.contentLanguage else 'ITA',
contentSeason = infolabels.get('season', ''),
contentEpisodeNumber=infolabels.get('episode', ''),
news= item.news if item.news else '',
news = item.news if item.news else '',
other = scraped['other'] if scraped['other'] else '',
grouped=group
grouped = group,
title2 = cleantitle(title2) if title2 else '',
episode2 = second_episode,
extraInfo = extraInfo
)
if scraped['episode'] and group and not item.grouped: # some adjustment for grouping feature
it.action = function
if it.action == 'findvideos':
@@ -478,10 +475,10 @@ def scrape(func):
typeContentDict, typeActionDict, blacklist, search, pag, function, lang, sceneTitle, group)
for it in blockItemlist:
if 'lang' in bl:
it.contentLanguage, it.title = scrapeLang(bl, it.contentLanguage, it.title)
it.contentLanguage = scrapeLang(bl, it.contentLanguage, it.title)
if 'quality' in bl and bl['quality']:
it.quality = bl['quality'].strip()
it.title = it.title + typo(bl['quality'].strip(), '_ [] color kod')
# it.title = it.title + typo(bl['quality'].strip(), '_ [] color kod')
itemlist.extend(blockItemlist)
matches.extend(blockMatches)
elif patron:
@@ -546,13 +543,13 @@ def scrape(func):
if patronNext and inspect.stack()[1][3] not in ['newest'] and len(inspect.stack()) > 2 and inspect.stack()[2][3] not in ['get_channel_results']:
nextPage(itemlist, item, data, patronNext, function)
for it in itemlist:
if it.contentEpisodeNumber and it.contentSeason:
it.title = '[B]{:d}x{:02d} - {}[/B]'.format(it.contentSeason, it.contentEpisodeNumber, it.infoLabels['title'] if it.infoLabels['title'] else it.fulltitle)
if it.contentLanguage:
it.title += typo(it.contentLanguage, '_ [] color kod')
if it.quality:
it.title += typo(it.quality, '_ [] color kod')
# for it in itemlist:
# if it.contentEpisodeNumber and it.contentSeason:
# it.title = '[B]{:d}x{:02d} - {}[/B]'.format(it.contentSeason, it.contentEpisodeNumber, it.infoLabels['title'] if it.infoLabels['title'] else it.fulltitle)
# if it.contentLanguage:
# it.title += typo(it.contentLanguage, '_ [] color kod')
# if it.quality:
# it.title += typo(it.quality, '_ [] color kod')
# next page for pagination
if pagination and len(matches) > pag * pagination and not search:
@@ -1207,15 +1204,16 @@ def server(item, data='', itemlist=[], headers='', AutoPlay=True, CheckLinks=Tru
# logger.debug(videoitem)
if videoitem.video_urls or srv_param.get('active', False):
# dbg()
item.title = typo(item.contentTitle.strip(), 'bold') if item.contentType == 'movie' and item.contentTitle or (config.get_localized_string(30161) in item.fulltitle) else item.fulltitle
item.title = item.contentTitle.strip() if item.contentType == 'movie' and item.contentTitle or (config.get_localized_string(30161) in item.fulltitle) else item.fulltitle
quality = videoitem.quality if videoitem.quality else item.quality if item.quality else ''
videoitem.contentLanguage = videoitem.contentLanguage if videoitem.contentLanguage else item.contentLanguage if item.contentLanguage else 'ITA'
videoitem.title = (item.title if item.channel not in ['url'] else '')\
+ (typo(videoitem.title, '_ color kod [] bold') if videoitem.title else "")\
+ (typo(videoitem.quality, '_ color kod []') if videoitem.quality else "")\
+ (typo(videoitem.contentLanguage, '_ color kod []') if videoitem.contentLanguage else "")\
+ (typo(videoitem.extraInfo, '_ color kod []') if videoitem.extraInfo else "")
videoitem.title = item.title
# videoitem.title = (item.title if item.channel not in ['url'] else '')\
# + (typo(videoitem.title, '_ color kod [] bold') if videoitem.title else "")\
# + (typo(videoitem.quality, '_ color kod []') if videoitem.quality else "")\
# + (typo(videoitem.contentLanguage, '_ color kod []') if videoitem.contentLanguage else "")\
# + (typo(videoitem.extraInfo, '_ color kod []') if videoitem.extraInfo else "")
videoitem.plot = typo(videoitem.title, 'bold') + (typo(quality, '_ [] bold') if quality else '')
videoitem.channel = item.channel
videoitem.fulltitle = item.fulltitle
+12 -12
View File
@@ -471,7 +471,7 @@ def save_tvshow(item, episodelist, silent=False):
if not head_nfo: return 0, 0, -1, ''
# support.dbg()
extra_info = get_fanart_tv(item)
if not item.infoLabels.get('posters'): item.infoLabels['posters'] = []
if not item.infoLabels.get('posters'):item.infoLabels['posters'] = []
item.infoLabels['posters'] += extra_info['poster'].get('all',[])
if not item.infoLabels.get('fanarts'): item.infoLabels['fanarts'] = []
item.infoLabels['fanarts'] += extra_info['fanart']
@@ -481,7 +481,7 @@ def save_tvshow(item, episodelist, silent=False):
item.infoLabels['cleararts'] += extra_info['clearart']
if not item.infoLabels.get('landscapes'): item.infoLabels['landscapes'] = []
item.infoLabels['landscapes'] += extra_info['landscape'].get('all',[])
if not item.infoLabels.get('banners'): item.infoLabels['banners'] = []
if not item.infoLabels.get('banners'):item.infoLabels['banners'] = []
item.infoLabels['banners'] += extra_info['banner'].get('all',[])
@@ -498,10 +498,10 @@ def save_tvshow(item, episodelist, silent=False):
if not tvshow_item.videolibrary_id: tvshow_item.videolibrary_id = _id
if not tvshow_item.thumbnail: tvshow_item.thumbnail = item.infoLabels['thumbnail']
if not tvshow_item.fanart: tvshow_item.fanart = item.infoLabels['fanart']
if not tvshow_item.landscape: tvshow_item.landscape = item.infoLabels['landscapes'][0] if item.infoLabels['landscapes'] else item.infoLabels['fanart']
if not tvshow_item.banner and item.infoLabels['banners']: tvshow_item.clearart = item.infoLabels['banners'][0]
if not tvshow_item.clearart and item.infoLabels['cleararts']: tvshow_item.clearart = item.infoLabels['cleararts'][0]
if not tvshow_item.clearlogo and item.infoLabels['clearlogos']: tvshow_item.clearlogo = item.infoLabels['clearlogos'][0]
if not tvshow_item.infoLabels.get('landscape'): tvshow_item.infoLabels['landscape'] = item.infoLabels['landscapes'][0] if item.infoLabels['landscapes'] else item.infoLabels['fanart']
if not tvshow_item.infoLabels.get('banner') and item.infoLabels['banners']: tvshow_item.infoLabels['banner'] = item.infoLabels['banners'][0]
if not tvshow_item.infoLabels.get('clearart') and item.infoLabels['cleararts']: tvshow_item.infoLabels['clearart'] = item.infoLabels['cleararts'][0]
if not tvshow_item.infoLabels.get('clearlogo') and item.infoLabels['clearlogos']: tvshow_item.infoLabels['clearlogo'] = item.infoLabels['clearlogos'][0]
if not tvshow_item.base_name: tvshow_item.base_name = base_name
if tvshow_item.active == '': tvshow_item.active = True
if not tvshow_item.prefered_lang: tvshow_item.prefered_lang = ''
@@ -555,13 +555,13 @@ def save_episodes(item, episodelist, extra_info, host, local_files, silent=False
episode = None
season_episode = None
season_episode = scrapertools.get_season_and_episode(e.title)
if season_episode:
if e.contentSeason and e.contentEpisodeNumber:
season_episode = '{}x{:02d}'.format(e.contentSeason, e.contentEpisodeNumber)
strm_path = filetools.join(item.base_name, "{}.strm".format(season_episode))
e.contentSeason = int(season_episode.split('x')[0])
e.contentEpisodeNumber = int(season_episode.split('x')[1])
# e.contentSeason = int(season_episode.split('x')[0])
# e.contentEpisodeNumber = int(season_episode.split('x')[1])
if item.infoLabels.get('imdb_id'): e.infoLabels['imdb_id'] = item.infoLabels['imdb_id']
if item.infoLabels.get('tmdb_id'): e.infoLabels['tmdb_id'] = item.infoLabels['tmdb_id']
if item.infoLabels.get('tvdb_id'): e.infoLabels['tvdb_id'] = item.infoLabels['tvdb_id']
@@ -581,7 +581,7 @@ def save_episodes(item, episodelist, extra_info, host, local_files, silent=False
videolibrary_id = item.videolibrary_id,
thumbnail = e.infoLabels.get('poster_path') if e.infoLabels.get('poster_path') else item.thumbnail,
fanart = e.infoLabels.get('poster_path') if e.infoLabels.get('poster_path') else item.fanart,
title = '{}. {}'.format(e.contentEpisodeNumber, e.infoLabels['title']))
title = e.infoLabels['title'])
episode = episodes.get(season_episode, {})
@@ -879,7 +879,7 @@ def add_tvshow(item, channel=None):
it = item.clone()
itemlist = getattr(channel, it.action)(it)
item.host = channel.host
if itemlist and not scrapertools.find_single_match(itemlist[0].title, r'[Ss]?(\d+)(?:x|_|\s+)[Ee]?[Pp]?(\d+)'):
if itemlist:
from platformcode.autorenumber import start, check
if not check(item):
action = item.action