Пример #1
0
def render_item(clientid, f, icon):

    icon = "/file?path=%s" % urlquote.quote(icon, "")
    name = urlquote.quote(f.name)
    link = urlquote.quote(f.full_path, "")

    return "[ '%s', '%s', '%s', '%s' ]," \
           % (icon,
              name,
              link,
              f.mimetype)
    def make_thumbnail(self, f, cb, *args):
    
        self.call_service(msgs.VIDEOPLAYER_SVC_LOCK_DSP)

        uri = "file://" + urlquote.quote(f.resource)
        self.__thumbnailer.queue(uri, ["video/mp4"], self.__on_finish,
                                 f, cb, args)
Пример #3
0
    def __get_didl(self, path):
       
        if (path.startswith("/")): path = path[1:]
        
        cache_key = urlquote.quote(self.get_prefix() + "/" + path, safe = "")
        cache_file = os.path.join(_CACHE_DIR, cache_key + ".didl.gz")

        didl = None
        if (os.path.exists(cache_file)):
            try:
                didl = gzip.open(cache_file, "r").read()
            except:
                pass
        #end if        

        if (not didl):
            # hello ORB, you'd misinterpret the RequestedCount parameter,
            # so I'm feeding you an insanely high number instead of '0',
            # which was originally intended to mean "return _all_ entries"  >:(
            didl, nil, nil, nil = self.__cds_proxy.Browse(None, path,
                                                "BrowseDirectChildren",
                                                "*", "0", "50000", "")

            try:
                gzip.open(cache_file, "w").write(didl)
            except:
                pass
            
        return didl
Пример #4
0
    def __ls_playlists(self, begin_at, end_at, cb, *args):

        self.__lists.sort(lambda a, b: cmp(a[0], b[0]))
        playlists = [pl for n, pl in self.__lists]
        if (end_at == 0):
            playlists = playlists[begin_at:]
        else:
            playlists = playlists[begin_at:end_at]

        for pl in playlists:
            f = File(self)
            f.name = pl.get_name()
            #f.info = "%d items" % pl.get_size()
            f.path = "/" + urlquote.quote(f.name)
            f.mimetype = f.DIRECTORY
            f.icon = theme.mb_folder_playlist.get_path()
            f.folder_flags |= f.ITEMS_UNSORTED

            if (pl.get_name() != _PLAYLIST_RECENT_50):
                f.folder_flags |= f.ITEMS_SORTABLE

            cb(f, *args)
        #end for

        cb(None, *args)
Пример #5
0
    def __make_genre(self, genre):

        f = File(self)    
        f.name = genre
        f.path = "/" + urlquote.quote(genre, "")
        f.mimetype = f.DIRECTORY
        f.icon = theme.shoutcast_folder.get_path()
        f.folder_flags = f.ITEMS_ENQUEUEABLE

        return f
Пример #6
0
def render_navbutton(clientid, action, icon):

    if (action.startswith("nav")):
        target = ""
    else:
        target = "target='if'"

    icon = urlquote.quote(icon)
    return """
           <img src="/theme?path=%s" align="middle" onclick="%s">
           """ % (icon, action)
    """
Пример #7
0
    def __parse_stations(self, data, genre):
        """
        Parses the list of stations.
        """

        stations = []
        soup = BeautifulSoup(data)
        resulttable = soup.find("div", {"id": "resulttable"})
        if (resulttable):
            for entry in resulttable.findAll("div", {"class": "dirlist"}):
                #print entry
                station = File(self)
                a_tag = entry.find("a", {"class": "playbutton playimage"})
                playing_tag = entry.find("div", {"class": "playingtext"})
                bitrate_tag = entry.find("div", {"class": "dirbitrate"})
                type_tag = entry.find("div", {"class": "dirtype"})

                if (not a_tag or not playing_tag or not bitrate_tag
                        or not type_tag):
                    continue

                station.resource = a_tag["href"]
                station.name = a_tag["title"]
                now_playing = playing_tag["title"]
                bitrate = bitrate_tag.contents[0].strip()

                typename = type_tag.contents[0].strip()
                if (typename == "MP3"):
                    station.mimetype = "audio/mpeg"
                elif (typename == "AAC+"):
                    station.mimetype = "audio/mp4"
                else:
                    station.mimetype = "audio/x-unknown"

                station.path = File.pack_path("/" + urlquote.quote(genre, ""),
                                              station.name, bitrate,
                                              station.mimetype,
                                              station.resource, genre)
                station.info = "Bitrate: %s kb\n" \
                               "Now playing: %s" % (bitrate, now_playing)
                station.icon = theme.shoutcast_station.get_path()
                stations.append(station)
            #end for
        #end if

        if (not stations):
            self.__current_folder.message = "station list not available"
            logging.error("SHOUTcast station listing download failed\n%s",
                          logging.stacktrace())

        stations.sort()
        return stations
Пример #8
0
    def __make_folder(self, folder_name):

        f = File(self)
        f.is_local = True
        f.path = "/" + urlquote.quote(folder_name, "")
        f.mimetype = f.DIRECTORY
        f.resource = ""
        f.name = folder_name
        f.acoustic_name = "Folder: " + f.name
        f.icon = theme.mb_folder_audioclips.get_path()
        #f.info = "%d items" % len(self.__folders.get(folder_name, []))
        f.folder_flags = f.ITEMS_ENQUEUEABLE

        return f
Пример #9
0
    def make_thumbnail(self, f, cb, *args):

        if (f.mimetype == "application/x-image-folder"):
            c = f.get_children()[0]
            res = c.resource
            mimetype = c.mimetype
        else:
            res = f.resource
            mimetype = f.mimetype

        uri = "file://" + urlquote.quote(res)
        print "thumbnailing image", f, mimetype
        self.__thumbnailer.queue(uri, [mimetype], self.__on_finish, f, cb,
                                 args)
Пример #10
0
    def __make_folder(self, folder_name):

        f = File(self)
        f.is_local = True
        f.path = "/" + urlquote.quote(folder_name, "")
        f.mimetype = "application/x-image-folder"
        f.resource = ""
        f.name = folder_name
        f.acoustic_name = "Folder: " + f.name
        #f.info = "%d items" % len(self.__folders.get(folder_name, []))
        f.folder_flags = f.ITEMS_ENQUEUEABLE | \
                            f.ITEMS_COMPACT

        return f
Пример #11
0
    def __create_playlist(self, name):
        """
        Creates a new playlist with the given name.
        Returns the file object representing the list.
        """

        name = name.encode("utf-8")
        pl_path = os.path.join(_PLAYLIST_DIR,
                               urlquote.quote(name, safe="") + ".m3u")
        logging.info("creating playlist '%s'" % pl_path)
        pl = Playlist()
        pl.set_name(name)
        pl.save_as(pl_path)
        self.__lists.append((name, pl))
Пример #12
0
 def __make_station(self, s):
 
     try:
         name, bitrate, mimetype, location, genre = self.__decode_station(s)
     except:
         logging.error("error decoding iradio path: %s\n%s",
                         path, logging.stacktrace())
         return None
     
     f = File(self)
     f.name = name
     f.info = "Bitrate: %s kb" % bitrate
     f.resource = location
     f.path = "/" + urlquote.quote(genre, "") + "/" + s
     f.mimetype = mimetype
     f.icon = theme.shoutcast_station.get_path()
     
     return f       
Пример #13
0
    def __encode_path(self, name, resource):

        path = "/" + "\t\t\t".join([name, resource])
        return urlquote.quote(path)
Пример #14
0
 def __encode_station(self, name, bitrate, mimetype, resource, genre):
 
     s = "\t\t\t".join([name, bitrate, mimetype, resource, genre])
     return urlquote.quote(s, "")