getvideourl.py
· 1.4 KiB · Python
Raw
#!/usr/bin/env python3
# pip install selenium, you probably want firefox as well or it won't work so good
import contextlib
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from subprocess import Popen
from sys import argv, stderr, stdin
from os import environ
if len(argv) > 1:
if argv[1] == "-":
urls = [line for line in stdin]
else:
urls = argv[1:]
with contextlib.closing(webdriver.Firefox()) as driver:
for i in urls:
while True:
try:
driver.get(i)
WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_tag_name('video'))
video = driver.find_element_by_tag_name("video").get_attribute("src")
show, title = driver.current_url.split("/")[-2:]
filename = "{}.{}.mp4".format(show, title[:title.index("?")])
driver.get("about:blank")
print("Getting {}".format(filename), file=stderr)
wget = Popen(["wget", "-O", filename, video])
wget.wait()
except TimeoutException: # refreshes after ten seconds to try again
continue
break
| 1 | #!/usr/bin/env python3 |
| 2 | # pip install selenium, you probably want firefox as well or it won't work so good |
| 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 selenium.common.exceptions import TimeoutException |
| 9 | from subprocess import Popen |
| 10 | from sys import argv, stderr, stdin |
| 11 | from os import environ |
| 12 | |
| 13 | if len(argv) > 1: |
| 14 | if argv[1] == "-": |
| 15 | urls = [line for line in stdin] |
| 16 | else: |
| 17 | urls = argv[1:] |
| 18 | with contextlib.closing(webdriver.Firefox()) as driver: |
| 19 | for i in urls: |
| 20 | while True: |
| 21 | try: |
| 22 | driver.get(i) |
| 23 | WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_tag_name('video')) |
| 24 | video = driver.find_element_by_tag_name("video").get_attribute("src") |
| 25 | show, title = driver.current_url.split("/")[-2:] |
| 26 | filename = "{}.{}.mp4".format(show, title[:title.index("?")]) |
| 27 | driver.get("about:blank") |
| 28 | print("Getting {}".format(filename), file=stderr) |
| 29 | wget = Popen(["wget", "-O", filename, video]) |
| 30 | wget.wait() |
| 31 | except TimeoutException: # refreshes after ten seconds to try again |
| 32 | continue |
| 33 | break |