Ejemplo n.º 1
0
 def getChannelsEpg(
     self, cids
 ):  #RodnoeTV hasn't got this function in API. Got epg for all instead.
     params = {}
     if len(cids) == 1:
         params['cid'] = cids[0]
     root = self.getData(
         self.site + "/get_epg_current?" + urllib.urlencode(params),
         "getting epg of all channels")
     for channel in root.find('channels'):
         id = int(channel.findtext('id').encode("utf-8"))
         prog = channel.find('current')
         if prog and prog.findtext('begin') and prog.findtext('title'):
             title = prog.findtext('title').encode('utf-8') + '\n'
             title += prog.findtext('info').encode('utf-8')
             t_start = datetime.datetime.fromtimestamp(
                 int(prog.findtext('begin').encode('utf-8')))
             t_end = datetime.datetime.fromtimestamp(
                 int(prog.findtext('end').encode('utf-8')))
             self.channels[id].epg = EpgEntry(title, t_start, t_end)
         prog = channel.find('next')
         if prog and prog.findtext('begin') and prog.findtext('title'):
             title = prog.findtext('title').encode('utf-8') + '\n'
             title += prog.findtext('info').encode('utf-8')
             t_start = datetime.datetime.fromtimestamp(
                 int(prog.findtext('begin').encode('utf-8')))
             t_end = datetime.datetime.fromtimestamp(
                 int(prog.findtext('end').encode('utf-8')))
             self.channels[id].nepg = EpgEntry(title, t_start, t_end)
         else:
             self.channels[id].lastUpdateFailed = True
             #	print "[KartinaTV] INFO there is no epg for id=%d on ktv-server" % id
             pass
Ejemplo n.º 2
0
 def setChannelsList(self):
     root = self.getChannelsList()
     lst = []
     t_str = root.findtext("servertime").encode("utf-8")
     t_cur = datetime.datetime.fromtimestamp(int(t_str))
     setSyncTime(t_cur)
     num = -1
     for group in root.find("groups"):
         title = group.findtext("name").encode("utf-8")
         gid = int(group.findtext("id"))
         for channel in group.find("channels"):
             num += 1
             name = channel.findtext("name").encode("utf-8")
             id = int(channel.findtext("id").encode("utf-8"))
             archive = channel.findtext("have_archive") or 0
             self.channels[id] = Channel(name, title, num, gid, archive)
             if channel.findtext("epg_progname") and channel.findtext(
                     "epg_end"):
                 prog = channel.findtext("epg_progname").encode("utf-8")
                 t_str = channel.findtext("epg_start").encode("utf-8")
                 t_start = datetime.datetime.fromtimestamp(int(t_str))
                 t_str = channel.findtext("epg_end").encode("utf-8")
                 t_end = datetime.datetime.fromtimestamp(int(t_str))
                 #print "[KartinaTV] updating epg for cid = ", id
                 self.channels[id].epg = EpgEntry(prog, t_start, t_end)
             else:
                 #print "[KartinaTV] there is no epg for id=%d on ktv-server" % id
                 pass
Ejemplo n.º 3
0
 def getDayEpg(self, id, date=None):
     if not date:
         date = syncTime()
     print date
     params = {
         "cid":
         id,
         "from_uts":
         datetime.datetime(date.year, date.month, date.day).strftime('%s'),
         "hours":
         24
     }
     root = self.getData(self.site + "/get_epg?" + urllib.urlencode(params),
                         "EPG for channel %s" % id)
     epglist = []
     self.channels[id].lepg[date.strftime("%y%m%d")] = []
     for prog in root.find('channels').find('item').find('epg'):
         title = prog.findtext('title').encode('utf-8') + '\n'
         title += prog.findtext('info').encode('utf-8')
         t_start = datetime.datetime.fromtimestamp(
             int(prog.findtext('begin').encode('utf-8')))
         t_end = datetime.datetime.fromtimestamp(
             int(prog.findtext('end').encode('utf-8')))
         self.channels[id].lepg[date.strftime("%y%m%d")] += [
             EpgEntry(title, t_start, t_end)
         ]
         epglist += [(t_start, title.split('\n')[0], title.split('\n')[1])]
     return epglist
Ejemplo n.º 4
0
    def setChannelsList(self):
        root = self.getChannelsList()
        t = int(root.findtext('servertime'))
        self.trace('server time %s' % datetime.datetime.fromtimestamp(t))
        setSyncTime(datetime.datetime.fromtimestamp(t))

        groups = root.find('groups')
        for group in groups.findall('item'):
            gid = int(group.findtext('id').encode('utf-8'))
            groupname = group.findtext('name').encode('utf-8')
            channels = group.find('channels')
            for channel in channels.findall('item'):
                id = int(channel.findtext('id').encode('utf-8'))
                name = channel.findtext('name').encode('utf-8')
                num = int(channel.findtext('number').encode('utf-8'))
                archive = int(channel.findtext('has_archive').encode('utf-8'))
                self.channels[id] = Channel(name, groupname, num, gid, archive)
                self.channels[id].is_protected = int(
                    channel.findtext('protected'))
                if channel.findtext('epg_current_title') and channel.findtext(
                        'epg_current_start'):
                    prog = channel.findtext('epg_current_title').encode(
                        'utf-8') + '\n'
                    prog += channel.findtext('epg_current_info').encode(
                        'utf-8')
                    t_start = datetime.datetime.fromtimestamp(
                        int(channel.findtext('epg_current_start')))
                    t_end = datetime.datetime.fromtimestamp(
                        int(
                            channel.findtext('epg_current_end').encode(
                                'utf-8')))
                    self.channels[id].epg = EpgEntry(prog, t_start, t_end)
                if channel.findtext('epg_next_title') and channel.findtext(
                        'epg_next_start'):
                    prog = channel.findtext('epg_next_title').encode(
                        'utf-8') + '\n'
                    prog += channel.findtext('epg_next_info').encode('utf-8')
                    t_start = datetime.datetime.fromtimestamp(
                        int(
                            channel.findtext('epg_next_start').encode(
                                'utf-8')))
                    t_end = datetime.datetime.fromtimestamp(
                        int(channel.findtext('epg_next_end').encode('utf-8')))
                    self.channels[id].nepg = EpgEntry(prog, t_start, t_end)
                else:
                    #print "[RodnoeTV] there is no epg for id=%d on rtv-server" % id
                    pass
Ejemplo n.º 5
0
    def epgNext(self, cid):
        params = {"cid": cid}
        root = self.getData("/api/xml/epg_next?" + urllib.urlencode(params),
                            "EPG next for channel %s" % cid)
        lst = root.find('epg')

        def parseepg(epg):
            t = int(epg.findtext('ts').encode("utf-8"))
            tstart = datetime.datetime.fromtimestamp(t)
            title = epg.findtext('progname').encode('utf-8')
            return (tstart, title)

        if len(lst) > 1:
            #print parseepg(lst[0])[0]
            self.channels[cid].epg = EpgEntry(
                parseepg(lst[0])[1],
                parseepg(lst[0])[0],
                parseepg(lst[1])[0])
        if len(lst) > 2:
            self.channels[cid].nepg = EpgEntry(
                parseepg(lst[1])[1],
                parseepg(lst[1])[0],
                parseepg(lst[2])[0])
Ejemplo n.º 6
0
 def getChannelsEpg(self, cids):
     if len(cids) == 1:
         return self.epgNext(cids[0])
     params = {"cids": ",".join(map(str, cids))}
     root = self.getData("/api/xml/epg_current?" + urllib.urlencode(params),
                         "getting epg of cids = %s" % cids)
     for channel in root.find('epg'):
         id = int(channel.findtext("cid").encode("utf-8"))
         e = channel.find("epg")
         t = int(e.findtext('epg_start').encode("utf-8"))
         t_start = datetime.datetime.fromtimestamp(t)
         t = int(e.findtext('epg_end').encode("utf-8"))
         t_end = datetime.datetime.fromtimestamp(t)
         prog = e.findtext('epg_progname').encode('utf-8')
         self.channels[id].epg = EpgEntry(prog, t_start, t_end)
Ejemplo n.º 7
0
 def getGmtEpg(self, id):
     params = {
         "m": "channels",
         "act": "get_stream_url",
         "cid": id,
         "gmt": (syncTime() + secTd(self.aTime)).strftime("%s"),
         "just_info": 1
     }
     root = self.getData("/?" + urllib.urlencode(params),
                         "get GmtEpg of stream %s" % id)
     prog = unescapeEntities(root.attrib.get("programm")).encode("utf-8")
     tstart = datetime.datetime.fromtimestamp(
         int(root.attrib.get("start").encode("utf-8")))  #unix
     tend = datetime.datetime.fromtimestamp(
         int(root.attrib.get("next").encode("utf-8")))
     self.channels[id].aepg = EpgEntry(prog, tstart, tend)
Ejemplo n.º 8
0
 def getStreamUrl(self, cid, pin):
     params = {"m": "channels", "act": "get_stream_url", "cid": cid}
     if self.aTime:
         params["gmt"] = (syncTime() + secTd(self.aTime)).strftime("%s")
     params["protect_code"] = pin
     root = self.getData("/?" + urllib.urlencode(params),
                         "URL of stream %s" % cid)
     if self.aTime:
         prog = unescapeEntities(root.attrib.get("programm"))
         if prog:
             prog = prog.encode("utf-8")
             tstart = datetime.datetime.fromtimestamp(
                 int(root.attrib.get("start").encode("utf-8")))  #unix
             tend = datetime.datetime.fromtimestamp(
                 int(root.attrib.get("next").encode("utf-8")))
             self.channels[cid].aepg = EpgEntry(prog, tstart, tend)
     url = root.attrib.get("url").encode("utf-8").split(' ')[0].replace(
         'http/ts://', 'http://')
     if url == "protected": return 0
     return url