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
def get_file(self, path): if (self.__needs_playlist_reload): self.__load_playlists() self.__needs_playlist_reload = False if (path == "/"): return self.get_root() name = urlquote.unquote(path[1:]) pl = self.__lookup_playlist(name) if (pl): f = File(self) f.name = pl.get_name() #f.info = "%d items" % pl.get_size() f.path = path f.mimetype = f.DIRECTORY f.icon = theme.mb_folder_playlist.get_path() if (pl.get_name() != _PLAYLIST_RECENT_50): f.folder_flags |= f.ITEMS_SORTABLE return f else: return None
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
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
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
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)
def __ls_menu(self, cb, *args): for name, category in [("Search", "video"), ("Recently Featured", "recently_featured"), ("Today's Top Rated", "top_rated"), ("Most Viewed", "most_viewed"), ("Most Popular", "most_popular"), ("Music", "music"), ("Movies", "movie"), ("News", "news"), ("For Mobile Phones", "watch_on_mobile")]: item = File(self) query = "" idx = 0 item.path = File.pack_path("/search", name, category, query, idx) item.resource = item.path item.name = name item.mimetype = File.DIRECTORY item.folder_flags = File.ITEMS_UNSORTED if (name in _ICONS): item.icon = _ICONS[name].get_path() cb(item, *args) #end for cb(None, *args)
def get_root(self): f = File(self) f.name = self.get_name() f.path = "/" f.mimetype = f.DEVICE_ROOT f.folder_flags = f.ITEMS_ADDABLE #| f.ITEMS_COMPACT f.icon = self.get_icon().get_path() return f
def __make_genre(self, genre, href): f = File(self) f.name = genre f.path = href f.mimetype = f.DIRECTORY f.icon = theme.icecast_folder.get_path() f.folder_flags = f.ITEMS_ENQUEUEABLE return f
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
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
def __make_genre(self, genre): f = File(self) f.path = File.pack_path("/genres", genre) f.name = genre f.acoustic_name = genre f.mimetype = f.DIRECTORY f.icon = theme.mb_folder_genre.get_path() f.folder_flags = f.ITEMS_ENQUEUEABLE | \ f.ITEMS_COMPACT return f
def __make_artist(self, artist): f = File(self) f.path = File.pack_path("/artists", artist) f.name = artist f.acoustic_name = f.name f.mimetype = f.DIRECTORY f.icon = theme.mb_folder_artist.get_path() f.folder_flags = f.ITEMS_ENQUEUEABLE | \ f.ITEMS_COMPACT return f
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
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
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
def __make_album(self, ffolder, album): f = File(self) f.is_local = True f.path = File.pack_path("/albums", ffolder, album) f.name = album f.acoustic_name = f.name #f.info = artist f.mimetype = "application/x-music-folder" f.folder_flags = f.ITEMS_ENQUEUEABLE f.comparable = f.name if (album == "All Tracks"): f.icon = theme.mb_folder_audio.get_path() return f
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
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
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
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
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
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
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
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
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
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 __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
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
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)