def create_DB(url, dbname): DB_file = os.path.join(cache_dir, translate_string("%s.txt" % dbname)) try: save_data(get_film_list(url), DB_file) except: print "impossible de créer la base %s" % DB_file print_exc()
def load_DB(dbname): DB_file = os.path.join(cache_dir, translate_string("%s.txt" % dbname)) if os.path.isfile(DB_file): try: if time.time() - os.path.getmtime(DB_file) > 3600: print "base de plus de 24h, reconstruction..." return ("") data = load_data(DB_file) except: print "impossible de charger %s" % DB_file print_exc() data = "" else: data = "" return data
def load_DB(dbname): DB_file= os.path.join( cache_dir , translate_string("%s.txt" % dbname) ) ## print "last modifications: %s" % os.path.getmtime(DB_file) ## print "actual %s" % time.time() ## print time.time() - os.path.getmtime(DB_file) if os.path.isfile(DB_file): try: if time.time() - os.path.getmtime(DB_file) > 3600: print "base de plus de 24h, reconstruction..." return("") data=load_data(DB_file) except: print "impossible de charger %s" % DB_file print_exc() data="" else: data="" return data
def create_DB( url , dbname ): DB_file= os.path.join( cache_dir , translate_string("%s.txt" % dbname) ) try: save_data( get_film_list( url ) , DB_file ) except: print "impossible de créer la base %s" % DB_file print_exc()
def get_film_info(id_allo , BA = False , all_BA = False , emissions_liees = False , interviews = False): film = {} film_url = "http://www.allocine.fr/film/fichefilm_gen_cfilm=%s.html" % id_allo film_data = get_html_source( film_url ) #save_data(film_data) #DEBUG try: media_list = re.findall( '<a href="/video/player_gen_cmedia=(.*?)&cfilm=.*.html"><b>', film_data ) except: print_exc() media_list = "" match = re.search(r'<a class="fs11 underline" href="(.*)"><img class="ico icoticka" alt=" " width="0" height="0" src="http://images.allocine.fr/commons/empty.gif"/><span>Toutes les vid\xc3\xa9os</span></a>', film_data, re.IGNORECASE) if match: url_all_video = match.group(1) else: url_all_video = "" # print "url_video: %s" % url_all_video #DEBUG if BA: BA_list = [] if media_list: for id_media in media_list: BA_list.append(get_media_link(id_media)) film["Bande-annonces"] = BA_list return film if emissions_liees or all_BA or interviews: # print "test liens toutes vidéos" #DEBUG if not url_all_video == "": # print "url toutes vidéos trouvé" #DEBUG video_data = get_html_source( "http://www.allocine.fr" + url_all_video ) # save_data(video_data) #DEBUG if interviews: # print "test interviews liées" #DEBUG match = re.search(r"<h2>\s+(\d+) Interviews li\xc3\xa9es \xc3\xa0 ce film\s+</h2>(.*?)<h2>Autres bandes-annonces</h2>", video_data, re.DOTALL | re.IGNORECASE) if match: nbre_interviews = match.group(1) interviews_data = match.group(2) else: dialog.ok("Interviews Allociné" , "aucune interview liée") return False nbre_interviews = "" interviews_data = "" # save_data(interviews_data) #DEBUG # print "nombre interviews liées: %s" % nbre_interviews #DEBUG result = re.findall(r'(?i)<a href=\'/film/fichefilm-\d+/interviews/\?cmedia=(\d+)\'>\s+<img src=\'(.*?)\' alt="Photo : (.*?)" title="Photo : (.*?)" />\s+</a>', interviews_data) # print "nombre emissions liées trouvées: %s" % len(result) #DEBUG for i in result: # print i[3] , i[1]#DEBUG #ba = get_media_link(i[0]) print i[2] if xbmcplugin.getSetting("hdimage") == "true": image = i[1].replace( "cx_120_96/b_1_x/o_play.png_5_se" , "r_760_x" ) else: image = i[1] print image c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string( i[3] ) ) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % ( urllib.quote_plus( "cmedia=%s" % i[0] ), urllib.quote_plus( local_trailer ) , quality) if not os.path.exists(local_trailer):c_items += [ ( "Télécharger", "XBMC.RunScript(%s,%s)" % ( script, args ) ) ] else : c_items += [ ( "jouer en local", "xbmc.PlayMedia(%s)" % local_trailer) ] addDir(i[3], i[0],5,image, c_items ) if emissions_liees: # print "test emisions liées" #DEBUG match = re.search(r"<h2>(\d+) \xc3\xa9missions li\xc3\xa9es</h2>(.*?)<h2>Autres bandes-annonces</h2>", video_data, re.DOTALL | re.IGNORECASE) if match: nbre_emissions = match.group(1) emision_data = match.group(2) else: dialog.ok("Emissions Allociné" , "aucune emission liée") return False nbre_emissions = "" emision_data = "" # save_data(emision_data) #DEBUG # print "nombre emissions liées: %s" % nbre_emissions #DEBUG result = re.findall(r'(?i)<a href=\'/video/emissions/(.*?)/episode/\?cmedia=(\d+)\'>\s+<img src=\'(.*?)\' alt="Photo : (.*?)" title="Photo : (.*?)" />', emision_data) # print "nombre emissions liées trouvées: %s" % len(result) #DEBUG for i in result: # print i[4] #DEBUG #ba = get_media_link(i[0]) print i[2] if xbmcplugin.getSetting("hdimage") == "true": image = i[2].replace("cx_120_110/o_overlayEmissions-P2C-120.png_1_c", "r_760_x" ).replace("cx_120_110/o_overlayEmissions-MerciQui-120.png_1_c", "r_760_x" ).replace("cx_120_110/o_overlayEmissions-LaMinute-120.png_1_c", "r_760_x" ).replace("cx_120_110/o_overlayEmissions-D2DVD-120.png_1_c", "r_760_x" ).replace("cx_120_110/o_overlayEmissions-TES-120.png_1_c", "r_760_x" ).replace("cx_120_110/o_overlayEmissions-FauxR-120.png_1_c", "r_760_x" ) else: image = i[2] print image c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string( i[4] ) ) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % ( urllib.quote_plus( "cmedia=%s" % i[0] ), urllib.quote_plus( local_trailer ) , quality) if not os.path.exists(local_trailer):c_items += [ ( "Télécharger", "XBMC.RunScript(%s,%s)" % ( script, args ) ) ] else : c_items += [ ( "jouer en local", "xbmc.PlayMedia(%s)" % local_trailer) ] addDir(i[4], i[1],5,image, c_items ) if all_BA: # print "test all ba" #DEBUG if url_all_video: match = re.search(r"(\d+) bandes-annonces", video_data) if match: nb_ba = match.group(1) else: nb_ba = "" # print "nombre BA: %s" % nb_ba #DEBUG match = re.search("-- CONSTRAINT RIGHT COLUMN -->(.*?)Autres bandes-annonces", video_data, re.DOTALL) if match: video_data = match.group(1) else: video_data = "" #save_data(video_data) #DEBUG #result = re.findall(r"(?i)<a href=\'/video/player_gen_cmedia=(.*?)&cfilm=(.*?).html\'>\s+", video_data) #DEBUG result = re.findall(r"""<a href=\'/video/player_gen_cmedia=(.*?)&cfilm=(.*?).html\'>\s+<img src=\'(.*?)\' alt="Photo : (.*?)" title="Photo : (.*?)" />\s+</a>""", video_data) # print "liste BA: %s ba trouvées " % len(result) #DEBUG # print "#####################liste des BA##########################" #DEBUG for i in result: # print i[4] #DEBUG if xbmcplugin.getSetting("hdimage") == "true": image = i[2].replace( "cx_120_96/b_1_x/o_play.png_5_se" , "r_760_x" ) else: image = i[2] c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string( i[4] ) ) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % ( urllib.quote_plus( "cmedia=%s" % i[0] ), urllib.quote_plus( local_trailer ) , quality) if not os.path.exists(local_trailer):c_items += [ ( "Télécharger", "XBMC.RunScript(%s,%s)" % ( script, args ) ) ] else : c_items += [ ( "jouer en local", "xbmc.PlayMedia(%s)" % local_trailer) ] addDir(i[4], i[0],5,image, c_items ) # print "#####################liste des BA FIN######################" #DEBUG return True
def get_film_list( url , database = False): catalogue = [] page_data = get_html_source( url ) count = 0 pager = 1 try: nbpage = int(re.findall( '<span class="navcurrpage">.*</span>(.*?)</li>', page_data )[0].strip( " / ")) except: nbpage = "error" print "impossible de trouver le nb de page" print_exc() print "nb pages: %s" % nbpage try: total_item = int(re.findall( '<p class="extrazone">.* sur (.*?) r.*sultats</p>', page_data )[0].strip( " / ")) except: total_item = "error" print "impossible de trouver le nb d'item" print_exc() print "nb d'items: %s" % total_item #progress bar: #dp = xbmcgui.DialogProgress() #dp.create("Update Database") while pager <= nbpage and nbpage != "error" and pager <= [5,10,20,30,999][int(xbmcplugin.getSetting("page_limit"))]: if not pager == 1: current_url= "%s?page=%s" % (url , pager) print "page %s: %s" % ( pager , current_url ) page_data = get_html_source( current_url ) try: #print page_data match = re.search( '<a href="/video/emissions/(.*?)/episode/\?cmedia=(.*?)">\s+<img src="(.*?)" alt="" />\s+</a>\s+</div>\s+<div style="float:left; position:relative; width:320px; height:220px; padding:95px 0 0 35px; overflow:hidden;">\s+<h2 class="fs18" style="color:#FFFFFF;">(.*?)</h2>', page_data ) if match: film = {} count = count+1 film["type"] = match.group(1) film["poster"] = match.group(3) film["name"] = match.group(4) film["id_allo"] = match.group(2) film["id_media"] = match.group(2) if xbmcplugin.getSetting("hdimage") == "true": film["poster"] = film["poster"].replace( "c_120_160/b_1_x/o_play.png_5_se" , "r_760_x" ).replace("cx_120_96/b_1_x/o_play.png_5_se", "r_760_x" ).replace("c_120_120/b_1_x/o_play.png_5_se", "r_760_x" ) film["poster"] = film["poster"].replace("cx_120_113/o_overlayEmissions-P2C-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-MerciQui-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-LaMinute-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-D2DVD-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-TES-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-FauxR-120.png_1_c", "r_760_x" ) catalogue.append(film) try: c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string(film["name"] ) ) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % ( urllib.quote_plus( "cmedia=%s" % film["id_media"] ), urllib.quote_plus( local_trailer ) , quality) if not os.path.exists(local_trailer):c_items += [ ( "Télécharger", "XBMC.RunScript(%s,%s)" % ( script, args ) ) ] else : c_items += [ ( "jouer en local", "xbmc.PlayMedia(%s)" % local_trailer) ] addDir(film["name"], film["id_media"],5,film["poster"], c_items ) except: print_exc() print "#######trouvé########trouvé############trouvé##########trouvé###########" MEDIA=re.compile( '<div class="mainzone">(.*?)<div class="spacer">', re.DOTALL ).findall(page_data) #save_data(page_data) for i in MEDIA: if database: film = get_film_info(id_allo) else: film = {} #print i film["type"] = url.split("/")[4] if film["type"] == "bandes-annonces": film["type"] = "film" elif film["type"] == "series": film["type"] = "serie" print "###################type#############################" print film["type"] count = count+1 ratio= int(100*float(count)/float(total_item)) if film["type"] == "serie": match = re.search( "<span class=\'bold\'>(.*?)</span>(.*?)\s+</a>", i ) #( "<span class='bold'>(.*?)</a>", i ) elif film["type"] == "interviews": match = re.search( "<span class=\'bold\'>\s+(.*?)\s+</span>\s+(.*?)<br />", i ) else : match = re.search( "<span class='bold'>(.*?)</span>", i ) print match save_data(i) if match : if film["type"] == "serie" : film["name"] = match.group(1) + " " + match.group(2) #match.group(1).replace("</span>"," ") elif film["type"] == "interviews": film["name"] = match.group(1) + match.group(2) else : film["name"] = match.group(1) else: film["name"] = "" print "récupération info %s (%s/%s): %s" % ( film["type"] , count , total_item , film["name"] ) #dp.update(ratio , "récupération info %s (%s/%s)" % ( film["type"], count , total_item ), film["name"]) # if dp.iscanceled() : # dp.close() # break match = re.search( "<a href='/video/player_gen_cmedia=(.*?)&c%s=(.*?).html'" % film["type"] , i ) if match: film["id_allo"] = match.group(2) film["id_media"] = match.group(1) #print "############TEST###############" + "test id:%s %s" % (match.group(1) , match.group(2)) else : match = re.search( "cmedia=(.*?)'" , i ) if match: film["id_allo"] = film["id_media"] = match.group(1) else: film["id_allo"] = film["id_media"] = "" match = re.search( "<p>Date de sortie :\s+(.*?)</p>", i ) if match: print "sortie: %s " % match.group(1).replace("/",".") film["sortie"] = match.group(1).replace("/",".") try: film["poster"] = re.findall( "<img src='(.*?)'", i )[0] except: film["poster"] = "" print "hd image: %s" % xbmcplugin.getSetting("hdimage") if xbmcplugin.getSetting("hdimage") == "true": film["poster"] = film["poster"].replace( "c_120_160/b_1_x/o_play.png_5_se" , "r_760_x" ).replace("cx_120_96/b_1_x/o_play.png_5_se", "r_760_x" ).replace("c_120_120/b_1_x/o_play.png_5_se", "r_760_x" ) film["poster"] = film["poster"].replace("cx_120_113/o_overlayEmissions-P2C-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-MerciQui-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-LaMinute-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-D2DVD-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-TES-120.png_1_c", "r_760_x" ).replace("cx_120_113/o_overlayEmissions-FauxR-120.png_1_c", "r_760_x" ) catalogue.append(film) if film["type"] == "film": if xbmcplugin.getSetting("date_sortie") == "true" : ajout_sortie = "[CR]" + film["sortie"] else : ajout_sortie = "" addDir(film["name"] + ajout_sortie ,"%s##%s" % (film["poster"] , film["id_allo"]),2,film["poster"], sortie=film["sortie"]) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) #xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_NONE) else : #print "image:%s " % film["poster"] c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string(film["name"] ) ) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % ( urllib.quote_plus( "cmedia=%s" % film["id_media"] ), urllib.quote_plus( local_trailer ) , quality) if not os.path.exists(local_trailer):c_items += [ ( "Télécharger", "XBMC.RunScript(%s,%s)" % ( script, args ) ) ] else : c_items += [ ( "jouer en local", "xbmc.PlayMedia(%s)" % local_trailer) ] addDir(film["name"], film["id_media"],5,film["poster"], c_items ) except: print "probleme de récupération de la liste de film" print_exc() pager = pager + 1 #dp.close() print "total movies = %s" % count return catalogue
xbmcplugin.setPluginCategory(int(sys.argv[1]), name) if load_DB( name ) == "": create_DB( url , name) else: data=load_DB( name ) for film in data: if film["type"] == "film": if xbmcplugin.getSetting("date_sortie") == "true" : ajout_sortie = "[CR]" + film["sortie"] else : ajout_sortie = "" addDir(film["name"] + ajout_sortie ,"%s##%s" % (film["poster"] , film["id_allo"]),2,film["poster"], sortie=film["sortie"]) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) #xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_NONE) else : #print "image:%s " % film["poster"] c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string(film["name"] ) ) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % ( urllib.quote_plus( "cmedia=%s" % film["id_media"] ), urllib.quote_plus( local_trailer ) , quality) if not os.path.exists(local_trailer):c_items += [ ( "Télécharger", "XBMC.RunScript(%s,%s)" % ( script, args ) ) ] else : c_items += [ ( "jouer en local", "xbmc.PlayMedia(%s)" % local_trailer) ] addDir(film["name"], film["id_media"],5,film["poster"], c_items ) if mode == 2: #menu bande-annonce de film + liens contenus liées # print 'name : %s' % name #DEBUG poster = url.split("##")[0] url = url.split("##")[1] film = get_film_info(url, BA = True) for ba in film["Bande-annonces"]:
Language.getLocalizedString(30025)) local_artist = get_local_artist() count_artist_local = len(local_artist) artist_count = 0 download_count = 0 #print local_artist #DEBUG for artist in local_artist: print "SEARCH: %s" % artist["name"] artist_count = float(artist_count) + 1 #print "artist count: %s" % artist_count #DEBUG percent = (artist_count / count_artist_local) * 100 #print percent #DEBUG DIALOG_PROGRESS.update( percent, Language.getLocalizedString(30026) + translate_string(artist["name"]), ) #print urllib.unquote_plus(artist["name"]) try: local_album_list = get_local_album(artist["name"]) except: local_album_list = [] print "erreur recherche album %s" % artist["name"] print_exc() #print local_album_list #DEBUG for album in local_album_list: print "SEARCH: %s - %s" % (artist["name"], album["title"]) DIALOG_PROGRESS.update( percent, "%s%s" % (Language.getLocalizedString(30026), translate_string(artist["name"])), "%s%s" % (Language.getLocalizedString(30027), album["title"]))
def get_film_info(id_allo, BA=False, all_BA=False, emissions_liees=False, interviews=False): film = {} film_url = "http://www.allocine.fr/film/fichefilm_gen_cfilm=%s.html" % id_allo film_data = get_html_source(film_url) #save_data(film_data) #DEBUG try: media_list = re.findall( '<a href="/video/player_gen_cmedia=(.*?)&cfilm=.*.html"><b>', film_data) except: print_exc() media_list = "" match = re.search( r'<a class="fs11 underline" href="(.*)"><img class="ico icoticka" alt=" " width="0" height="0" src="http://images.allocine.fr/commons/empty.gif"/><span>Toutes les vid\xc3\xa9os</span></a>', film_data, re.IGNORECASE) if match: url_all_video = match.group(1) else: url_all_video = "" # print "url_video: %s" % url_all_video #DEBUG if BA: BA_list = [] if media_list: for id_media in media_list: BA_list.append(get_media_link(id_media)) film["Bande-annonces"] = BA_list return film if emissions_liees or all_BA or interviews: # print "test liens toutes vidéos" #DEBUG if not url_all_video == "": # print "url toutes vidéos trouvé" #DEBUG video_data = get_html_source("http://www.allocine.fr" + url_all_video) # save_data(video_data) #DEBUG if interviews: # print "test interviews liées" #DEBUG match = re.search( r"<h2>\s+(\d+) Interviews li\xc3\xa9es \xc3\xa0 ce film\s+</h2>(.*?)<h2>Autres bandes-annonces</h2>", video_data, re.DOTALL | re.IGNORECASE) if match: nbre_interviews = match.group(1) interviews_data = match.group(2) else: dialog.ok("Interviews Allociné", "aucune interview liée") return False nbre_interviews = "" interviews_data = "" # save_data(interviews_data) #DEBUG # print "nombre interviews liées: %s" % nbre_interviews #DEBUG result = re.findall( r'(?i)<a href=\'/film/fichefilm-\d+/interviews/\?cmedia=(\d+)\'>\s+<img src=\'(.*?)\' alt="Photo : (.*?)" title="Photo : (.*?)" />\s+</a>', interviews_data) # print "nombre emissions liées trouvées: %s" % len(result) #DEBUG for i in result: # print i[3] , i[1]#DEBUG #ba = get_media_link(i[0]) print i[2] if xbmcplugin.getSetting("hdimage") == "true": image = i[1].replace("cx_120_96/b_1_x/o_play.png_5_se", "r_760_x") else: image = i[1] print image c_items = [] local_trailer = os.path.join(trailer_dir, "%s.flv" % translate_string(i[3])) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % (urllib.quote_plus( "cmedia=%s" % i[0]), urllib.quote_plus(local_trailer), quality) if not os.path.exists(local_trailer): c_items += [("Télécharger", "XBMC.RunScript(%s,%s)" % (script, args))] else: c_items += [("jouer en local", "xbmc.PlayMedia(%s)" % local_trailer)] addDir(i[3], i[0], 5, image, c_items) if emissions_liees: # print "test emisions liées" #DEBUG match = re.search( r"<h2>(\d+) \xc3\xa9missions li\xc3\xa9es</h2>(.*?)<h2>Autres bandes-annonces</h2>", video_data, re.DOTALL | re.IGNORECASE) if match: nbre_emissions = match.group(1) emision_data = match.group(2) else: dialog.ok("Emissions Allociné", "aucune emission liée") return False nbre_emissions = "" emision_data = "" # save_data(emision_data) #DEBUG # print "nombre emissions liées: %s" % nbre_emissions #DEBUG result = re.findall( r'(?i)<a href=\'/video/emissions/(.*?)/episode/\?cmedia=(\d+)\'>\s+<img src=\'(.*?)\' alt="Photo : (.*?)" title="Photo : (.*?)" />', emision_data) # print "nombre emissions liées trouvées: %s" % len(result) #DEBUG for i in result: # print i[4] #DEBUG #ba = get_media_link(i[0]) print i[2] if xbmcplugin.getSetting("hdimage") == "true": image = i[2].replace( "cx_120_110/o_overlayEmissions-P2C-120.png_1_c", "r_760_x").replace( "cx_120_110/o_overlayEmissions-MerciQui-120.png_1_c", "r_760_x" ).replace( "cx_120_110/o_overlayEmissions-LaMinute-120.png_1_c", "r_760_x").replace( "cx_120_110/o_overlayEmissions-D2DVD-120.png_1_c", "r_760_x" ).replace( "cx_120_110/o_overlayEmissions-TES-120.png_1_c", "r_760_x" ).replace( "cx_120_110/o_overlayEmissions-FauxR-120.png_1_c", "r_760_x") else: image = i[2] print image c_items = [] local_trailer = os.path.join(trailer_dir, "%s.flv" % translate_string(i[4])) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % (urllib.quote_plus( "cmedia=%s" % i[0]), urllib.quote_plus(local_trailer), quality) if not os.path.exists(local_trailer): c_items += [("Télécharger", "XBMC.RunScript(%s,%s)" % (script, args))] else: c_items += [("jouer en local", "xbmc.PlayMedia(%s)" % local_trailer)] addDir(i[4], i[1], 5, image, c_items) if all_BA: # print "test all ba" #DEBUG if url_all_video: match = re.search(r"(\d+) bandes-annonces", video_data) if match: nb_ba = match.group(1) else: nb_ba = "" # print "nombre BA: %s" % nb_ba #DEBUG match = re.search( "-- CONSTRAINT RIGHT COLUMN -->(.*?)Autres bandes-annonces", video_data, re.DOTALL) if match: video_data = match.group(1) else: video_data = "" #save_data(video_data) #DEBUG #result = re.findall(r"(?i)<a href=\'/video/player_gen_cmedia=(.*?)&cfilm=(.*?).html\'>\s+", video_data) #DEBUG result = re.findall( r"""<a href=\'/video/player_gen_cmedia=(.*?)&cfilm=(.*?).html\'>\s+<img src=\'(.*?)\' alt="Photo : (.*?)" title="Photo : (.*?)" />\s+</a>""", video_data) # print "liste BA: %s ba trouvées " % len(result) #DEBUG # print "#####################liste des BA##########################" #DEBUG for i in result: # print i[4] #DEBUG if xbmcplugin.getSetting("hdimage") == "true": image = i[2].replace("cx_120_96/b_1_x/o_play.png_5_se", "r_760_x") else: image = i[2] c_items = [] local_trailer = os.path.join(trailer_dir, "%s.flv" % translate_string(i[4])) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % (urllib.quote_plus("cmedia=%s" % i[0]), urllib.quote_plus(local_trailer), quality) if not os.path.exists(local_trailer): c_items += [("Télécharger", "XBMC.RunScript(%s,%s)" % (script, args))] else: c_items += [("jouer en local", "xbmc.PlayMedia(%s)" % local_trailer)] addDir(i[4], i[0], 5, image, c_items) # print "#####################liste des BA FIN######################" #DEBUG return True
def get_film_list(url, database=False): catalogue = [] page_data = get_html_source(url) count = 0 pager = 1 try: nbpage = int( re.findall('<span class="navcurrpage">.*</span>(.*?)</li>', page_data)[0].strip(" / ")) except: nbpage = "error" print "impossible de trouver le nb de page" print_exc() print "nb pages: %s" % nbpage try: total_item = int( re.findall('<p class="extrazone">.* sur (.*?) r.*sultats</p>', page_data)[0].strip(" / ")) except: total_item = "error" print "impossible de trouver le nb d'item" print_exc() print "nb d'items: %s" % total_item #progress bar: #dp = xbmcgui.DialogProgress() #dp.create("Update Database") while pager <= nbpage and nbpage != "error" and pager <= [ 5, 10, 20, 30, 999 ][int(xbmcplugin.getSetting("page_limit"))]: if not pager == 1: current_url = "%s?page=%s" % (url, pager) print "page %s: %s" % (pager, current_url) page_data = get_html_source(current_url) try: #print page_data match = re.search( '<a href="/video/emissions/(.*?)/episode/\?cmedia=(.*?)">\s+<img src="(.*?)" alt="" />\s+</a>\s+</div>\s+<div style="float:left; position:relative; width:320px; height:220px; padding:95px 0 0 35px; overflow:hidden;">\s+<h2 class="fs18" style="color:#FFFFFF;">(.*?)</h2>', page_data) if match: film = {} count = count + 1 film["type"] = match.group(1) film["poster"] = match.group(3) film["name"] = match.group(4) film["id_allo"] = match.group(2) film["id_media"] = match.group(2) if xbmcplugin.getSetting("hdimage") == "true": film["poster"] = film["poster"].replace( "c_120_160/b_1_x/o_play.png_5_se", "r_760_x").replace( "cx_120_96/b_1_x/o_play.png_5_se", "r_760_x").replace( "c_120_120/b_1_x/o_play.png_5_se", "r_760_x") film["poster"] = film["poster"].replace( "cx_120_113/o_overlayEmissions-P2C-120.png_1_c", "r_760_x" ).replace( "cx_120_113/o_overlayEmissions-MerciQui-120.png_1_c", "r_760_x" ).replace( "cx_120_113/o_overlayEmissions-LaMinute-120.png_1_c", "r_760_x").replace( "cx_120_113/o_overlayEmissions-D2DVD-120.png_1_c", "r_760_x" ).replace( "cx_120_113/o_overlayEmissions-TES-120.png_1_c", "r_760_x" ).replace( "cx_120_113/o_overlayEmissions-FauxR-120.png_1_c", "r_760_x") catalogue.append(film) try: c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string(film["name"])) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % ( urllib.quote_plus("cmedia=%s" % film["id_media"]), urllib.quote_plus(local_trailer), quality) if not os.path.exists(local_trailer): c_items += [("Télécharger", "XBMC.RunScript(%s,%s)" % (script, args))] else: c_items += [("jouer en local", "xbmc.PlayMedia(%s)" % local_trailer)] addDir(film["name"], film["id_media"], 5, film["poster"], c_items) except: print_exc() print "#######trouvé########trouvé############trouvé##########trouvé###########" MEDIA = re.compile( '<div class="mainzone">(.*?)<div class="spacer">', re.DOTALL).findall(page_data) #save_data(page_data) for i in MEDIA: if database: film = get_film_info(id_allo) else: film = {} #print i film["type"] = url.split("/")[4] if film["type"] == "bandes-annonces": film["type"] = "film" elif film["type"] == "series": film["type"] = "serie" print "###################type#############################" print film["type"] count = count + 1 ratio = int(100 * float(count) / float(total_item)) if film["type"] == "serie": match = re.search( "<span class=\'bold\'>(.*?)</span>(.*?)\s+</a>", i) #( "<span class='bold'>(.*?)</a>", i ) elif film["type"] == "interviews": match = re.search( "<span class=\'bold\'>\s+(.*?)\s+</span>\s+(.*?)<br />", i) else: match = re.search("<span class='bold'>(.*?)</span>", i) print match save_data(i) if match: if film["type"] == "serie": film["name"] = match.group(1) + " " + match.group( 2) #match.group(1).replace("</span>"," ") elif film["type"] == "interviews": film["name"] = match.group(1) + match.group(2) else: film["name"] = match.group(1) else: film["name"] = "" print "récupération info %s (%s/%s): %s" % ( film["type"], count, total_item, film["name"]) #dp.update(ratio , "récupération info %s (%s/%s)" % ( film["type"], count , total_item ), film["name"]) # if dp.iscanceled() : # dp.close() # break match = re.search( "<a href='/video/player_gen_cmedia=(.*?)&c%s=(.*?).html'" % film["type"], i) if match: film["id_allo"] = match.group(2) film["id_media"] = match.group(1) #print "############TEST###############" + "test id:%s %s" % (match.group(1) , match.group(2)) else: match = re.search("cmedia=(.*?)'", i) if match: film["id_allo"] = film["id_media"] = match.group(1) else: film["id_allo"] = film["id_media"] = "" match = re.search("<p>Date de sortie :\s+(.*?)</p>", i) if match: print "sortie: %s " % match.group(1).replace("/", ".") film["sortie"] = match.group(1).replace("/", ".") try: film["poster"] = re.findall("<img src='(.*?)'", i)[0] except: film["poster"] = "" print "hd image: %s" % xbmcplugin.getSetting("hdimage") if xbmcplugin.getSetting("hdimage") == "true": film["poster"] = film["poster"].replace( "c_120_160/b_1_x/o_play.png_5_se", "r_760_x").replace( "cx_120_96/b_1_x/o_play.png_5_se", "r_760_x").replace( "c_120_120/b_1_x/o_play.png_5_se", "r_760_x") film["poster"] = film["poster"].replace( "cx_120_113/o_overlayEmissions-P2C-120.png_1_c", "r_760_x" ).replace( "cx_120_113/o_overlayEmissions-MerciQui-120.png_1_c", "r_760_x" ).replace( "cx_120_113/o_overlayEmissions-LaMinute-120.png_1_c", "r_760_x").replace( "cx_120_113/o_overlayEmissions-D2DVD-120.png_1_c", "r_760_x" ).replace( "cx_120_113/o_overlayEmissions-TES-120.png_1_c", "r_760_x" ).replace( "cx_120_113/o_overlayEmissions-FauxR-120.png_1_c", "r_760_x") catalogue.append(film) if film["type"] == "film": if xbmcplugin.getSetting("date_sortie") == "true": ajout_sortie = "[CR]" + film["sortie"] else: ajout_sortie = "" addDir(film["name"] + ajout_sortie, "%s##%s" % (film["poster"], film["id_allo"]), 2, film["poster"], sortie=film["sortie"]) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) #xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_NONE) else: #print "image:%s " % film["poster"] c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string(film["name"])) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % ( urllib.quote_plus("cmedia=%s" % film["id_media"]), urllib.quote_plus(local_trailer), quality) if not os.path.exists(local_trailer): c_items += [("Télécharger", "XBMC.RunScript(%s,%s)" % (script, args))] else: c_items += [("jouer en local", "xbmc.PlayMedia(%s)" % local_trailer)] addDir(film["name"], film["id_media"], 5, film["poster"], c_items) except: print "probleme de récupération de la liste de film" print_exc() pager = pager + 1 #dp.close() print "total movies = %s" % count return catalogue
ajout_sortie = "" addDir(film["name"] + ajout_sortie, "%s##%s" % (film["poster"], film["id_allo"]), 2, film["poster"], sortie=film["sortie"]) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) #xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_NONE) else: #print "image:%s " % film["poster"] c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string(film["name"])) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % (urllib.quote_plus( "cmedia=%s" % film["id_media"]), urllib.quote_plus(local_trailer), quality) if not os.path.exists(local_trailer): c_items += [("Télécharger", "XBMC.RunScript(%s,%s)" % (script, args))] else: c_items += [("jouer en local", "xbmc.PlayMedia(%s)" % local_trailer)] addDir(film["name"], film["id_media"], 5, film["poster"], c_items) if mode == 2: #menu bande-annonce de film + liens contenus liées # print 'name : %s' % name #DEBUG
def _report_hook( count, blocksize, totalsize ): percent = int( float( count * blocksize * 100 ) / totalsize ) strProgressBar = str( percent ) #print percent #DEBUG DIALOG_PROGRESS.update( tvcount , "Searching: %s " % translate_string( name ) , "Downloading: %s" % percent )
else: xbmcgui.Dialog().ok("Error" , "Can't get logo from this view" ) else: print "### Starting Bulk Mode" DIALOG_PROGRESS.create( "Logo Downloader in action ..." , "Getting info ..." ) TVshow_list = listing() if TVshow_list and base_info: total_tvshow = len(TVshow_list) tvcount = 0 total_logo = 0 downloaded = 0 for TVshow in TVshow_list: tvcount = tvcount + 1 ratio = int (float( tvcount * 100 ) / total_tvshow ) print "### Checking %s TVshow: %s id: %s" % ( ratio , translate_string( TVshow["name"] ) , TVshow["id"] ) if TVshow["id"][0:2] == "tt" or TVshow["id"] == "": print "### IMDB id found in database(%s), checking for nfo" % TVshow["id"] try: tvid = get_nfo_id( TVshow["path"] ) except: print "### Error checking for nfo: %stvshow.nfo" % TVshow["path"] tvid = TVshow["id"] print_exc() else : tvid = TVshow["id"] DIALOG_PROGRESS.update( ratio , "Searching: %s " % translate_string( TVshow["name"] ) , tvid ) if ( DIALOG_PROGRESS.iscanceled() ): break if tvid == "" : print "### no id, skipping ..." logo_url = False if os.path.isfile(os.path.join( TVshow["path"] , "logo.png").replace("\\\\" , "\\").encode("utf-8")): print "### Logo.png already exist, skiping ..."
get_emissions_list() save_data(liste_chaines, chaine_path) print liste_chaines save_data(liste_emissions, emissions_path) for chaine in liste_chaines: addDir(chaine, chaine, 1, "") if mode == 1: liste_emissions = load_data(emissions_path) for emission in liste_emissions: if emission["chaine"] == url: addDir( emission["nom"], translate_string(emission["nom"].replace("Î", "i").replace( "ô", "o").replace("è", "e")).replace(" ", "-").replace("'", "-").lower(), 2, "") if mode == 2: video = get_video_url(url) try: playableVideoItem = xbmcgui.ListItem(video["titre"], path=video["link"]) playableVideoItem.setThumbnailImage(video["image"]) print "###%s###" % video["link"] xbmc.Player().play(video["link"], playableVideoItem, False) except: xbmcgui.Dialog().ok("Plugin Pluzz.fr", "Impossible de lire la vidéo")
if mode==None or url==None or len(url)<1: #menu principal #initialisation des listes liste_chaines = [] liste_emissions = [] get_emissions_list() save_data( liste_chaines , chaine_path ) print liste_chaines save_data( liste_emissions , emissions_path ) for chaine in liste_chaines: addDir(chaine,chaine,1,"" ) if mode == 1: liste_emissions = load_data( emissions_path ) for emission in liste_emissions: if emission["chaine"] == url: addDir(emission["nom"] , translate_string(emission["nom"].replace("Î","i").replace("ô","o").replace("è","e")).replace(" ","-").replace("'","-").lower() ,2,"" ) if mode == 2: video = get_video_url(url) try: playableVideoItem = xbmcgui.ListItem( video["titre"] , path = video["link"] ) playableVideoItem.setThumbnailImage(video["image"]) print "###%s###" % video["link"] xbmc.Player().play( video["link"] , playableVideoItem , False ) except: xbmcgui.Dialog().ok("Plugin Pluzz.fr" , "Impossible de lire la vidéo") OK = False end_of_directory( OK )
OK = False if mode == 5: DIALOG_PROGRESS.create( Language.getLocalizedString(30024), Language.getLocalizedString(30025) ) local_artist = get_local_artist() count_artist_local = len(local_artist) artist_count = 0 download_count = 0 #print local_artist #DEBUG for artist in local_artist: print "SEARCH: %s" % artist["name"] artist_count = float(artist_count) + 1 #print "artist count: %s" % artist_count #DEBUG percent = (artist_count / count_artist_local) * 100 #print percent #DEBUG DIALOG_PROGRESS.update( percent , Language.getLocalizedString(30026) + translate_string(artist["name"]), ) #print urllib.unquote_plus(artist["name"]) try: local_album_list = get_local_album(artist["name"]) except: local_album_list = [] print "erreur recherche album %s" % artist["name"] print_exc() #print local_album_list #DEBUG for album in local_album_list: print "SEARCH: %s - %s" % (artist["name"] , album["title"]) DIALOG_PROGRESS.update( percent , "%s%s" % (Language.getLocalizedString(30026) , translate_string(artist["name"])) , "%s%s" % (Language.getLocalizedString(30027) , album["title"]) ) test_album = find_cdart2(album) #print "dico album: " , album #DEBUG if not test_album == [] : print "####################################################FOUND####################################################" download_cdart( test_album[0] , album )
xbmcplugin.setPluginCategory(int(sys.argv[1]), name) if load_DB( name ) == "": create_DB( url , name) else: data=load_DB( name ) for film in data: if film["type"] == "film": if __settings__.getSetting("date_sortie") == "true" : ajout_sortie = "[CR]" + film["sortie"] else : ajout_sortie = "" addDir(film["name"] + ajout_sortie ,"%s##%s" % (film["poster"] , film["id_allo"]),2,film["poster"], sortie=film["sortie"]) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) #xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_NONE) else : #print "image:%s " % film["poster"] c_items = [] local_trailer = os.path.join( trailer_dir, "%s.flv" % translate_string(film["name"] ) ) script = "special://home/plugins/video/Bande-Annonce Allocine/resources/lib/downloader.py" args = "%s&%s&%s" % ( urllib.quote_plus( "cmedia=%s" % film["id_media"] ), urllib.quote_plus( local_trailer ) , quality) if not os.path.exists(local_trailer):c_items += [ ( "Télécharger", "XBMC.RunScript(%s,%s)" % ( script, args ) ) ] else : c_items += [ ( "jouer en local", "xbmc.PlayMedia(%s)" % local_trailer) ] addDir(film["name"], film["id_media"],5,film["poster"], c_items ) if mode == 2: #menu bande-annonce de film + liens contenus liées # print 'name : %s' % name #DEBUG poster = url.split("##")[0] url = url.split("##")[1] film = get_film_info(url, BA = True) for ba in film["Bande-annonces"]: