Skip to content

Instantly share code, notes, and snippets.

@OakNinja
Last active September 20, 2015 21:58
Show Gist options
  • Select an option

  • Save OakNinja/9c8c4c39e1789571f586 to your computer and use it in GitHub Desktop.

Select an option

Save OakNinja/9c8c4c39e1789571f586 to your computer and use it in GitHub Desktop.
Download new episodes based on keywords from SVT play
import os
import svtplay_dl
import re
import feedparser
__author__ = 'oakninja'
def lines(file_name):
home = os.path.expanduser("~")
path = home + '/' + file_name
if not os.path.isfile(path):
open(path, 'w').close()
with open(path) as f:
content = f.readlines()
f.close()
return content
def search(keywords, text):
for keyword in keywords:
if keyword.strip(' \t\n\r') in text:
# print 'keyword =' + keyword.strip(' \t\n\r') + ' text =' + text
return True
return False
def is_new(downloaded, link):
pattern = re.compile('http://www.svtplay.se/video/([0-9]+)/.+')
id = pattern.search(link)
if id and search(downloaded, id.group(1)):
return False
else:
return True
def find_new_downloads(feed, keywords, downloaded):
new_downloads = []
for entry in feed.entries:
if search(keywords, entry.title) and is_new(downloaded, entry.link):
new_downloads.append(entry)
return new_downloads
def download_new_streams(new_downloads):
pattern = re.compile('http://www.svtplay.se/video/([0-9]+)/.+')
downloaded = []
home = os.path.expanduser("~")
options = svtplay_dl.Options()
options.subtitle = True
options.get_url = False
for item in new_downloads:
options.output = home + '/Movies/svtplay_subscribe/' + item.title + '.mp4'
print(item)
svtplay_dl.get_media(item.link, options)
video_number = pattern.search(item.link)
if video_number:
downloaded.append(video_number.group(1))
f = open(home + '/' + 'svt_new_downloaded', 'a+')
for item in downloaded:
print>>f, item
print('Downloaded ' + item)
f.close()
def svtplay_subscribe():
downloaded = lines('svt_new_downloaded')
# new_downloads = lines('new_downloads')
keywords = lines('svt_keywords')
print('Looking for ...')
print(keywords)
feed = feedparser.parse('http://www.svtplay.se/daniel-tigers-kvarter/rss.xml')
new_downloads = find_new_downloads(feed, keywords, downloaded)
print(new_downloads)
download_new_streams(new_downloads)
svtplay_subscribe()
@OakNinja
Copy link
Author

Download episodes from SVT play based on keywords defined in /usr/keywords. Only downloads new videos. Dependent on svtplay_dl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment