From 15994f11b1396edf9618cb86cbf381cdfe38e1af Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Tue, 30 Jun 2026 09:49:46 +0100 Subject: [PATCH] able to downlaod podcast mp3 --- .../apps/podcast_aggregator/__init__.py | 0 django_code/apps/podcast_aggregator/admin.py | 3 ++ django_code/apps/podcast_aggregator/apps.py | 6 +++ .../podcast_aggregator/migrations/__init__.py | 0 django_code/apps/podcast_aggregator/models.py | 3 ++ django_code/apps/podcast_aggregator/tests.py | 3 ++ django_code/apps/podcast_aggregator/utils.py | 42 +++++++++++++++++++ django_code/apps/podcast_aggregator/views.py | 3 ++ .../apps/telegram_communication/utils.py | 0 9 files changed, 60 insertions(+) create mode 100644 django_code/apps/podcast_aggregator/__init__.py create mode 100644 django_code/apps/podcast_aggregator/admin.py create mode 100644 django_code/apps/podcast_aggregator/apps.py create mode 100644 django_code/apps/podcast_aggregator/migrations/__init__.py create mode 100644 django_code/apps/podcast_aggregator/models.py create mode 100644 django_code/apps/podcast_aggregator/tests.py create mode 100644 django_code/apps/podcast_aggregator/utils.py create mode 100644 django_code/apps/podcast_aggregator/views.py create mode 100644 django_code/apps/telegram_communication/utils.py diff --git a/django_code/apps/podcast_aggregator/__init__.py b/django_code/apps/podcast_aggregator/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_code/apps/podcast_aggregator/admin.py b/django_code/apps/podcast_aggregator/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/django_code/apps/podcast_aggregator/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/django_code/apps/podcast_aggregator/apps.py b/django_code/apps/podcast_aggregator/apps.py new file mode 100644 index 0000000..24f670d --- /dev/null +++ b/django_code/apps/podcast_aggregator/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PodcastAggregatorConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'podcast_aggregator' diff --git a/django_code/apps/podcast_aggregator/migrations/__init__.py b/django_code/apps/podcast_aggregator/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_code/apps/podcast_aggregator/models.py b/django_code/apps/podcast_aggregator/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/django_code/apps/podcast_aggregator/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/django_code/apps/podcast_aggregator/tests.py b/django_code/apps/podcast_aggregator/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/django_code/apps/podcast_aggregator/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/django_code/apps/podcast_aggregator/utils.py b/django_code/apps/podcast_aggregator/utils.py new file mode 100644 index 0000000..448dc66 --- /dev/null +++ b/django_code/apps/podcast_aggregator/utils.py @@ -0,0 +1,42 @@ +import requests +import xmltodict +import urllib.request +from urllib import request as urlrequest +from urllib import parse as urlparse + +from django.template.loader_tags import ExtendsNode + + +def rss_to_dict(url): + response = requests.get(url) + data = xmltodict.parse(response.content) + #print(data['rss']) + title = data['rss']['channel']['title'] + #use first object as it's ordered in a chronological order + today_object = data['rss']['channel']['item'][0] + today_title = today_object['title'] + today_podcast_url = data['rss']['channel']['item'][0]['enclosure']['@url'] + return title,today_title,today_podcast_url + +def download_news_mp3(url_mp3, filename): + print("Downloading again: " + filename +" -- " + url_mp3) + try: + urlrequest.urlretrieve(url_mp3, filename) + except: + print("Can't download " + filename +" -- " + url_mp3 + " == Cancelling") + return 0 + +def pretty_filename(filename,extension=''): + filename = filename.replace(' ', '_') + pretty_filename = filename.replace('/', '_') + if extension != '': + extension = str('.'+extension) + return pretty_filename+extension + +def main(): + url = "https://feeds.audiomeans.fr/feed/44f6a116-20a6-44c4-98c4-b3e1bdd46dce.xml" + today_podcast = rss_to_dict(url) + print(today_podcast) + download_news_mp3(today_podcast[2],pretty_filename(today_podcast[1],'mp3')) + +main() \ No newline at end of file diff --git a/django_code/apps/podcast_aggregator/views.py b/django_code/apps/podcast_aggregator/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/django_code/apps/podcast_aggregator/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/django_code/apps/telegram_communication/utils.py b/django_code/apps/telegram_communication/utils.py new file mode 100644 index 0000000..e69de29