Exemple #1
0
    def get_file(self, path):

        parts = [ p for p in path.split("/") if p ]
        len_parts = len(parts)
        
        f = None
        if (len_parts == 0):
            # root folder
            f = File(self)
            f.path = "/"
            f.mimetype = f.DIRECTORY
            f.resource = ""
            f.name = self.get_name()
            f.info = "Browse the SHOUTcast directory"
            f.icon = self.get_icon().get_path()
            f.folder_flags = f.ITEMS_ENQUEUEABLE | f.ITEMS_COMPACT
    
        elif (len_parts == 1):
            genre = urlquote.unquote(parts[0])
            f = self.__make_genre(genre)
    
        elif (len_parts == 2):
            f = self.__make_station(parts[1])

        return f
Exemple #2
0
    def get_file(self, path):

        f = None
        if (path == "/"):
            f = File(self)
            f.path = "/"
            f.name = "YouTube"
            f.mimetype = f.DIRECTORY
            f.resource = ""
            f.info = "Browse and download videos from YouTube"
            f.icon = theme.youtube_folder.get_path()

        elif (path.startswith("/search")):
            nil, name, category, query, idx = File.unpack_path(path)
            f = File(self)
            f.name = name
            f.mimetype = f.DIRECTORY
            f.path = path
            f.resource = ""
            if (name in _ICONS):
                f.icon = _ICONS[name].get_path()

        elif (path.startswith("/videos")):
            f = self.__make_video(path)

        return f
Exemple #3
0
    def get_file(self, path):

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

        f = None
        if (len_parts == 0):
            f = File(self)
            f.name = self.get_name()
            f.info = "Change the configuration"
            f.path = "/"
            f.icon = self.get_icon().get_path()
            f.mimetype = f.DEVICE_ROOT
            f.folder_flags = f.ITEMS_COMPACT

        elif (len_parts == 1):
            cfg_name = parts[-1]
            cs = [c for c in self.__configurators if ` c ` == cfg_name]
            if (cs):
                c = cs[0]
                f = self.__make_configurator(c)
            #end if
        #end if

        return f
Exemple #4
0
    def new_file(self, path):

        # present search dialog
        dlg = Dialog()
        dlg.add_entry("Name:", "")
        dlg.add_entry("Location:", "http://")
        values = dlg.wait_for_values()

        if (values):
            name, location = values
            stations = inetstations.get_stations()
            stations.append((location, name))
            inetstations.save_stations(stations)

            item = File(self)
            item.path = self.__encode_path(name, location)
            item.resource = location
            item.name = name
            item.info = location
            if (location.endswith(".ram") or location.endswith(".rm")):
                item.mimetype = "application/vnd.rn-realmedia"
            else:
                item.mimetype = "audio/x-unknown"

            self.emit_message(msgs.CORE_EV_FOLDER_INVALIDATED, self.get_root())
            return item

        else:
            return None
Exemple #5
0
    def get_file(self, path):

        parts = File.unpack_path(path)
        prefix = parts[0]

        f = None
        if (prefix == "/"):
            # root folder
            f = File(self)
            f.is_local = True
            f.path = "/"
            f.mimetype = f.DIRECTORY
            f.resource = ""
            f.name = self.get_name()
            f.info = "Browse your music library by album"
            f.icon = self.get_icon().get_path()
            f.folder_flags = f.ITEMS_ENQUEUEABLE | f.ITEMS_COMPACT

        elif (prefix == "/albums"):
            # album
            ffolder, album = parts[1:]
            f = self.__make_album(ffolder, album)

        elif (prefix == "/tracks"):
            # track
            artist, album, title, trackno, resource, mimetype = parts[1:]
            f = self.__make_track(artist, album, title, trackno, resource,
                                  mimetype)

        return f
Exemple #6
0
        def on_receive_node(node):
            if (node.get_name() == "{%s}totalResults" % _XMLNS_OPENSEARCH):
                # read total number of hits
                total_results = int(node.get_pcdata())

                # set a sane limit (YouTube cannot handle more anyway)
                total_results = min(total_results, 20 * _PAGE_SIZE)

                page = 1
                for n in range(1, total_results, _PAGE_SIZE):
                    f = File(self)
                    f.name = "Page %d" % page
                    f.path = File.pack_path("/search", f.name, category, query,
                                            n)
                    f.mimetype = f.DIRECTORY
                    f.info = "Results %d - %d" % (
                        n, min(total_results, n + _PAGE_SIZE - 1))
                    f.folder_flags = File.ITEMS_UNSORTED
                    cb(f, *args)
                    page += 1
                #end for

                cb(None, *args)

            return True
Exemple #7
0
    def get_root(self):

        f = File(self)
        f.name = self.get_name()
        f.info = "History of recently visited folders"
        f.path = "/"
        f.mimetype = f.DEVICE_ROOT

        return f
Exemple #8
0
 def get_root(self):
 
     f = File(self)
     f.path = "/"
     f.name = self.get_name()
     f.mimetype = f.DIRECTORY
     f.resource = ""
     f.info = "Listen to internet radio stations"
     
     return f
Exemple #9
0
 def get_root(self):
 
     f = File(self)
     f.path = "/"
     f.name = "World TV"
     f.mimetype = f.DIRECTORY
     f.resource = ""
     f.info = "Watch TV streams from all over the world"
     
     return f
Exemple #10
0
    def __make_configurator(self, c):

        f = File(self)
        f.name = c.TITLE
        f.info = c.DESCRIPTION
        f.resource = ` c `
        f.path = "/" + f.resource
        f.mimetype = f.CONFIGURATOR
        f.icon = c.ICON.get_path()

        return f
Exemple #11
0
 def cb(pl, name, location):
     f = self.call_service(msgs.CORE_SVC_GET_FILE, location)
     if (f):
         pl.append(f)
     else:
         # insert a placeholder for files that are currently
         # not available
         f = File(self)
         f.name = name
         f.info = location
         pl.append(f)
Exemple #12
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
Exemple #13
0
    def __make_video(self, path):
        """
        Creates a video file object from the given path.
        """

        prefix, title, info, video_id, thumbnail_url = File.unpack_path(path)

        f = File(self)
        f.name = title
        f.resource = video_id
        f.path = path
        f.mimetype = "video/x-flash-video"

        if (video_id == _REGION_BLOCKED):
            f.info = "This video cannot be viewed in your country."
            f.icon = theme.youtube_restricted.get_path()
        else:
            f.info = info
            f.thumbnailer = "youtube.YouTubeThumbnailer"
            f.thumbnailer_param = thumbnail_url

        return f
Exemple #14
0
    def get_file(self, path):
    
        f = None
        if (path == "/"):
            f = File(self)
            f.path = "0"
            f.mimetype = f.DEVICE_ROOT
            f.resource = ""
            f.name = self.get_name()
            f.icon = self.get_icon()
            f.info = "UPnP network storage"
            f.folder_flags = f.ITEMS_ENQUEUEABLE
            
        else:
            if (path.startswith("/")): path = path[1:]
            didl, nil, nil, nil = self.__cds_proxy.Browse(None, path,
                                                          "BrowseMetadata",
                                                          "*", "0", "0", "")
            entry = didl_lite.parse(didl)
            ident, clss, child_count, res, title, artist, mimetype = entry[0]

            url_base = self.__description.get_url_base()

            f = File(self)
            f.mimetype = mimetype
            f.resource = res
            f.name = title
            f.info = artist
            f.path = "/" + path

            if (f.mimetype == f.DIRECTORY):
                f.resource = ident
                f.folder_flags = f.ITEMS_ENQUEUEABLE
            else:
                f.resource = urlparse.urljoin(url_base, res)
            f.child_count = child_count

        return f
Exemple #15
0
    def get_root(self):

        f = File(self)
        f.path = "/"
        f.mimetype = f.DIRECTORY
        f.resource = ""
        f.name = self.get_name()
        f.info = "Editable list of radio stations"
        f.icon = self.get_icon()
        f.folder_flags = f.ITEMS_ENQUEUEABLE | \
                         f.ITEMS_ADDABLE | \
                         f.ITEMS_DELETABLE

        return f
Exemple #16
0
 def __make_station(self, name, url):
 
     f = File(self)
     f.name = name
     f.info = url
     f.path = File.pack_path("/", name, url)
     f.resource = url
     if (url.endswith(".ram") or url.endswith(".rm")):
         f.mimetype = "application/vnd.rn-realmedia"
     else:
         f.mimetype = "audio/x-unknown"
     f.thumbnailer = "iradio.IRadioThumbnailer"
     f.thumbnailer_param = url
     
     return f
Exemple #17
0
    def __parse_stations(self, data, genre):
        """
        Parses the XML list of stations.
        """

        stations = []
        try:
            dtree = ElementTree.parse(StringIO(data))
            for i in dtree.getiterator():
                if i.tag == "station":
                    # build station object
                    station = File(self)
                    bitrate = "-"
                    now_playing = "-"
                    
                    for j,n in i.items():
                        if j == "name":
                            station.name = n
                        elif j == "ct":
                            now_playing = n
                        elif j == "id":
                            station.resource = _SHOUTCAST_BASE + "/sbin/shoutcast-playlist.pls?rn=%s&file=filename.pls" % n
                        elif j == "br":
                            bitrate = n
                        elif j == "mt":
                            station.mimetype = n

                    station.path = "/" + genre + "/" + \
                                   self.__encode_station(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
                    stations.append(station)

        except:
            self.call_service(msgs.UI_ACT_SHOW_INFO,
                              "An error occured while loading the list of stations.\n" \
                              "Check your internet connection and try again.")
            logging.error("SHOUTcast station listing download failed\n%s",
                          logging.stacktrace())

        stations.sort()
        return stations
Exemple #18
0
 def get_file(self, path):
 
     f = None
     if (path == "/"):
         f = File(self)
         f.name = "Internet Radio"
         f.info = "Listen to Internet Radio"
         f.path = "/"
         f.mimetype = File.DEVICE_ROOT
         f.icon = self.get_icon().get_path()
         f.folder_flags = File.ITEMS_ADDABLE | File.ITEMS_SORTABLE
         
     else:
         prefix, name, url = File.unpack_path(path)
         f = self.__make_station(name, url)
         
     return f
Exemple #19
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       
Exemple #20
0
    def __make_station(self, s):

        try:
            prefix, name, bitrate, mimetype, location, genre = File.unpack_path(
                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 = s
        f.mimetype = mimetype
        f.icon = theme.shoutcast_station.get_path()

        return f
Exemple #21
0
    def get_file(self, path):
            
        if (path == "/"):
            f = File(self)
            f.path = "/"
            f.name = "World TV"
            f.mimetype = f.DIRECTORY
            f.resource = ""
            f.info = "Watch TV streams from all over the world"
            f.icon = theme.worldtv_device.get_path()
        else:
            prefix, node_nr, name, url = File.unpack_path(path)
            f = File(self)
            f.name = name
            f.resource = url
            f.path = path
            f.mimetype = "video/x-unknown"

        return f
Exemple #22
0
    def get_file(self, path):

        try:
            name, location = self.__decode_path(path)
        except:
            logging.error("error decoding iradio path: %s\n%s", path,
                          logging.stacktrace())
            return None

        f = File(self)
        f.name = name
        f.info = location
        f.path = path
        f.resource = location
        if (location.endswith(".ram") or location.endswith(".rm")):
            f.mimetype = "application/vnd.rn-realmedia"
        else:
            f.mimetype = "audio/x-unknown"
        f.icon = theme.iradio_device

        return f
Exemple #23
0
    def get_file(self, path):

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

        f = None
        if (len_parts == 0):
            f = File(self)
            f.is_local = True
            f.path = "/"
            f.mimetype = f.DEVICE_ROOT
            f.resource = ""
            f.name = self.get_name()
            f.info = "Browse your video library"
            f.icon = self.get_icon().get_path()
            f.folder_flags = f.ITEMS_ENQUEUEABLE  #| f.ITEMS_COMPACT

        elif (len_parts == 1):
            folder_name = urlquote.unquote(parts[0])
            f = self.__make_folder(folder_name)

        return f
Exemple #24
0
    def __list_categories(self):

        out = []
        for name, info, path, icon in [
            ("Music", "Browse Music Library", "/audio", theme.mb_folder_audio),
            ("Videos", "Browse Video Library", "/video",
             theme.mb_folder_video),
            ("Pictures", "Browse Picture Library", "/image",
             theme.mb_folder_image),
            ("Storage & Network", "Browse storage and network", "/storage",
             theme.mb_folder_storage),
        ]:
            f = File(self)
            f.name = name
            f.info = info
            f.path = path
            f.mimetype = f.DIRECTORY
            f.icon = icon.get_path()
            f.folder_flags = f.ITEMS_COMPACT
            out.append(f)
        #end for

        return out
Exemple #25
0
    def __make_track(self, artist, album, title, trackno, resource, mimetype):

        #f = self.call_service(msgs.CORE_SVC_GET_FILE, resource)
        #if (not f): return None

        path = File.pack_path("/tracks", artist, album, title, trackno,
                              resource, mimetype)

        f = File(self)
        f.path = path
        f.is_local = True
        f.resource = resource
        f.name = title
        f.info = artist or "unknown"
        f.mimetype = mimetype
        f.acoustic_name = f.name + ", by " + f.info

        if (album == "All Tracks"):
            f.comparable = f.name.upper()
        else:
            f.comparable = trackno

        return f
    def get_file(self, path):

        parts = File.unpack_path(path)
        prefix = parts[0]

        f = None
        if (prefix == "/"):
            # root folder
            f = File(self)
            f.is_local = True
            f.path = "/"
            f.mimetype = f.DEVICE_ROOT
            f.resource = ""
            f.name = self.get_name()
            f.icon = self.get_icon().get_path()
            f.info = "Browse your music library by genre"

        elif (prefix == "/genres"):
            # genre
            genre = parts[1]
            f = self.__make_genre(genre)

        return f
    def get_file(self, path):

        parts = File.unpack_path(path)
        prefix = parts[0]

        f = None
        if (prefix == "/"):
            # root folder
            f = File(self)
            f.is_local = True
            f.path = "/"
            f.mimetype = f.DEVICE_ROOT
            f.resource = ""
            f.name = self.get_name()
            f.icon = self.get_icon().get_path()
            f.info = "Browse your music library by artist"
            #f.folder_flags = f.ITEMS_COMPACT
            
        elif (prefix == "/artists"):
            # artist
            artist = parts[1]
            f = self.__make_artist(artist)
    
        return f
Exemple #28
0
    def get_contents(self, folder, begin_at, end_at, cb, *args):

        if (end_at == 0):
            end_at = 999999999

        cnt = 0
        for location, name in inetstations.get_stations():
            if (begin_at <= cnt <= end_at):
                f = File(self)
                f.name = name
                f.info = location
                f.path = self.__encode_path(name, location)
                f.resource = location
                if (location.endswith(".ram") or location.endswith(".rm")):
                    f.mimetype = "application/vnd.rn-realmedia"
                else:
                    f.mimetype = "audio/x-unknown"
                f.icon = theme.iradio_device

                cb(f, *args)
            #end if
            cnt += 1
        #end for
        cb(None, *args)
Exemple #29
0
    def get_file(self, path):

        parts = File.unpack_path(path)
        prefix = parts[0]

        f = None
        if (prefix == "/"):
            f = File(self)
            f.is_local = True
            f.path = "/"
            f.mimetype = f.DEVICE_ROOT
            f.resource = ""
            f.name = self.get_name()
            f.info = "Browse your camera pictures"
            f.icon = self.get_icon().get_path()
            f.folder_flags = f.ITEMS_ENQUEUEABLE | f.ITEMS_COMPACT

        elif (prefix == "/months"):
            month, year = parts[1:]
            month = int(month)
            year = int(year)
            f = self.__make_folder(month, year)

        return f
Exemple #30
0
    def __build_file(self, url_base, entry):

        ident, clss, child_count, res, title, artist, mimetype = entry
        f = File(self)
        f.mimetype = mimetype
        f.resource = res or urlparse.urljoin(url_base, ident)
        f.name = title
        f.artist = artist
        f.info = artist

        if (f.mimetype == f.DIRECTORY):
            f.path = "/" + ident
            f.folder_flags = f.ITEMS_ENQUEUEABLE
        else:
            f.path = "/" + ident

        f.child_count = child_count    
        
        # MythTV thinks Ogg-Vorbis was text/plain...
        if (clss.startswith("object.item.audioItem") and
            f.mimetype == "text/plain"):
            f.mimetype = "audio/x-unknown"

        # no useful MIME type reported? let's look at the file extension
        if (not f.mimetype in mimetypes.get_audio_types() + 
                              mimetypes.get_video_types() +
                              mimetypes.get_image_types() + [f.DIRECTORY]):
            ext = os.path.splitext(f.name)[-1]
            f.mimetype = mimetypes.ext_to_mimetype(ext)

        if (f.mimetype.startswith("image/")):
            f.thumbnail = f.resource
            
        logging.debug("'%s' has MIME type '%s'" % (f.name, f.mimetype))
        
        return f