From 7163afe6711df90aa1a051412ba3ef346fac0a47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Wed, 1 May 2013 20:52:46 +0200 Subject: [PATCH] try to subscribe to pubsubhubbub hubs given in feeds --- mygpo/core/models.py | 1 + mygpo/data/feeddownloader.py | 4 ++++ mygpo/data/podcast.py | 25 +++++++++++++++++++++++++ mygpo/settings.py | 5 +++++ 4 files changed, 35 insertions(+) diff --git a/mygpo/core/models.py b/mygpo/core/models.py index 6539a8c1..20dd189c 100644 --- a/mygpo/core/models.py +++ b/mygpo/core/models.py @@ -172,6 +172,7 @@ class Podcast(Document, SlugMixin, OldIdMixin): flattr_url = StringProperty() outdated = BooleanProperty(default=False) created_timestamp = IntegerProperty() + hub = StringProperty() diff --git a/mygpo/data/feeddownloader.py b/mygpo/data/feeddownloader.py index ad7050d7..8930d49a 100755 --- a/mygpo/data/feeddownloader.py +++ b/mygpo/data/feeddownloader.py @@ -33,6 +33,7 @@ from feedservice.parse.text import ConvertMarkdown from feedservice.parse.models import ParserException from mygpo.utils import file_hash, split_list from mygpo.web.logo import CoverArt +from mygpo.data.podcast import subscribe_at_hub from mygpo.db.couchdb.episode import episode_for_podcast_id_url, \ episodes_for_podcast_uncached from mygpo.db.couchdb.podcast import podcast_for_url @@ -139,6 +140,7 @@ class PodcastUpdater(object): changed |= update_a(podcast, 'common_episode_title', parsed.common_title or podcast.common_episode_title) changed |= update_a(podcast, 'new_location', parsed.new_location or podcast.new_location) changed |= update_a(podcast, 'flattr_url', parsed.flattr) + changed |= update_a(podcast, 'hub', parsed.hub) if podcast.new_location: @@ -175,6 +177,8 @@ class PodcastUpdater(object): podcast.save() + subscribe_at_hub(podcast) + assign_slug(podcast, PodcastSlug) assign_missing_episode_slugs(podcast) diff --git a/mygpo/data/podcast.py b/mygpo/data/podcast.py index f51cee61..0ee2a561 100644 --- a/mygpo/data/podcast.py +++ b/mygpo/data/podcast.py @@ -16,9 +16,15 @@ # from collections import Counter +import logging + +from django.conf import settings from mygpo.db.couchdb.podcast_state import subscribed_users, \ subscribed_podcast_ids_by_user_id +from mygpo import pubsub + +logger = logging.getLogger(__name__) def calc_similar_podcasts(podcast, num=20): @@ -39,3 +45,22 @@ def calc_similar_podcasts(podcast, num=20): podcasts.update(user_counter) return podcasts.most_common(num) + + +def subscribe_at_hub(podcast): + """ Tries to subscribe to the given podcast at its hub """ + + if not podcast.hub: + return + + base_url = settings.DEFAULT_BASE_URL + + if not base_url: + logger.warn('Could not subscribe to podcast {podcast} ' + 'at hub {hub} because DEFAULT_BASE_URL is not ' + 'set.'.format(podcast=podcast, hub=podcast.hub)) + return + + logger.info('subscribing to {podcast} at {hub}.'.format(podcast=podcast, + hub=podcast.hub)) + pubsub.subscribe(podcast.url, podcast.hub, base_url) diff --git a/mygpo/settings.py b/mygpo/settings.py index ae66795d..fbeb9cdb 100644 --- a/mygpo/settings.py +++ b/mygpo/settings.py @@ -258,6 +258,11 @@ FLATTR_MYGPO_THING='https://flattr.com/submit/auto?user_id=stefankoegl&url=http: # The User-Agent string used for outgoing HTTP requests USER_AGENT = 'gpodder.net (+https://github.com/gpodder/mygpo)' +# Base URL of the website that is used if the actually used parameters is not +# available. Request handlers, for example, can access the requested domain. +# Code that runs in background can not do this, and therefore requires a +# default value. This should be set to something like 'http://example.com' +DEFAULT_BASE_URL = '' ### Celery -- 2.11.4.GIT