youthsee 0.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
examples/download.py ADDED
@@ -0,0 +1,8 @@
1
+ from ..youthsee.services.cookies_extractor import CookiesExtractor
2
+ from ..youthsee.services.video_downloader import VideoDownloader
3
+
4
+ DOWNLOAD_STORE = "~/Downloads/_YouthSee"
5
+
6
+ if __name__ == "__main__":
7
+ CookiesExtractor().export_cookies_txt("cookies.txt", domain="youtube.com")
8
+ VideoDownloader(DOWNLOAD_STORE).download("https://www.youtube.com/watch?v=TQjLFNpu4r8")
@@ -0,0 +1,4 @@
1
+ from ..youthsee.services.cookies_extractor import CookiesExtractor
2
+
3
+ if __name__ == "__main__":
4
+ print(CookiesExtractor().export_cookies_str(domain="youtube.com"))
@@ -0,0 +1,7 @@
1
+ from ..youthsee.services.channel_manager import ChannelManager
2
+
3
+ if __name__ == "__main__":
4
+ cm = ChannelManager(channel_url="https://www.youtube.com/@IBM/videos")
5
+ videos = cm.get_video_infos()
6
+ print(f"Total videos: {len(videos)}")
7
+ print(videos)
youthsee/cli.py ADDED
@@ -0,0 +1,76 @@
1
+ import typer
2
+ from pathlib import Path
3
+ from typing import Optional
4
+
5
+ from .services.channel_manager import ChannelManager
6
+ from .services.cookies_extractor import CookiesExtractor
7
+ from .services.video_downloader import VideoDownloader
8
+
9
+
10
+ app = typer.Typer(help="Youthsee – YouTube knowledge pipeline")
11
+
12
+
13
+ # ─────────────────────────
14
+ # 🍪 Cookies
15
+ # ─────────────────────────
16
+
17
+ @app.command("show-cookies")
18
+ def show_cookies():
19
+ """
20
+ Show extracted YouTube cookies from browser (debug purpose).
21
+ """
22
+ print(CookiesExtractor().export_cookies_str(domain="youtube.com"))
23
+
24
+
25
+ @app.command("save-cookies")
26
+ def save_cookies(
27
+ output: Path = typer.Option("cookies.txt", help="Output cookies.txt"),
28
+ ):
29
+ """
30
+ Export YouTube cookies to cookies.txt (Netscape format).
31
+ """
32
+ CookiesExtractor().export_cookies_txt(output_file=output, domain="youtube.com")
33
+ typer.echo(f"✅ Cookies saved to {output}")
34
+
35
+
36
+ # ─────────────────────────
37
+ # 🎬 Download
38
+ # ─────────────────────────
39
+
40
+ @app.command("download-video")
41
+ def download_video(
42
+ url: str = typer.Argument(..., help="YouTube video URL"),
43
+ cookies: Path = typer.Option("cookies.txt", help="cookies.txt"),
44
+ outdir: Path = typer.Option("~/Downloads/_YouthSee", help="Output directory"),
45
+ ):
46
+ """
47
+ Download YouTube video.
48
+ """
49
+ CookiesExtractor().export_cookies_txt(cookies, domain="youtube.com")
50
+ VideoDownloader(outdir).download(url)
51
+ typer.echo(f"⬇️ Video has downloaded to: {outdir}")
52
+
53
+
54
+ # ─────────────────────────
55
+ # 📋 List videos
56
+ # ─────────────────────────
57
+
58
+ @app.command("list-videos")
59
+ def list_videos(
60
+ channel_url: str = typer.Argument(..., help="Channel URL"),
61
+ only: Optional[str] = typer.Option(
62
+ None, help="Filter: video | short | live"
63
+ ),
64
+ ):
65
+ """
66
+ List videos in a channel (optionally filter shorts/live).
67
+ """
68
+ cm = ChannelManager(channel_url=channel_url)
69
+ videos = cm.get_video_infos()
70
+
71
+ for v in videos:
72
+ typer.echo(
73
+ f"{v['title']:<90} ({v['duration']}s)"
74
+ )
75
+
76
+ typer.echo(f"\nTotal: {len(videos)}")
@@ -0,0 +1,29 @@
1
+ from yt_dlp import YoutubeDL
2
+
3
+
4
+ class ChannelManager:
5
+
6
+ def __init__(self, channel_url):
7
+ self._channel_url = channel_url
8
+ self._ydl_opts = {
9
+ "extract_flat": True, # --flat-playlist
10
+ "skip_download": True,
11
+ "quiet": True,
12
+ }
13
+
14
+ def get_video_infos(self):
15
+ return list(self._video_iter())
16
+
17
+ def _video_iter(self):
18
+ with YoutubeDL(self._ydl_opts) as ydl:
19
+ info = ydl.extract_info(self._channel_url, download=False)
20
+
21
+ for e in info["entries"]:
22
+ yield {
23
+ "id": e.get("id"),
24
+ "title": e.get("title"),
25
+ "url": e.get("url"),
26
+ "duration": e.get("duration"),
27
+ "upload_date": e.get("upload_date"),
28
+ "channel": e.get("channel"),
29
+ }
@@ -0,0 +1,63 @@
1
+ import browser_cookie3
2
+ import http.cookiejar as cookiejar
3
+
4
+ class CookiesExtractor:
5
+
6
+ def export_cookies_jar(self, domain: str | None = None):
7
+ """
8
+ Export cookies từ Google Chrome ra MozillaCookieJar object (Netscape format)
9
+
10
+ :param domain: ví dụ "youtube.com" để lọc cookie
11
+ """
12
+ cj = cookiejar.MozillaCookieJar()
13
+
14
+ # 🔒 Chỉ đọc cookies từ Chrome
15
+ cookies = browser_cookie3.chrome(domain_name=domain)
16
+
17
+ for c in cookies:
18
+ ck = cookiejar.Cookie(
19
+ version=0,
20
+ name=c.name,
21
+ value=c.value,
22
+ port=None,
23
+ port_specified=False,
24
+ domain=c.domain,
25
+ domain_specified=True,
26
+ domain_initial_dot=c.domain.startswith("."),
27
+ path=c.path,
28
+ path_specified=True,
29
+ secure=c.secure,
30
+ expires=c.expires,
31
+ discard=False,
32
+ comment=None,
33
+ comment_url=None,
34
+ rest={"HttpOnly": c.has_nonstandard_attr("HttpOnly")},
35
+ rfc2109=True,
36
+ )
37
+ cj.set_cookie(ck)
38
+
39
+ return cj
40
+
41
+ def export_cookies_txt(self,
42
+ output_file: str = "cookies.txt",
43
+ domain: str | None = None,
44
+ ):
45
+ """
46
+ Export cookies từ Google Chrome ra file cookies.txt (Netscape format)
47
+
48
+ :param output_file: đường dẫn file output
49
+ :param domain: ví dụ "youtube.com" để lọc cookie
50
+ """
51
+ cj = self.export_cookies_jar(domain=domain)
52
+ cj.save(output_file, ignore_discard=True, ignore_expires=True)
53
+ print(f"✅ Chrome cookies saved to {output_file}")
54
+
55
+ def export_cookies_str(self, domain: str | None = None) -> str:
56
+ return self._cookiejar_to_string(self.export_cookies_jar(domain=domain))
57
+
58
+ def _cookiejar_to_string(self, cj: cookiejar.MozillaCookieJar) -> str:
59
+ import tempfile
60
+ with tempfile.NamedTemporaryFile(mode="w+", delete=True) as f:
61
+ cj.save(f.name, ignore_discard=True, ignore_expires=True)
62
+ f.seek(0)
63
+ return f.read()
@@ -0,0 +1,45 @@
1
+ from yt_dlp import YoutubeDL
2
+
3
+ from ..utils._path_util import resolve_path
4
+
5
+ class VideoDownloader:
6
+ def __init__(self, download_store, cookies_txt_path: str | None = None):
7
+ self._download_store = resolve_path(download_store)
8
+ self._download_store.mkdir(parents=True, exist_ok=True)
9
+
10
+ self._ydl_opts = {
11
+ # Auth
12
+ "cookiefile": cookies_txt_path or "cookies.txt",
13
+
14
+ # JS challenge (YouTube 2025)
15
+ "js_runtimes": {
16
+ "node": {}
17
+ },
18
+ "extractor_args": {
19
+ "youtube": {
20
+ "player_skip": [],
21
+ }
22
+ },
23
+ "remote_components": ["ejs:github"],
24
+
25
+ # Format: MP4 <= 360p
26
+ "format": "best[ext=mp4][height<=360]",
27
+
28
+ # Output
29
+ "outtmpl": f"{self._download_store}/%(channel)s/%(channel)s | %(title)s | [%(id)s].%(ext)s",
30
+
31
+ "windowsfilenames": True,
32
+ "restrictfilenames": False,
33
+
34
+ # Network stability
35
+ "force_ipv4": True,
36
+ "noplaylist": True,
37
+
38
+ # Logging
39
+ "quiet": False,
40
+ "no_warnings": False,
41
+ }
42
+
43
+ def download(self, yt_url):
44
+ with YoutubeDL(self._ydl_opts) as ydl:
45
+ ydl.download([yt_url])
@@ -0,0 +1,9 @@
1
+ from pathlib import Path
2
+
3
+ def resolve_path(path: str | Path) -> Path:
4
+ """
5
+ Resolve path:
6
+ - expand ~
7
+ - convert to absolute path
8
+ """
9
+ return Path(path).expanduser().resolve()
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: youthsee
3
+ Version: 0.0.7
4
+ Summary: A local-first Python toolkit for collecting, transcribing, and organizing YouTube knowledge.
5
+ License-File: LICENSE
6
+ Requires-Dist: browser-cookie3>=0.20.1
7
+ Requires-Dist: typer>=0.21.1
8
+ Requires-Dist: yt-dlp>=2026.1.31
9
+ Dynamic: license-file
@@ -0,0 +1,14 @@
1
+ examples/download.py,sha256=9K1wsaniI0JA7UP4n4PgXl7PT_bYa9oRLosOmEDvdoY,373
2
+ examples/show_cookies.py,sha256=NuSYIxyDKPFW9SQEOgIUg02s-NoImigOWj7FfaEwzmk,166
3
+ examples/show_videos.py,sha256=87Yf6SNS8YbdoxUwHPzBMIxN78t6NL4l4txUZQqLXJU,260
4
+ youthsee/cli.py,sha256=DA3lyaLzDT8xJJqVqdJ4xIj0zbG5Nms9U2t8hpXeEQo,2368
5
+ youthsee/services/channel_manager.py,sha256=vYj1cu_RFFRI1l0r3VHpciV4mvRsL5QJAkfgQeQD63U,865
6
+ youthsee/services/cookies_extractor.py,sha256=5gRGGFFDb08zfvr0MpEZ-DnqohkBuRyK5j-yhM28tgk,2182
7
+ youthsee/services/video_downloader.py,sha256=7JI-32y-zzVCbAPKfP9FJA2yi9rPM7_YQn3LQia56hM,1307
8
+ youthsee/utils/_path_util.py,sha256=mO6n4-QQL7iuY8KUXXrbSnGCn3Otwp8SeGKLRZDlPOQ,195
9
+ youthsee-0.0.7.dist-info/licenses/LICENSE,sha256=_u5ED1MNh-sLChvQiRE5SXlC-_xNpIK_7x58Sb1spwg,1078
10
+ youthsee-0.0.7.dist-info/METADATA,sha256=rsCq2ft_At2dmbDfSHZo6_dzSfBwz4hjL2PdvO6L_Ks,299
11
+ youthsee-0.0.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
+ youthsee-0.0.7.dist-info/entry_points.txt,sha256=Clvc5p02vwN7sfqhinJqA43SZQFnEwuFl-SWK5STCM0,46
13
+ youthsee-0.0.7.dist-info/top_level.txt,sha256=0pGTWInl_1HmWxAIUcBfXcYrfJ3ikaZISnK6hgD57ps,18
14
+ youthsee-0.0.7.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ youthsee = youthsee.cli:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 youthsee contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ examples
2
+ youthsee