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