From 440f1a26ef243f83f1bb2ce43d3e0e7835cf1c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Thu, 4 Oct 2018 23:51:54 +0200 Subject: Introduce python packaging --- arte/__main__.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 arte/__main__.py (limited to 'arte/__main__.py') diff --git a/arte/__main__.py b/arte/__main__.py new file mode 100755 index 0000000..a9e30df --- /dev/null +++ b/arte/__main__.py @@ -0,0 +1,48 @@ +#!/bin/python + +"""A download a video from arte.tv website.""" + +from bs4 import BeautifulSoup +from urllib.request import urlopen, unquote, urlretrieve +import re, json, sys + +def main(): + if len(sys.argv) != 2: + print("Usage:") + print(" "+sys.argv[0]+" ") + print("Example:") + print(" "+sys.argv[0]+" https://www.arte.tv/fr/videos/051868-000-A/liberte-egalite-indemnites-vers-un-revenu-universel/") + sys.exit(0) + + url = sys.argv[1] + + content = urlopen(url) + + soup = BeautifulSoup(content, "lxml") + + iframes = soup.find_all("iframe") + + url = "" + + for iframe in iframes: + url = unquote(iframe['src']) + + url = re.split("url=",url)[1] + url = re.split("\?autostart", url)[0] + + content = urlopen(url) + json = json.loads(content.read().decode()) + name = json['videoJsonPlayer']['VTI'] + url = json['videoJsonPlayer']['VSR']['HTTPS_SQ_1']['url'] + + name=name+".mp4" + try: + print("Downloading '"+name+"'...") + urlretrieve(url, name) + print("\nDownload completed") + except Exception as e: + print(e) + + +if __name__ == "__main__": + main() -- cgit v1.2.1