youtube: List only long-form videos
This commit is contained in:
parent
6f7852eedb
commit
74946e744f
|
@ -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 <https://stackoverflow.com/a/76602819/3452708>
|
||||
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,13 +31,13 @@ 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'<a href="{video["url"]}"><img src="{video["thumbnail"]}" /></a><br><br>'
|
||||
f'Durée: {video["duration"]}<br><br>'
|
||||
+ f'<a href="{video["url"]}"><img src="{video["thumbnail"]}" /></a><br><br>'
|
||||
+ video["description"]
|
||||
),
|
||||
"pubDate": video["published"].timetuple(),
|
||||
|
|
Loading…
Reference in New Issue