Skip to content

Instantly share code, notes, and snippets.

@AvverbioPronome
Last active March 13, 2019 12:27
Show Gist options
  • Save AvverbioPronome/a5935deaa253d9f073c7f2126fcfcecc to your computer and use it in GitHub Desktop.
Save AvverbioPronome/a5935deaa253d9f073c7f2126fcfcecc to your computer and use it in GitHub Desktop.
download a whole season from raiplay.it
#!/usr/bin/env python3
# USAGE:
# $ ./downloader.py http://www.raiplay.it/programmi/*/puntate | youtube-dl -a -
import sys
import requests
import bs4
from urllib.parse import urljoin
# TODO: (better, selective) Exception handling
def error(message, code=1):
print (message, file=sys.stderr)
exit(code)
if len(sys.argv) > 1:
pages = sys.argv[1:]
else:
pages = [x.rstrip() for x in sys.stdin]
for page in pages:
try:
req = requests.get(page)
req.raise_for_status()
except Exception as e:
error("Problem downloading your page.\n{}".format(e))
try:
html = req.text
soup = bs4.BeautifulSoup(html, 'lxml')
tags = soup.select(".puntateItem a")
if len(tags) == 0:
tags = soup.select("a.singleVodUrl")
except Exception as e:
error("Problem parsing HTML.\n{}".format(e))
if len(tags) > 0:
for tag in tags:
print ("{}".format(urljoin(page, tag.attrs['href'])))
else:
error("No episodes detected at this address.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment