Skip to content

Instantly share code, notes, and snippets.

@Glamhoth
Created December 15, 2019 15:41
Show Gist options
  • Save Glamhoth/fbd4c5df6b15e004b2942ac47f4fb560 to your computer and use it in GitHub Desktop.
Save Glamhoth/fbd4c5df6b15e004b2942ac47f4fb560 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import sys
import wget
import multiprocessing as mp
from contextlib import redirect_stdout
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from urllib import request
def download_video(id):
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
try:
driver.get('https://tvgry.pl/wideo.asp?ID=' + str(id))
except:
print(f'Timeout on {id}')
driver.close()
return
video_url = ''
try:
video_url = driver.execute_script('return jwplayer_setup.sources[0].file');
except:
print(f'Unable to download video {id}')
driver.close()
return
print(f'Downloading {driver.title} ({id})')
clean_title = driver.title
for c in '\\/:*?"<>|':
clean_title = clean_title.replace(c, '')
out_file = 'downloads/' + str(id) + ' - ' + clean_title + '.mp4'
if os.path.exists(out_file):
print(f'Video {id} is already downloaded')
driver.close()
return
with open(os.devnull, 'w') as devnull:
with redirect_stdout(devnull):
wget.download(video_url, out_file)
driver.close()
def check_for_download_folder():
path = os.path.join(os.getcwd(), "downloads");
if os.path.exists(path) == False:
os.mkdir(path);
def main():
check_for_download_folder();
options = Options()
options.headless = True
global driver
driver = webdriver.Firefox(options=options)
pool = mp.Pool(mp.cpu_count())
result = pool.map(download_video, range(int(sys.argv[1]), int(sys.argv[2])))
driver.stop_client()
driver.quit()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment