mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 07:09:16 +02:00
See #170: subscribe to 3d-party RSS feeds in Funkwhale
This commit is contained in:
parent
7cae1ae5db
commit
deb1f35779
29 changed files with 1451 additions and 129 deletions
51
api/funkwhale_api/audio/tasks.py
Normal file
51
api/funkwhale_api/audio/tasks.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
import datetime
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
|
||||
from funkwhale_api.taskapp import celery
|
||||
|
||||
from . import models
|
||||
from . import serializers
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@celery.app.task(name="audio.fetch_rss_feeds")
|
||||
def fetch_rss_feeds():
|
||||
limit = timezone.now() - datetime.timedelta(
|
||||
seconds=settings.PODCASTS_RSS_FEED_REFRESH_DELAY
|
||||
)
|
||||
candidates = (
|
||||
models.Channel.objects.external_rss()
|
||||
.filter(actor__last_fetch_date__lte=limit)
|
||||
.values_list("rss_url", flat=True)
|
||||
)
|
||||
|
||||
total = len(candidates)
|
||||
logger.info("Refreshing %s rss feeds…", total)
|
||||
for url in candidates:
|
||||
fetch_rss_feed.delay(rss_url=url)
|
||||
|
||||
|
||||
@celery.app.task(name="audio.fetch_rss_feed")
|
||||
@transaction.atomic
|
||||
def fetch_rss_feed(rss_url):
|
||||
channel = (
|
||||
models.Channel.objects.external_rss()
|
||||
.filter(rss_url=rss_url)
|
||||
.order_by("id")
|
||||
.first()
|
||||
)
|
||||
if not channel:
|
||||
logger.warn("Cannot refresh non external feed")
|
||||
return
|
||||
|
||||
try:
|
||||
serializers.get_channel_from_rss_url(rss_url)
|
||||
except serializers.BlockedFeedException:
|
||||
# channel was blocked since last fetch, let's delete it
|
||||
logger.info("Deleting blocked channel linked to %s", rss_url)
|
||||
channel.delete()
|
Loading…
Add table
Add a link
Reference in a new issue