Created
November 2, 2020 12:35
-
-
Save tothi/ff3c1040291d7a51d0f7787061ff2710 to your computer and use it in GitHub Desktop.
download video files from filmhiradokline.hu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# download video from https://filmhiradokonline.hu | |
# | |
import argparse | |
import requests | |
import urllib.request | |
import sys | |
from tqdm import tqdm | |
from bs4 import BeautifulSoup | |
EXT=".mp4" | |
URL_FO="https://filmhiradokonline.hu/fo/" | |
parser = argparse.ArgumentParser() | |
parser.add_argument("video_url", help="URL of video page (e.g.:https://filmhiradokonline.hu/watch.php?id=6030") | |
args = parser.parse_args() | |
print("[*] opening video page at {}".format(args.video_url)) | |
r = requests.get(args.video_url) | |
bs = BeautifulSoup(r.content, features="lxml") | |
video_id = '-'.join(bs.find("strong", text="Azonosító:").next_sibling.split("-")[:-1]) | |
print("[+] extracted video ID: {}".format(video_id)) | |
url = URL_FO+video_id+EXT | |
hdr = {"Referer": "https://filmhiradokonline.hu/player.php"} | |
out = video_id+EXT | |
print("[*] downloading {} to {}".format(url, out)) | |
req = requests.get(url, headers=hdr, stream=True) | |
file_size = int(req.headers['Content-Length']) | |
chunk_size = 1024 # 1 MB | |
num_bars = int(file_size / chunk_size) | |
with open(out, 'wb') as fp: | |
for chunk in tqdm(req.iter_content(chunk_size=chunk_size), total=num_bars, unit='KB', desc=out, leave=True, file=sys.stdout): | |
fp.write(chunk) | |
print("[+] DONE.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment