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 = [ 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_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)
def get_contents(self, folder, begin_at, end_at, cb, *args): def folder_cmp(a, b): if (a.name == "All Pictures"): return -1 if (b.name == "All Pictures"): return 1 else: return cmp(a.name, b.name) parts = [ p for p in folder.path.split("/") if p ] len_parts = len(parts) items = [] if (len_parts == 0): # list folders res = self.call_service(msgs.FILEINDEX_SVC_QUERY, "File.Folder of File.Type='image'") res.add(("All Pictures",)) for folder_name, in res: f = self.__make_folder(folder_name) if (f): items.append(f) #end for elif (len_parts == 1): # list images folder_name = urlquote.unquote(parts[0]) if (folder_name == "All Pictures"): query = "File.Path of File.Type='image'" query_args = () else: query = "File.Path of and File.Type='image' File.Folder='%s'" query_args = (folder_name,) res = self.call_service(msgs.FILEINDEX_SVC_QUERY, query, *query_args) for path, in res: f = self.call_service(msgs.CORE_SVC_GET_FILE, path) if (f): items.append(f) #end if #end if items.sort(folder_cmp) cnt = -1 for item in items: cnt += 1 if (cnt < begin_at): continue if (end_at and cnt > end_at): break cb(item, *args) #end for cb(None, *args)
def load_from_file(self, path, cb): """ Loads the playlist from the given file. """ now = time.time() self.__files = [] for location, name in m3u.load(path): cb(self, name, location) self.__path = path self.__is_modified = False self.__name = urlquote.unquote( os.path.splitext(os.path.basename(path))[0]) logging.profile(now, "[playlist] loaded playlist: %s", self.__name)
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 __decode_path(self, path): data = urlquote.unquote(path[1:]) name, resource = data.split("\t\t\t") return (name, resource)
def handle_HTTPSERVER_EV_REQUEST(self, owner, request): def on_child(f, folder, contents): if (f): # look up thumbnail if (not f.icon): icon, is_final = self.call_service( msgs.THUMBNAIL_SVC_LOOKUP_THUMBNAIL, f) else: icon = f.icon contents.append((f, icon)) else: self.__send_contents(request, clientid, folder, contents) return True if (owner != self): return path = urlquote.unquote(request.get_path()) #if (not path): # path = "media:///" if (path.startswith("theme.")): path = getattr(theme, path[6:]).get_path() # get parameters params = request.get_query() action = params.get("action", ["open"])[0] clientid = params.get("clientid", [""])[0] if (not clientid): clientid = str(self.__client_cnt) self.__client_cnt += 1 # prepare path stack for client if (not clientid in self.__path_stacks): self.__path_stacks[clientid] = [] path_stack = self.__path_stacks[clientid] print "requesting", clientid, path, action if (path == "/"): request.send_html(pages.render_page_browser(clientid)) elif (path == "/nav-home"): f = self.call_service(msgs.CORE_SVC_GET_FILE, "media:///") path_stack[:] = [f] f.get_contents(0, 0, on_child, f, []) elif (path == "/nav-up"): if (len(path_stack) > 1): path_stack.pop() f = path_stack.pop() else: f = self.call_service(msgs.CORE_SVC_GET_FILE, "media:///") path_stack[:] = [] path_stack.append(f) f.get_contents(0, 0, on_child, f, []) elif (path == "/open"): filepath = urlquote.unquote(params["path"][0]) f = self.call_service(msgs.CORE_SVC_GET_FILE, filepath) if (f and f.mimetype.endswith("-folder")): path_stack.append(f) f.get_contents(0, 0, on_child, f, []) elif (f): parent = path_stack[-1] self.emit_message(msgs.MEDIA_ACT_LOAD, f) self.emit_message(msgs.MEDIA_ACT_CHANGE_PLAY_FOLDER, parent) request.send_html("<html><body>OK</body></html>") else: request.send_not_found("MediaBox WebAccess", filepath) elif (path == "/file"): filepath = urlquote.unquote(params["path"][0]) f = self.call_service(msgs.CORE_SVC_GET_FILE, filepath) print "FILE", f, f.is_local if (f and f.is_local): request.send_file(open(f.get_resource(), "r"), f.name, f.mimetype) elif (path == "/theme"): filepath = urlquote.unquote(params["path"][0]) pbuf = getattr(theme, filepath) request.send_file(open(pbuf.get_path(), "r"), filepath, "image/x-png") elif (action == "volume-down"): self.emit_message(msgs.INPUT_EV_VOLUME_DOWN, True) request.send_html("<html><body>OK</body></html>") elif (action == "volume-up"): self.emit_message(msgs.INPUT_EV_VOLUME_UP, True) request.send_html("<html><body>OK</body></html>") elif (action == "media-previous"): self.emit_message(msgs.MEDIA_ACT_PREVIOUS) request.send_html("<html><body>OK</body></html>") elif (action == "media-next"): self.emit_message(msgs.MEDIA_ACT_NEXT) request.send_html("<html><body>OK</body></html>") elif (action == "media-pause"): self.emit_message(msgs.MEDIA_ACT_PAUSE) request.send_html("<html><body>OK</body></html>") elif (action == "ui-fullscreen"): self.emit_message(msgs.INPUT_EV_FULLSCREEN, True) request.send_html("<html><body>OK</body></html>") elif (action == "nav-up"): if (len(path_stack) > 1): path_stack.pop() f = path_stack.pop() else: f = self.call_service(msgs.CORE_SVC_GET_FILE, "media:///") path_stack[:] = [] path_stack.append(f) f.get_contents(0, 0, on_child, f, []) elif (action == "nav-shelf"): f = self.call_service(msgs.CORE_SVC_GET_FILE, "media:///") path_stack[:] = [f] f.get_contents(0, 0, on_child, f, []) elif (action == "open"): f = self.call_service(msgs.CORE_SVC_GET_FILE, path) if (f): path_stack.append(f) print "opening", f.name f.get_contents(0, 0, on_child, f, []) else: request.send_not_found("MediaBox WebAccess", path) elif (action == "play"): f = self.call_service(msgs.CORE_SVC_GET_FILE, path) if (f): print "loading" parent = path_stack[-1] self.emit_message(msgs.MEDIA_ACT_LOAD, f) self.emit_message(msgs.MEDIA_ACT_CHANGE_PLAY_FOLDER, parent) request.send_html("<html><body>OK</body></html>") else: request.send_not_found("MediaBox WebAccess", path) else: f = self.call_service(msgs.CORE_SVC_GET_FILE, path) if (f and f.is_local): request.send_file(open(f.get_resource(), "r"), f.name, f.mimetype) elif (f and not f.is_local): request.send_redirect(f.get_resource()) else: request.send_not_found("MediaBox WebAccess", path)
def __decode_station(self, s): data = urlquote.unquote(s) name, bitrate, mimetype, resource, genre = data.split("\t\t\t") return (name, bitrate, mimetype, resource, genre)