Commit 33a5d25b authored by Jonas's avatar Jonas

Respect DTD

parent 21c7f1c1
......@@ -182,7 +182,7 @@ def get_epg_data(root, channel_uid, channel_slug, start_time):
for time_slot in range(10):
epgurl = EPG_URL + "%s/%s/" % (channel_uid, start_time+time_slot*7200)
dic_epg = do_request(epgurl)
logging.info("%d programes (%d au total)"%(len(dic_epg), len(epg_progs)))
logging.info("Récupération de %d programes (il y en avait %d avant cette requête)"%(len(dic_epg), len(epg_progs)))
# don't handle fake results
if len(dic_epg)==1:
for k,v in dic_epg.items():
......@@ -209,17 +209,20 @@ def get_epg_data(root, channel_uid, channel_slug, start_time):
# Add Description
# desc = ET.Element('desc')
# desc.text = str( obj.get('desc') )
# check if need description depending category
if 'category' in obj and obj.get('category') not in [0, 5, 6, 9, 10, 12, 13, 14, 19, 20, 22, 31]:
# Ok let's check if we have a description
epg_id = obj.get('id')
prog_url = PROG_URL + "%s" % (epg_id)
dic_prog = do_request(prog_url)
if 'desc' in dic_prog:
desc = ET.Element('desc')
desc.attrib['lang'] = "fr"
desc.text = dic_prog.get('desc')
cur_prog.append(desc)
else:
logging.debug("Pas de description trouvée")
# Add category
if 'picture' in obj:
icon = ET.Element('icon')
icon.attrib['src'] = B_URL+obj.get('picture')
cur_prog.append(icon)
if 'episode_number' in obj and 'season_number' in obj:
episode = ET.Element('episode-num')
episode.attrib['system'] = "xmltv_ns"
episode.text="%d.%d.0" % (obj.get('season_number')-1,
obj.get('episode_number')-1)
cur_prog.append(episode)
if 'category_name' in obj:
if obj.get('category') in categories_en :
#traduction de la catégorie en anglais pour le filtre de hts
......@@ -239,19 +242,18 @@ def get_epg_data(root, channel_uid, channel_slug, start_time):
length.attrib['units'] = "seconds"
length.text = str(obj.get('duration'))
cur_prog.append(length)
# check if need description depending category
if 'category' in obj and obj.get('category') not in [0, 5, 6, 9, 10, 12, 13, 14, 19, 20, 22, 31]:
# Ok let's check if we have a description
epg_id = obj.get('id')
prog_url = PROG_URL + "%s" % (epg_id)
dic_prog = do_request(prog_url)
if 'desc' in dic_prog:
desc = ET.Element('desc')
desc.attrib['lang'] = "fr"
desc.text = dic_prog.get('desc')
cur_prog.append(desc)
else:
logging.debug("Pas de description trouvée")
# Add icon
if 'picture' in obj:
icon = ET.Element('icon')
icon.attrib['src'] = B_URL+obj.get('picture')
cur_prog.append(icon)
# Add episode-num
if 'episode_number' in obj and 'season_number' in obj:
episode = ET.Element('episode-num')
episode.attrib['system'] = "xmltv_ns"
episode.text="%d . %d . 0" % (obj.get('season_number')-1,
obj.get('episode_number')-1)
cur_prog.append(episode)
root.append(cur_prog)
return True
......@@ -268,13 +270,13 @@ def build_xml():
logging.info("%d chaines trouvée"%len(dic_channels))
cfg_chan = get_cfg_chan()
start = start_time()
i=1
i=0
for chan_name, channel in dic_channels.iteritems():
if slugify(channel.get('name')) not in cfg_chan:
logging.info("%s pas dans la liste, saut"%channel.get('name'))
continue
channel_slug = slugify(channel.get('name')).lower()+'.mafreebox.fr'
cur_channel = ET.Element('tv')
cur_channel = ET.Element('channel')
cur_channel.attrib['id'] = channel_slug
icon_channel = ET.Element('icon')
icon_channel.attrib['src'] = B_URL + channel.get('logo_url')
......@@ -283,12 +285,12 @@ def build_xml():
cur_channel.append(disp_channel)
cur_channel.append(icon_channel)
logging.debug("Récupération epg pour %s"%channel.get('name'))
res = get_epg_data(root,
root.insert(i, cur_channel)
i += 1
get_epg_data(root,
channel.get('uuid'),
channel_slug,
start_time())
if res:
root.insert(1, cur_channel)
return ET.tostring(root)
......@@ -302,7 +304,9 @@ def configure () :
" 1 : Toutes par défaut\n"+\
" 2 : Aucune par défaut\n"+\
" 3 : Préconfiguration à partir de hts tvheadend\n"+\
" 4 : Préconfiguration à partir de mythtv (beta, non testé)\n"
" 4 : Préconfiguration à partir de mythtv (beta, non testé)\n"+\
"Vous pouvez à tout moment éditer la liste des chaines dans le fichier %s\n"\
%args.config_file
)
if choise not in ('1','2','3') :
logging.error("Entrée invalide")
......@@ -333,7 +337,6 @@ def configure () :
"# Les lignes qui commencent par un # sont ignorées\n\n"+\
"\n".join(list_chan)
)
print("Vous pouvez à tout moment éditer la liste des chaines dans le fichier %s"%args.config_file)
if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment