Spaces:
Runtime error
Runtime error
File size: 2,047 Bytes
1801c3b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
{
"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
}
|