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.icecast_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): f = None if (path == "/"): f = File(self) f.name = self.get_name() f.path = "/" f.mimetype = f.DEVICE_ROOT f.folder_flags = f.ITEMS_COMPACT else: for c in self.__list_categories(): if (c.path == path): f = c break #end for #end if 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 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 __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 = 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 __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 __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)
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
def __parse_item(self, parent_path, node_nr, node): try: name = node.get_attr("title") url = node.get_attr("url") except: return None if (name in _BLACKLISTED): return None if (not url.strip()): return None elif (url.endswith(".xml")): return None f = File(self) f.name = name f.resource = url f.path = File.pack_path(parent_path, `node_nr`, name, url) f.mimetype = "video/x-unknown" f.thumbnail = theme.worldtv_device.get_path() return f
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
def __parse_stations(self, data, genre): """ Parses the list of stations. """ stations = [] next_page_url = "" soup = BeautifulSoup(data) resulttable = soup.find("div", {"id": "content"}) if (resulttable): for entry in resulttable.findAll("tr"): #print entry station = File(self) try: station.name = entry.find("span", { "class": "name" }).a.contents[0] except: continue try: now_playing = entry.find("p", { "class": "stream-onair" }).contents[1] except: now_playing = "" station.resource = _ICECAST_BASE + entry.find( "td", { "class": "tune-in" }).find("a")["href"] try: bitrate = entry.find("td", { "class": "tune-in" }).findAll("p", {"class": "format"})[1]["title"] except: bitrate = "-" try: typename = entry.find("a", { "class": "no-link" }).contents[0].strip() except: typename = "" if (typename == "MP3"): station.mimetype = "audio/mpeg" elif (typename == "AAC+"): station.mimetype = "audio/mp4" else: station.mimetype = "audio/x-unknown" station.path = "/" + genre + "/" + \ self.__encode_station(station.name, bitrate, station.mimetype, station.resource, genre) station.info = "Bitrate: %s\n" \ "Now playing: %s" % (bitrate, now_playing) station.icon = theme.icecast_station.get_path() stations.append(station) #end for pager_tag = resulttable.find("ul", {"class": "pager"}) if (pager_tag): link = pager_tag.findAll("a")[-1] if (not link.contents[0].isdigit()): # must be an arrow next_page_url = link["href"] #end if #end if #end if if (not stations): self.__current_folder.message = "station list not available" logging.error("icecast station listing download failed\n%s", logging.stacktrace()) return (stations, next_page_url)