Last active 1458535125

A script that loads the given (list of) urls, waits for there to be a video tag on the page, then starts downloading the video using the page url as a filename (e.g http://example.com/my-show/episode-1 will produce my-show.episode-1.mp4)

Steven Smith revised this gist 1458571125. Go to revision

1 file changed, 1 insertion

getvideourl.py

@@ -1,4 +1,5 @@
1 1 #!/usr/bin/env python3
2 + # pip install selenium, you probably want firefox as well or it won't work so good
2 3
3 4 import contextlib
4 5 from selenium import webdriver

Steven Smith revised this gist 1458571108. Go to revision

No changes

Steven Smith revised this gist 1458571014. Go to revision

1 file changed, 17 insertions, 5 deletions

getvideourl.py

@@ -1,11 +1,13 @@
1 1 #!/usr/bin/env python3
2 - # pip install selenium, you'll also need firefox installed
3 2
4 3 import contextlib
5 4 from selenium import webdriver
6 5 from selenium.webdriver.support.ui import WebDriverWait
7 6 from selenium.webdriver.support import expected_conditions as EC
7 + from selenium.common.exceptions import TimeoutException
8 + from subprocess import Popen
8 9 from sys import argv, stderr, stdin
10 + from os import environ
9 11
10 12 if len(argv) > 1:
11 13 if argv[1] == "-":
@@ -14,7 +16,17 @@ if len(argv) > 1:
14 16 urls = argv[1:]
15 17 with contextlib.closing(webdriver.Firefox()) as driver:
16 18 for i in urls:
17 - driver.get(i)
18 - WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_tag_name('video'))
19 - print(driver.title, file=stderr)
20 - print(driver.find_element_by_tag_name("video").get_attribute("src"))
19 + while True:
20 + try:
21 + driver.get(i)
22 + WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_tag_name('video'))
23 + video = driver.find_element_by_tag_name("video").get_attribute("src")
24 + show, title = driver.current_url.split("/")[-2:]
25 + filename = "{}.{}.mp4".format(show, title[:title.index("?")])
26 + driver.get("about:blank")
27 + print("Getting {}".format(filename), file=stderr)
28 + wget = Popen(["wget", "-O", filename, video])
29 + wget.wait()
30 + except TimeoutException: # refreshes after ten seconds to try again
31 + continue
32 + break

Steven Smith revised this gist 1458569217. Go to revision

1 file changed, 20 insertions

getvideourl.py(file created)

@@ -0,0 +1,20 @@
1 + #!/usr/bin/env python3
2 + # pip install selenium, you'll also need firefox installed
3 +
4 + import contextlib
5 + from selenium import webdriver
6 + from selenium.webdriver.support.ui import WebDriverWait
7 + from selenium.webdriver.support import expected_conditions as EC
8 + from sys import argv, stderr, stdin
9 +
10 + if len(argv) > 1:
11 + if argv[1] == "-":
12 + urls = [line for line in stdin]
13 + else:
14 + urls = argv[1:]
15 + with contextlib.closing(webdriver.Firefox()) as driver:
16 + for i in urls:
17 + driver.get(i)
18 + WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_tag_name('video'))
19 + print(driver.title, file=stderr)
20 + print(driver.find_element_by_tag_name("video").get_attribute("src"))
Newer Older