Skip to content

Instantly share code, notes, and snippets.

@BaksiLi
Created October 21, 2024 14:20
Show Gist options
  • Save BaksiLi/e0997b567101472b7836e64f67fd847c to your computer and use it in GitHub Desktop.
Save BaksiLi/e0997b567101472b7836e64f67fd847c to your computer and use it in GitHub Desktop.
Download Bauer****d Training App Videos
import os
import asyncio
import aiohttp
import argparse
from tqdm import tqdm
async def download_video(session, url, file_path):
if os.path.exists(file_path):
print(f"[!] Skipping: {file_path} (already downloaded)")
return
try:
async with session.get(url) as response:
response.raise_for_status() # Raise an exception for 4xx or 5xx status codes
total_size = int(response.headers.get("Content-Length", 0))
progress_bar = tqdm(total=total_size, unit="B", unit_scale=True, desc=file_path)
with open(file_path, "wb") as file:
async for chunk in response.content.iter_chunked(1024):
if chunk:
file.write(chunk)
progress_bar.update(len(chunk))
progress_bar.close()
print(f"[+] Downloaded: {file_path}")
with open(log_file, "a") as log:
log.write(f"[+] Downloaded: {file_path}\n")
except aiohttp.ClientError as e:
print(f"[-] Error downloading {file_path}: {str(e)}")
with open(log_file, "a") as log:
log.write(f"[-] Error downloading {file_path}: {str(e)}\n")
async def download_videos(tags, indices):
async with aiohttp.ClientSession() as session:
tasks = []
for tag in tags:
for index in indices:
url = base_url.format(tag=tag, index=index)
filename = f"{tag}-{index}_en.mp4"
file_path = os.path.join(output_dir, filename)
task = asyncio.ensure_future(download_video(session, url, file_path))
tasks.append(task)
await asyncio.gather(*tasks)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Video Downloader")
parser.add_argument("--tags", nargs="+", default=["oa", "gt"], help="List of two-letter tags (default: oa gt)")
parser.add_argument("--indices", type=int, nargs=2, default=[1, 20], help="Range of indices (default: 0 21)")
args = parser.parse_args()
base_url = "https://app-data.bauer****d.de/therapie/v4.3/en/{tag}-{index}_en.mp4"
tags = args.tags
indices = range(args.indices[0], args.indices[1])
output_dir = "downloaded_videos"
os.makedirs(output_dir, exist_ok=True)
log_file = "download_log.txt"
asyncio.run(download_videos(tags, indices))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment