From 74946e744f79b42381224eb6dbcdc2da824446f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Mon, 3 Feb 2025 13:49:16 -0500 Subject: [PATCH] youtube: List only long-form videos --- feedleware/youtube/feed.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/feedleware/youtube/feed.py b/feedleware/youtube/feed.py index c45da47..a2d5a33 100644 --- a/feedleware/youtube/feed.py +++ b/feedleware/youtube/feed.py @@ -3,10 +3,6 @@ from ..feedformatter import Feed from .youtube import APIClient -# Minimum duration for videos to be listed in the feed -MINIMUM_DURATION = timedelta(seconds=70) - - def construct_rss(client: APIClient, channel_id: str) -> str: """ Build a RSS stream for a YouTube channel. @@ -18,7 +14,11 @@ def construct_rss(client: APIClient, channel_id: str) -> str: :raises NoSuchChannel: if the channel does not exist """ channel_info = client.channel(channel_id) - videos = client.playlist(channel_info["playlist"]) + + # Retrieve channel playlist which excludes short videos + # see + videos_playlist = "UULF" + channel_id.removeprefix("UC") + videos = client.playlist(videos_playlist) feed = Feed() channel_url = f"https://www.youtube.com/channel/{channel_id}" @@ -31,16 +31,16 @@ def construct_rss(client: APIClient, channel_id: str) -> str: feed.feed["ttl"] = "30" for video in videos: - if video["duration"] >= MINIMUM_DURATION: - feed.items.append({ - "guid": video["id"], - "title": video["title"], - "link": video["url"], - "description": ( - f'

' - + video["description"] - ), - "pubDate": video["published"].timetuple(), - }) + feed.items.append({ + "guid": video["id"], + "title": video["title"], + "link": video["url"], + "description": ( + f'Durée: {video["duration"]}

' + + f'

' + + video["description"] + ), + "pubDate": video["published"].timetuple(), + }) return feed.format_rss2_string()