{ "cells": [ { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "import subprocess\n", "from pathlib import Path\n", "import re\n", "\n", "from tqdm import tqdm\n", "\n", "import pipeline.videos as videos" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 1/1 [00:02<00:00, 2.37s/it]\n" ] } ], "source": [ "VIDEO_DIR = Path(\"videos\")\n", "VIDEO_DIR.mkdir(exist_ok=True)\n", "(VIDEO_DIR / \".gitingore\").write_text(\"**\")\n", "\n", "video_urls = [\"https://www.youtube.com/watch?v=frYIj2FGmMA&foo=bar\"]\n", "\n", "\n", "def get_id(url: str) -> str:\n", " return re.search(r\"(?<=v=)[^&]+\", url).group(0)\n", "\n", "\n", "for video_url in tqdm(video_urls):\n", " video_id = get_id(video_url)\n", " video_path = VIDEO_DIR / f\"{video_id}.mp4\"\n", " if video_path.exists():\n", " print(f\"Skipping {video_path} because it already exists\")\n", " continue\n", " subprocess.run([\"yt-dlp\", \"--quiet\", \"-f\", \"133\", \"-o\", str(video_path), video_url])\n", "\n", "# get_id(video_urls[0])\n", "# # !yt-dlp -f 133 -o \"buster.mp4\" {video_url}\n", "# def download_video(video_url: str) -> None:\n", "# subprocess.run(['yt-dlp', '-f', '133', '-o', 'buster.mp4', video_url])" ] } ], "metadata": { "kernelspec": { "display_name": "semvideo-hackathon-230523", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }