示例#1
0
    def __video_search(self, cb, args, query, start_index):

        start_index = int(start_index)

        if (not query):
            # present search dialog
            dlg = InputDialog("Search", label_ok="Search")
            dlg.add_input("Keywords:", "")
            resp = dlg.run()
            values = dlg.get_values()

            if (resp == dlg.RETURN_OK and values):
                query = urllib.quote_plus(values[0])
            else:
                cb(None, *args)
                return

            url = _VIDEO_SEARCH % (1, 1, query)
            #print "URL", url
            Downloader(url, self.__on_receive_xml, [""], "video", query, True,
                       cb, *args)

        else:
            url = _VIDEO_SEARCH % (start_index, _PAGE_SIZE, query)
            #print "URL", url
            Downloader(url, self.__on_receive_xml, [""], "video", query, False,
                       cb, *args)
示例#2
0
    def get_contents(self, folder, begin_at, end_at, cb, *args):
        def list_genres():
            cnt = 0
            for name in self.__genres:
                if (cnt < begin_at): continue
                if (end_at and cnt > end_at): break

                f = self.__make_genre(name)
                cb(f, *args)
                cnt += 1
            #end for
            cb(None, *args)

        def on_load_genres(d, amount, total, data):
            if (d):
                data[0] += d

            else:
                #open("/tmp/shoutcast-genres.html", "w").write(data[0])
                self.__genres = self.__parse_genres(data[0])
                list_genres()

        def on_load_stations(d, amount, total, data, genre):
            if (d):
                data[0] += d

            else:
                #open("/tmp/shoutcast-stations.html", "w").write(data[0])
                stations = self.__parse_stations(data[0], genre)
                cnt = 0
                for station in stations:
                    if (cnt < begin_at): continue
                    if (end_at and cnt > end_at): break

                    cb(station, *args)
                    cnt += 1
                #end for
                cb(None, *args)

        path = folder.path
        self.__current_folder = folder

        if (not path.endswith("/")): path += "/"
        parts = [p for p in path.split("/") if p]
        len_parts = len(parts)

        if (len_parts == 0):
            # list genres
            if (not self.__genres):
                dl = Downloader(_SHOUTCAST_BASE + "/", on_load_genres, [""])
            else:
                list_genres()

        elif (len_parts == 1):
            # list stations
            genre = urlquote.unquote(parts[0])
            dl = Downloader(_SHOUTCAST_BASE + "/radio/" + genre,
                            on_load_stations, [""], genre)
示例#3
0
    def __category_search(self, category, cb, args, start_index):

        start_index = int(start_index)

        #print category, start_index
        if (start_index == 0):
            url = _CATEGORIES[category] % (1, 1)
            Downloader(url, self.__on_receive_xml, [""], category, "", True,
                       cb, *args)
        else:
            url = _CATEGORIES[category] % (start_index, _PAGE_SIZE)
            Downloader(url, self.__on_receive_xml, [""], category, "", False,
                       cb, *args)
示例#4
0
    def __parse_scpd(self, scpdurl):
    
        def on_download(data, s, t, xml):
            if (data):
                xml[0] += data
        
        xml = [""]
        dl = Downloader(scpdurl, on_download, xml)
        dl.wait_until_closed()

        scpd = MiniXML(xml[0], _XMLNS_UPNP).get_dom()
        for c in scpd.get_children():
            name = c.get_name()
            if (name == "{%s}specVersion" % _XMLNS_UPNP):
                pass
            elif (name == "{%s}actionList" % _XMLNS_UPNP):
                for action in c.get_children():
                    self.__parse_action(action)
            elif (name == "{%s}serviceStateTable" % _XMLNS_UPNP):
                pass
示例#5
0
    def load(self, resource, maxlen, cb, *args):
    
        def f(d, amount, total):
            try:
                cb(d, amount, total, *args)
            except:
                pass

            if (d and maxlen > 0 and amount >= maxlen):
                try:
                    cb("", amount, total, *args)
                except:
                    pass
                dloader.cancel()
        
        dloader = Downloader(resource.resource, f)
示例#6
0
    def __load_page(self, url, cb, args):
        def on_page_loaded(d, amount, total, data, genre):
            if (d):
                data[0] += d

            else:
                stations, next = self.__parse_stations(data[0], genre)
                cnt = 0
                for station in stations:
                    cb(station, *args)
                #end for
                print "NEXT", next
                if (next):
                    self.__load_page(url + next, cb, args)
                else:
                    cb(None, *args)

        base = url
        dl = Downloader(url, on_page_loaded, [""], "")
示例#7
0
    def get_contents(self, folder, begin_at, end_at, cb, *args):
        def list_genres():
            cnt = 0
            for name, href in self.__genres:
                if (cnt < begin_at): continue
                if (end_at and cnt > end_at): break

                f = self.__make_genre(name, href)
                cb(f, *args)
                cnt += 1
            #end for
            cb(None, *args)

        def on_load_genres(d, amount, total, data):
            if (d):
                data[0] += d

            else:
                self.__genres = self.__parse_genres(data[0])
                list_genres()

        path = folder.path
        self.__current_folder = folder
        print path

        if (not path.endswith("/")): path += "/"
        parts = [p for p in path.split("/") if p]
        len_parts = len(parts)

        if (len_parts == 0):
            # list genres
            if (not self.__genres):
                dl = Downloader(_ICECAST_BASE + "/index.php", on_load_genres,
                                [""])
            else:
                list_genres()

        else:  #if (len_parts == 1):
            # list stations
            href = path
            self.__load_page(_ICECAST_BASE + href, cb, args)
示例#8
0
    def __handle_ssdp_alive(self, uuid, location, max_age):
    
        logging.debug("[ssdp monitor] ALIVE from: %s, max-age %ds", uuid, max_age)
        if (not uuid in self.__servers and
                not uuid in self.__processing):
            self.__servers[uuid] = location
            self.__processing[uuid] = location

            Downloader(location,
                        self.__on_receive_description_xml,
                        location, uuid, [""])
        #end if
                        
        # set up expiration handler
        if (uuid in self.__expiration_handlers):
            logging.debug("[ssdp monitor] still ALIVE from: %s", uuid)
            gobject.source_remove(self.__expiration_handlers[uuid])
            
        logging.debug("[ssdp monitor] expires in %d seconds: %s", max_age, uuid)
        self.__expiration_handlers[uuid] = gobject.timeout_add(
                    max_age * 1000, self.__on_expire, uuid)