aboutsummaryrefslogtreecommitdiff
path: root/artetv_dl
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-08-05 09:45:26 +0200
committerneodarz <neodarz@neodarz.net>2019-08-05 09:45:26 +0200
commit13b54779952bd1f56bac6d5fd8490b0bfa12f71d (patch)
treebf62ee649847930b7ab00fcae7af587f28371e1f /artetv_dl
parent6d18f1615f76336f612aca8c13806f33f0a05472 (diff)
downloadarte.tv-dl-13b54779952bd1f56bac6d5fd8490b0bfa12f71d.tar.xz
arte.tv-dl-13b54779952bd1f56bac6d5fd8490b0bfa12f71d.zip
Add ability to download a collection
Diffstat (limited to 'artetv_dl')
-rwxr-xr-xartetv_dl/__main__.py57
1 files changed, 44 insertions, 13 deletions
diff --git a/artetv_dl/__main__.py b/artetv_dl/__main__.py
index 8e6c759..58ce3d9 100755
--- a/artetv_dl/__main__.py
+++ b/artetv_dl/__main__.py
@@ -6,20 +6,8 @@ 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]+" <arte.tv_link>")
- 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]
-
- programId = re.findall('[0-9A-Z]{6}-[0-9A-Z]{3}-[0-9A-Z]', url)[0]
-
- url = "https://api.arte.tv/api/player/v1/config/en/{}".format(programId)
+def download(url):
content = urlopen(url)
json_data = json.loads(content.read().decode())
name = json_data['videoJsonPlayer']['VTI']
@@ -34,5 +22,48 @@ def main():
print(e)
+def main():
+ if len(sys.argv) != 2:
+ print("Usage:")
+ print(" "+sys.argv[0]+" <arte.tv_link>")
+ 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]
+
+ programId = re.findall('[0-9A-Z]{6}-[0-9A-Z]{3}-[0-9A-Z]', url)
+
+ collection = re.findall('[0-9A-Z]{2}-[0-9A-Z]{6}', url)
+
+ if len(programId) > 0:
+ url = "https://api.arte.tv/api/player/v1/config/en/{}".format(programId[0])
+
+ download(url)
+ elif len(collection) > 0:
+ content = urlopen(url)
+
+ soup = BeautifulSoup(content, "lxml")
+
+ links = soup.find_all("a", {"class": "next-teaser__link"}, href=True)
+
+ for link in links:
+ programId = re.findall('[0-9A-Z]{6}-[0-9A-Z]{3}-[0-9A-Z]', link['href'])
+ url = "https://api.arte.tv/api/player/v1/config/en/{}".format(programId[0])
+ download(url)
+
+ if not links:
+ url = "https://api.arte.tv/api/player/v1/collectionData/en/{}".format(collection[0])
+ content = urlopen(url)
+ json_data = json.loads(content.read().decode())
+ videos = json_data['videos']
+ for video in videos:
+ url = "https://api.arte.tv/api/player/v1/config/en/{}".format(video['programId'])
+ download(url)
+
+ else:
+ print("This is not a valid url")
+
+
if __name__ == "__main__":
main()