diff --git a/wiki/macro/TV.py b/wiki/macro/TV.py new file mode 100644 index 00000000..09b97587 --- /dev/null +++ b/wiki/macro/TV.py @@ -0,0 +1,92 @@ +Dependencies = ["Time"] + + + +SAP_FILE_URL = "http://tv/sap.txt" +BASE_IMAGE_URL = "http://tv/images/" +IMAGE_SUFFIX = ".jpg" +SMALL_IMAGE_SUFFIX = "_petites.jpg" + + +def image_url_for_channel(channel_name, channel_ip, small=0 ): + if small: + return BASE_IMAGE_URL + str(channel_ip) + IMAGE_SUFFIX + else: + return BASE_IMAGE_URL + str(channel_ip) + SMALL_IMAGE_SUFFIX + +def get_channel_list(): + import urllib + # Getsap file from web sever. + f = urllib.urlopen(SAP_FILE_URL) + # Read it. + s = f.read() + f.close() + + s = s.split("\n") + + channel_list = [] + for a_line in s: + try: + ch_name, ch_ip = a_line.split(":") + url = "udp://@%s:1234" % ch_ip + d = { + "name": ch_name, + "url": url, + "image_url": image_url_for_channel( ch_name, ch_ip ), + "small_image_url": image_url_for_channel( ch_name, ch_ip, small=1 ), + } + channel_list.append(d) + except: + pass + return channel_list + + +def execute(macro, args): + opt = {"col":4,"cat":False,"ch":False, "width":"4em"} + # parse args + if args: + try: + for name, value in [(x.split("=")[0].strip(), x.split("=")[1].strip()) for x in args.split(",")]: + opt[name] = value + except: + pass + + IMAGES_PER_LINE = int(opt["col"]) + CATHEGORY = opt["cat"] + CHANNEL = opt["ch"] + IMAGE_WIDTH = opt["width"] + # display all channel + ch_list = get_channel_list() + text = macro.formatter.table(1,{}) + i = 0 + for a_channel in ch_list: + if CATHEGORY: + if not a_channel["name"].startswith(CATHEGORY): + continue + if CHANNEL: + if a_channel["name"].find(CHANNEL)<0: + continue + if i == 0: + text+= macro.formatter.table_row(1) + text+= macro.formatter.table_cell(1, {'style':'text-align:center;'}) + text+= macro.formatter.strong( 1 ) + text+= macro.formatter.text( a_channel["name"] ) + text+= macro.formatter.strong( 0 ) + text+= macro.formatter.linebreak( 0 ) + text+= macro.formatter.url(1, href=a_channel["url"], style="text-decoration:none;") + text+= macro.formatter.image( src=a_channel["image_url"], alt="No image", style='%s' % IMAGE_WIDTH ) + text+= macro.formatter.linebreak( 0 ) + text+= macro.formatter.text( "Regarder maintenant" ) + text+= macro.formatter.url(0) + text+= macro.formatter.table_cell(0) + if i == IMAGES_PER_LINE - 1: + text+= macro.formatter.table_row(0) + i = (i + 1) % IMAGES_PER_LINE + while i != 0 and i < IMAGES_PER_LINE: + text+= macro.formatter.table_cell(1) + text+= macro.formatter.table_cell(0) + i += 1 + text+= macro.formatter.table(0) + return text + + \ No newline at end of file