#!/usr/bin/env python3
# file: youtube-feed.py
# vim:fileencoding=utf-8:fdm=marker:ft=python
#
# Copyright © 2019 R.F. Smith <rsmith@xs4all.nl>.
# SPDX-License-Identifier: MIT
# Created: 2019-07-28T13:42:58+0200
# Last modified: 2019-07-28T22:07:52+0200
"""Get the latest video's from your favorite youtube channels."""

import datetime
import html
import json
import os
import re
import requests

base = 'https://www.youtube.com/feeds/videos.xml?channel_id='
now = datetime.datetime.now(tz=datetime.timezone.utc)

# Read limit and channels from the configuration file.
# The file format is JSON, as shown below:
# {
#     "limit": 7,
#     "channels": {
#         "first channel name": "UC7QoixBiFO2zstyEXkbVpVg",
#         "second channel name": "UCvY8pgX_3ksKvZBNFHVoUAQ",
#         "third channel name": "UCk3wqxZummX-HTzYGjHDBpw"
#     }
# }
# The “limit” is optional. If not present, it will be set to 7 days.
# Note that the channelId's above are not real, they're randomly generated!
# You can find the “channelId” in the source of the channel's homepage.
rcpath = os.environ['HOME'] + os.sep + '.youtube-feedrc'
with open(rcpath) as rc:
    settings = json.load(rc)
    channels = settings['channels']
    if 'limit' in settings:
        limit = settings['limit']
    else:
        limit = 7

# Retrieve and print video information
for channel_title, channel_id in channels.items():
    res = requests.get(base + channel_id)
    if not res.ok:
        print(f'Could not retrieve data for “{channel_title}”, skipping it.\n')
        continue
    # nonewlines = ''.join(res.text.splitlines())
    titles = re.findall('<title>(.*?)</title>', res.text, re.IGNORECASE)
    links = re.findall('<link rel="alternate" href="(.*?)"/>', res.text, re.IGNORECASE)
    published = [
        datetime.datetime.fromisoformat(pt) for pt in
        re.findall('<published>(.*?)</published>', res.text, re.IGNORECASE)
    ]
    items = tuple(
        (html.unescape(title), link, date)
        for title, link, date in zip(titles, links, published)
        if 'watch' in link and (now-date).days < limit
    )
    if not items:
        print(f"No video's less than {limit} days old found for “{channel_title}”.\n")
        continue
    print(f"Channel “{channel_title}”")
    for title, link, date in items:
        print(f"* title: “{title}”")
        print(f"   date: {date}")
        print(f"   link: “{link}”")
    print()

@@ -235,18 +235,18 @@
 07-2
-8T22:07:52
+9T00:56:41
 +020
@@ -1547,58 +1547,8 @@
 nue%0A
-    # nonewlines = ''.join(res.text.splitlines())%0A
     
@@ -1578,17 +1578,16 @@
 itle%3E(.*
-?
 )%3C/title
@@ -1670,17 +1670,16 @@
 ref=%22(.*
-?
 )%22/%3E', r
@@ -1774,16 +1774,16 @@
 r pt in%0A
+
         
@@ -1808,17 +1808,16 @@
 shed%3E(.*
-?
 )%3C/publi

Use greedy capture because of newlines.