From 544979e7ffc6f9678a8391e596b69f708118efd2 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 9 Jan 2019 18:43:13 +0100 Subject: [PATCH] - Added `position` argument to `music.mpd.add` - Added RSS feed parser plugin --- platypush/plugins/http/request/rss.py | 23 +++++++++++++++++++++++ platypush/plugins/music/mpd/__init__.py | 12 +++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 platypush/plugins/http/request/rss.py diff --git a/platypush/plugins/http/request/rss.py b/platypush/plugins/http/request/rss.py new file mode 100644 index 0000000000..686b0ed255 --- /dev/null +++ b/platypush/plugins/http/request/rss.py @@ -0,0 +1,23 @@ +import feedparser + +from platypush.plugins import action +from platypush.plugins.http.request import HttpRequestPlugin + +class HttpRequestRssPlugin(HttpRequestPlugin): + """ + Plugin to programmatically retrieve and parse an RSS feed URL. + + Requires: + + * **feedparser** (``pip install feedparser``) + """ + + @action + def get(self, url): + response = super().get(url, output='text').output + feed = feedparser.parse(response) + return feed.entries + + +# vim:sw=4:ts=4:et: + diff --git a/platypush/plugins/music/mpd/__init__.py b/platypush/plugins/music/mpd/__init__.py index d07c9f0fa1..a895280aa4 100644 --- a/platypush/plugins/music/mpd/__init__.py +++ b/platypush/plugins/music/mpd/__init__.py @@ -207,7 +207,7 @@ class MusicMpdPlugin(MusicPlugin): return self._exec('shuffle') @action - def add(self, resource): + def add(self, resource, position=None): """ Add a resource (track, album, artist, folder etc.) to the current playlist @@ -219,14 +219,20 @@ class MusicMpdPlugin(MusicPlugin): for r in resource: r = self._parse_resource(r) try: - self._exec('add', r) + if position is None: + self._exec('add', r) + else: + self._exec('addid', r, position) except Exception as e: self.logger.warning('Could not add {}: {}'.format(r, e)) return self.status().output r = self._parse_resource(resource) - return self._exec('add', r) + + if position is None: + return self._exec('add', r) + return self._exec('addid', r, position) @classmethod def _parse_resource(cls, resource):