def parse(self): try: doc = feedparser.parse(self.uri) except: return False try: album = doc.channel.title except AttributeError: return False if album: self.name = album else: self.name = _("Unknown") defaults = AudioFile({"feed": self.uri}) try: self.__fill_af(doc.channel, defaults) except: return False entries = [] uris = set() for entry in doc.entries: try: for enclosure in entry.enclosures: try: if ("audio" in enclosure.type or "ogg" in enclosure.type or formats.filter(enclosure.url)): uri = enclosure.url.encode('ascii', 'replace') try: size = enclosure.length except AttributeError: size = 0 entries.append((uri, entry, size)) uris.add(uri) break except AttributeError: pass except AttributeError: pass for entry in list(self): if entry["~uri"] not in uris: self.remove(entry) else: uris.remove(entry["~uri"]) entries.reverse() for uri, entry, size in entries: if uri in uris: song = RemoteFile(uri) song["~#size"] = size song.fill_metadata = False song.update(defaults) song["album"] = self.name try: self.__fill_af(entry, song) except: pass else: self.insert(0, song) self.__lastgot = time.time() return bool(uris)
def open_location(self, action): name = GetStringDialog(self, _("Add a Location"), _("Enter the location of an audio file:"), okbutton=Gtk.STOCK_ADD).run() if name: if not util.uri_is_valid(name): ErrorMessage( self, _("Unable to add location"), _("<b>%s</b> is not a valid location.") % ( util.escape(name))).run() elif not app.player.can_play_uri(name): ErrorMessage( self, _("Unable to add location"), _("<b>%s</b> uses an unsupported protocol.") % ( util.escape(name))).run() else: if name not in self.__library: self.__library.add([RemoteFile(name)])
def open_location(self, action): name = GetStringDialog(self, _("Add a Location"), _("Enter the location of an audio file:"), button_label=_("_Add"), button_icon=Icons.LIST_ADD).run() if name: if not uri_is_valid(name): ErrorMessage( self, _("Unable to add location"), _("%s is not a valid location.") % ( util.bold(util.escape(name)))).run() elif not app.player.can_play_uri(name): ErrorMessage( self, _("Unable to add location"), _("%s uses an unsupported protocol.") % ( util.bold(util.escape(name)))).run() else: if name not in self.__library: self.__library.add([RemoteFile(name)])
def __drag_data_received(self, widget, ctx, x, y, sel, tid, etime): assert tid == DND_URI_LIST uris = sel.get_uris() dirs = [] error = False for uri in uris: try: uri = URI(uri) except ValueError: continue if uri.is_filename: loc = os.path.normpath(uri.filename) if os.path.isdir(loc): dirs.append(loc) else: loc = os.path.realpath(loc) if loc not in self.__library: self.__library.add_filename(loc) elif app.player.can_play_uri(uri): if uri not in self.__library: self.__library.add([RemoteFile(uri)]) else: error = True break Gtk.drag_finish(ctx, not error, False, etime) if error: ErrorMessage( self, _("Unable to add songs"), _("%s uses an unsupported protocol.") % util.bold(uri)).run() else: if dirs: copool.add(self.__library.scan, dirs, cofuncid="library", funcid="library")
def an_rf(i: int) -> AudioFile: return RemoteFile(f"https://example.com/{i}.mp3")
def parse(self): try: if not self._check_feed(): return False doc = feedparser.parse(self.uri) except Exception as e: print_w("Couldn't parse feed: %s (%s)" % (self.uri, e)) return False try: album = doc.channel.title except AttributeError: print_w("No channel title in %s" % doc) return False if album: self.name = album else: self.name = _("Unknown") defaults = AudioFile({"feed": self.uri}) try: self.__fill_af(doc.channel, defaults) except: return False entries = [] uris = set() print_d("Found %d entries in channel" % len(doc.entries)) for entry in doc.entries: try: for enclosure in entry.enclosures: try: if ("audio" in enclosure.type or "ogg" in enclosure.type or formats.filter(enclosure.url)): uri = enclosure.url if not isinstance(uri, str): uri = uri.decode('utf-8') try: size = float(enclosure.length) except (AttributeError, ValueError): size = 0 entries.append((uri, entry, size)) uris.add(uri) break except AttributeError: pass except AttributeError: print_d("No enclosures found in %s" % entry) for entry in list(self): if entry["~uri"] not in uris: self.remove(entry) else: uris.remove(entry["~uri"]) print_d("Successfully got %d episodes in channel" % len(entries)) entries.reverse() for uri, entry, size in entries: if uri in uris: song = RemoteFile(uri) song["~#size"] = size song.fill_metadata = False song.update(defaults) song["album"] = self.name try: self.__fill_af(entry, song) except Exception as e: print_d("Couldn't convert %s to AudioFile (%s)" % (uri, e)) else: self.insert(0, song) self.__lastgot = time.time() return bool(uris)
def parse(self): try: if not self._check_feed(): return False doc = feedparser.parse(self.uri) except Exception as e: print_w("Couldn't parse feed: %s (%s)" % (self.uri, e)) return False try: album = doc.channel.title except AttributeError: print_w("No channel title in %s" % doc) return False if album: self.name = album else: self.name = _("Unknown") defaults = AudioFile({"feed": self.uri}) try: self.__fill_af(doc.channel, defaults) except: return False entries = [] uris = set() print_d("Found %d entries in channel" % len(doc.entries)) for entry in doc.entries: try: for enclosure in entry.enclosures: try: if ("audio" in enclosure.type or "ogg" in enclosure.type or formats.filter(enclosure.url)): uri = enclosure.url if not isinstance(uri, text_type): uri = uri.decode('utf-8') try: size = float(enclosure.length) except AttributeError: size = 0 entries.append((uri, entry, size)) uris.add(uri) break except AttributeError: pass except AttributeError: print_d("No enclosures found in %s" % entry) for entry in list(self): if entry["~uri"] not in uris: self.remove(entry) else: uris.remove(entry["~uri"]) print_d("Successfully got %d episodes in channel" % len(entries)) entries.reverse() for uri, entry, size in entries: if uri in uris: song = RemoteFile(uri) song["~#size"] = size song.fill_metadata = False song.update(defaults) song["album"] = self.name try: self.__fill_af(entry, song) except Exception as e: print_d("Couldn't convert %s to AudioFile (%s)" % (uri, e)) else: self.insert(0, song) self.__lastgot = time.time() return bool(uris)
def test_fix_old_types(self): f = RemoteFile("http://example.com") f["~filename"] = b"foo" self.assertTrue(is_fsnative(f["~filename"])) f["~filename"] = u"foo" self.assertTrue(is_fsnative(f["~filename"]))
def test_path_types(self): f = RemoteFile("http://example.com") self.assertTrue(is_fsnative(f["~mountpoint"])) self.assertTrue(is_fsnative(f["~filename"]))
def test_fix_old_types(self): f = RemoteFile("http://example.com") dict.__setitem__(f, "~filename", b"foo") self.assertTrue(isinstance(f["~filename"], fsnative)) dict.__setitem__(f, "~filename", u"foo") self.assertTrue(isinstance(f["~filename"], fsnative))
def test_show_files_remote_songs(self): self.songs = self.library.songs = [RemoteFile("http://example.com/")] self.menu = self.empty_menu_with(show_files=True) self.failIf(len(self.menu))
def an_rf(i: int) -> AudioFile: return RemoteFile(f"https://github.com/quodlibet/quodlibet/{i}.mp3")