From anonymous, 1 Month ago, written in Python.
Embed
  1. #!/usr/bin/env python3
  2.  
  3. import pathlib
  4. import sys
  5. import argparse
  6. from glob import glob
  7. from pprint import pprint
  8. from time import time, mktime, strptime
  9. from datetime import datetime
  10.  
  11. import opml
  12. import feedparser
  13. import youtube_dl
  14.  
  15.  
  16. def main():
  17.     parser = argparse.ArgumentParser()
  18.     parser.add_argument('subs_filename', default='subs.xml')
  19.     args = parser.parse_args()
  20.  
  21.     last_txt = pathlib.Path('last.txt')
  22.     if not last_txt.exists():
  23.         last_txt.write_text(str(time()))
  24.         print('Initialized a last.txt file with current timestamp.')
  25.         return
  26.  
  27.     ptime = datetime.utcfromtimestamp(float(last_txt.read_text()))
  28.  
  29.     outline = opml.parse(args.subs_filename)
  30.     urls = [item.xmlUrl for item in outline[0]]
  31.  
  32.     videos = []
  33.     for i, url in enumerate(urls, start=1):
  34.         print(f'Parsing through channel {i} out of {len(urls)}', end='\r')
  35.         feed = feedparser.parse(url)
  36.         for item in feed['items']:
  37.             timef = item['published_parsed']
  38.             dt = datetime.fromtimestamp(mktime(timef))
  39.             if dt > ptime:
  40.                 videos.append(item['link'])
  41.  
  42.     print()
  43.     if videos:
  44.         print(f'{len(videos)} new videos found')
  45.     else:
  46.         print('Sorry, no new video found')
  47.  
  48.     with youtube_dl.YoutubeDL() as ydl, open('vids.txt', 'w') as f:
  49.         for url in videos:
  50.             info = ydl.extract_info(url, download=False)
  51.             desc = f"{info['uploader']} - {info['title']}"
  52.             print(desc)
  53.             f.write(f"{url}  # {desc}\n")
  54.  
  55.     last_txt.write_text(str(time()))
  56.  
  57.  
  58. if __name__ == '__main__':
  59.     main()
  60.