forked from tvalacarta/tvalacarta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eitb.py
115 lines (95 loc) · 3.81 KB
/
eitb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
#------------------------------------------------------------
# tvalacarta - XBMC Plugin
# Canal para EITB
# http://blog.tvalacarta.info/plugin-xbmc/tvalacarta/
#------------------------------------------------------------
import urlparse,re
import urllib
from core import logger
from core import scrapertools
from core.item import Item
logger.info("[eitb.py] init")
DEBUG = False
CHANNELNAME = "eitb"
def isGeneric():
return True
def mainlist(item):
logger.info("[eitb.py] mainlist")
itemlist=[]
url = 'http://www.eitb.tv/es/'
# Descarga la página
data = scrapertools.cachePage(url)
patron = "<li[^>]*><a href=\"\" onclick\=\"setPlaylistId\('(\d+)','([^']+)','([^']+)'\)\;"
matches = re.compile(patron,re.DOTALL).findall(data)
if DEBUG: scrapertools.printMatches(matches)
for id,titulo,titulo2 in matches:
scrapedtitle = titulo
if titulo!=titulo2:
scrapedtitle = scrapedtitle + " - " + titulo2
scrapedurl = "http://www.eitb.tv/es/get/playlist/"+id
scrapedthumbnail = ""
scrapedplot = ""
if (DEBUG): logger.info("title=["+scrapedtitle+"], url=["+scrapedurl+"], thumbnail=["+scrapedthumbnail+"]")
itemlist.append( Item(channel=CHANNELNAME, title=scrapedtitle , action="episodios" , url=scrapedurl, thumbnail=scrapedthumbnail, plot=scrapedplot , folder=True) )
return itemlist
def episodios(item):
logger.info("[eitb.py] episodios")
itemlist=[]
# Descarga la página
data = scrapertools.cachePage(item.url)
logger.info(data)
episodios_json = load_json(data)
if episodios_json == None : episodios_json = []
itemlist = []
for video in episodios_json['videos']:
scrapedthumbnail = video['thumbnailURL']
if scrapedthumbnail is None:
scrapedthumbnail = ""
logger.info("scrapedthumbnail="+scrapedthumbnail)
scrapedtitle = video['name']#.encode("utf-8",errors="ignore")
#scrapedtitle = unicode( scrapedtitle , "iso-8859-1" , errors="ignore").encode("utf-8")
scrapedplot = video['shortDescription']#.encode("utf8","ignore")
try:
scrapedtitle = video['customFields']['name_c']#.encode("utf-8","ignore")
scrapedplot = video['customFields']['shortdescription_c']#.encode("utf-8","ignore")
except:
pass
scrapedurl = "http://www.eitb.tv/es/#/video/"+str(video['id'])
if (DEBUG): logger.info("title=["+scrapedtitle+"], url=["+scrapedurl+"], thumbnail=["+scrapedthumbnail+"]")
itemlist.append( Item(channel=CHANNELNAME, title=scrapedtitle , action="play" , server="eitb", url=scrapedurl, thumbnail=scrapedthumbnail, plot=scrapedplot , folder=False) )
return itemlist
def load_json(data):
# callback to transform json string values to utf8
def to_utf8(dct):
rdct = {}
for k, v in dct.items() :
if isinstance(v, (str, unicode)) :
rdct[k] = v.encode('utf8', 'ignore')
else :
rdct[k] = v
return rdct
try :
from lib import simplejson
json_data = simplejson.loads(data, object_hook=to_utf8)
return json_data
except:
try:
import json
json_data = json.loads(data, object_hook=to_utf8)
return json_data
except:
import sys
for line in sys.exc_info():
logger.error("%s" % line)
def test():
# Al entrar sale una lista de programas
programas_items = mainlist(Item())
if len(programas_items)==0:
print "Al entrar a mainlist no sale nada"
return False
episodios_items = episodios(programas_items[0])
if len(episodios_items)==0:
print "El programa "+programas_items[0].title+" no tiene episodios"
return False
return True