# -*- coding: utf-8 -*-
# vStream https://github.com/Kodi-vStream/venom-xbmc-addons
import re
import string
from resources.lib.gui.hoster import cHosterGui
from resources.lib.gui.gui import cGui
from resources.lib.handler.inputParameterHandler import cInputParameterHandler
from resources.lib.handler.outputParameterHandler import cOutputParameterHandler
from resources.lib.handler.requestHandler import cRequestHandler
from resources.lib.parser import cParser
from resources.lib.comaddon import siteManager
from resources.lib.util import cUtil
SITE_IDENTIFIER = 'animecomplet'
SITE_NAME = 'Animecomplet'
SITE_DESC = 'Series Anime'
URL_MAIN = siteManager().getUrlMain(SITE_IDENTIFIER)
ANIM_ANIMS = (True, 'load')
# ANIM_NEWS = (URL_MAIN, 'showAnims')
# ANIM_ALPHA = (URL_MAIN, 'showAlpha')
tag_global = '#global'
URL_SEARCH_ANIMS = (URL_MAIN + tag_global + '?s=', 'showAnims')
URL_SEARCH = (URL_MAIN + '?s=', 'showAnims')
def load():
oGui = cGui()
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', 'http://venom/')
oGui.addDir(SITE_IDENTIFIER, 'showSearch', 'Recherche', 'search.png', oOutputParameterHandler)
# oOutputParameterHandler.addParameter('siteUrl', ANIM_NEWS[0])
# oGui.addDir(SITE_IDENTIFIER, ANIM_NEWS[1], 'Animés (Derniers épisodes récents)', 'series.png', oOutputParameterHandler)
# oOutputParameterHandler.addParameter('siteUrl', ANIM_ALPHA[0])
# oGui.addDir(SITE_IDENTIFIER, ANIM_ALPHA[1], 'Animés (Liste alphabétique)', 'az.png', oOutputParameterHandler)
oGui.setEndOfDirectory()
def showAlpha():
oGui = cGui()
sAlpha = string.ascii_lowercase
listAlpha = list(sAlpha)
liste = []
req = ANIM_LIST[0]
oRequestHandler = cRequestHandler(req)
sHtmlContent = oRequestHandler.request()
# on propose quand meme en premier la liste complete
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', ANIM_LIST[0])
oGui.addDir(SITE_IDENTIFIER, ANIM_LIST[1], ' [COLOR coral]' + 'Animés (Liste complète)' + '[/COLOR]', 'listes.png', oOutputParameterHandler)
# récupere les chiffres dispos
sPattern = 'href="#gti_(\d+)'
oParser = cParser()
aResult = oParser.parse(sHtmlContent, sPattern)
if aResult[0] is True:
for aEntry in aResult[1]:
liste.append([str(aEntry), url1 + str(aEntry)])
for alpha in listAlpha:
liste.append([str(alpha).upper(), url1 + str(alpha)])
# sUrl = 'tagalpha ;alpha'
for sTitle, sUrl in liste:
oOutputParameterHandler.addParameter('siteUrl', sUrl)
oGui.addDir(SITE_IDENTIFIER, 'showAnims', 'Lettre [COLOR coral]' + sTitle + '[/COLOR]', 'listes.png', oOutputParameterHandler)
oGui.setEndOfDirectory()
def showSearch():
oGui = cGui()
sSearchText = oGui.showKeyBoard()
if sSearchText is not False:
sUrl = URL_SEARCH[0] + sSearchText
showAnims(sUrl)
oGui.setEndOfDirectory()
return
def showAnims(sSearch=''):
oGui = cGui()
bSearchGlobal = False
if sSearch:
oUtil = cUtil()
sSearchText = sSearch.replace(URL_SEARCH[0], '')
sSearchText = sSearchText.replace(URL_SEARCH_ANIMS[0], '')
sSearchText = oUtil.CleanName(sSearchText)
sUrl = sSearch.replace(' ', '+').replace('%20', '+')
if tag_global in sSearch:
sUrl = sUrl.replace(tag_global, '')
bSearchGlobal = True
else:
oInputParameterHandler = cInputParameterHandler()
sUrl = oInputParameterHandler.getValue('siteUrl')
# pour la liste alpha on peu aussi faire sUrl = alpha (plus rapide)
# sPattern = '..' + alpha + '([^<]+).+?style="width'
oRequestHandler = cRequestHandler(sUrl)
sHtmlContent = oRequestHandler.request()
sPattern = '<.+?>(.+?)<'
oParser = cParser()
aResult = oParser.parse(sHtmlContent, sPattern)
iCurrent = 0
list_simlilar = []
if aResult[0] is False:
oGui.addText(SITE_IDENTIFIER)
else:
oOutputParameterHandler = cOutputParameterHandler()
for aEntry in aResult[1]:
iCurrent = iCurrent + 1
sThumb = ''
sDesc = ''
sThumb = aEntry[0]
sUrl2 = aEntry[1]
sTitle = aEntry[2]
try:
sTitle = sTitle.decode('ascii', errors='ignore')
except:
pass
sTitle = sTitle.replace(' - Episode', ' Episode').replace(' VOSTFR', '').replace(' VF', '')
if sSearch and not oUtil.CheckOccurence(sSearchText, sTitle):
continue # Filtre de recherche
sLang = ''
if ' VOSTFR' in sTitle:
sLang = 'VOSTFR'
if ' VF' in sTitle:
sLang = 'VF'
if 'http' not in sThumb:
sThumb = URL_MAIN + sThumb
# le lien liés a l'episode va nous fournir apres tous
# les episodes saisons donc inutile de tout afficher si titre semblable
if bSearchGlobal and iCurrent > 3:
bValid, sim = similarTitle(sTitle)
if bValid:
if sim not in list_simlilar:
list_simlilar.append(sim)
else:
continue
sDisplayTtitle = sTitle + ' (' + sLang + ')'
oOutputParameterHandler.addParameter('siteUrl', sUrl2)
oOutputParameterHandler.addParameter('sMovieTitle', sTitle)
oOutputParameterHandler.addParameter('sThumb', sThumb)
oOutputParameterHandler.addParameter('sLang', sLang)
oGui.addAnime(SITE_IDENTIFIER, 'seriesHosters', sDisplayTtitle, '', sThumb, sDesc, oOutputParameterHandler)
if not bSearchGlobal:
sNextPage, sPaging = __checkForNextPage(sHtmlContent)
if sNextPage is not False:
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', sNextPage)
oGui.addNext(SITE_IDENTIFIER, 'showAnims', 'Page ' + sPaging, oOutputParameterHandler)
oGui.setEndOfDirectory()
def __checkForNextPage(sHtmlContent):
oParser = cParser()
sPattern = '>([^<]+)')
sHtmlContent = sHtmlContent[start:]
sPattern = '