kabigon 0.8.7__py3-none-any.whl → 0.8.9__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.
- kabigon/playwright.py +4 -2
- kabigon/youtube_ytdlp.py +10 -2
- kabigon/ytdlp.py +17 -11
- {kabigon-0.8.7.dist-info → kabigon-0.8.9.dist-info}/METADATA +1 -1
- {kabigon-0.8.7.dist-info → kabigon-0.8.9.dist-info}/RECORD +8 -8
- {kabigon-0.8.7.dist-info → kabigon-0.8.9.dist-info}/WHEEL +0 -0
- {kabigon-0.8.7.dist-info → kabigon-0.8.9.dist-info}/entry_points.txt +0 -0
- {kabigon-0.8.7.dist-info → kabigon-0.8.9.dist-info}/licenses/LICENSE +0 -0
kabigon/playwright.py
CHANGED
@@ -26,7 +26,8 @@ class PlaywrightLoader(Loader):
|
|
26
26
|
|
27
27
|
with sync_playwright() as p:
|
28
28
|
browser = p.chromium.launch(headless=self.browser_headless)
|
29
|
-
|
29
|
+
context = browser.new_context()
|
30
|
+
page = context.new_page()
|
30
31
|
|
31
32
|
page.goto(url, timeout=self.timeout, wait_until=self.wait_until)
|
32
33
|
|
@@ -46,7 +47,8 @@ class PlaywrightLoader(Loader):
|
|
46
47
|
|
47
48
|
async with async_playwright() as p:
|
48
49
|
browser = await p.chromium.launch(headless=self.browser_headless)
|
49
|
-
|
50
|
+
context = await browser.new_context()
|
51
|
+
page = await context.new_page()
|
50
52
|
|
51
53
|
await page.goto(url, timeout=self.timeout, wait_until=self.wait_until)
|
52
54
|
|
kabigon/youtube_ytdlp.py
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
from urllib.parse import urlparse
|
2
2
|
|
3
|
+
from aioytt.video_id import ALLOWED_NETLOCS
|
4
|
+
from aioytt.video_id import ALLOWED_SCHEMES
|
5
|
+
|
3
6
|
from .loader import Loader
|
4
7
|
from .ytdlp import YtdlpLoader
|
5
8
|
|
6
9
|
|
7
10
|
def check_youtube_url(url: str) -> None:
|
8
|
-
|
9
|
-
|
11
|
+
schema = urlparse(url).scheme
|
12
|
+
if schema not in ALLOWED_SCHEMES:
|
13
|
+
raise ValueError(f"URL scheme is not allowed: {schema}")
|
14
|
+
|
15
|
+
domain = urlparse(url).netloc
|
16
|
+
if domain not in ALLOWED_NETLOCS:
|
17
|
+
raise ValueError(f"URL domain is not allowed: {domain}")
|
10
18
|
|
11
19
|
|
12
20
|
class YoutubeYtdlpLoader(Loader):
|
kabigon/ytdlp.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import hashlib
|
2
2
|
import os
|
3
3
|
import tempfile
|
4
|
+
from pathlib import Path
|
4
5
|
|
5
6
|
import yt_dlp
|
6
7
|
from loguru import logger
|
@@ -8,9 +9,7 @@ from loguru import logger
|
|
8
9
|
from .loader import Loader
|
9
10
|
|
10
11
|
|
11
|
-
def download_audio(url: str) ->
|
12
|
-
filename = os.path.join(tempfile.gettempdir(), hashlib.sha512(url.encode("utf-8")).hexdigest())
|
13
|
-
|
12
|
+
def download_audio(url: str, outtmpl: str | None = None) -> None:
|
14
13
|
ydl_opts = {
|
15
14
|
"format": "bestaudio/best",
|
16
15
|
"postprocessors": [
|
@@ -20,16 +19,19 @@ def download_audio(url: str) -> str:
|
|
20
19
|
"preferredquality": "192",
|
21
20
|
}
|
22
21
|
],
|
23
|
-
"outtmpl": filename,
|
24
|
-
"ffmpeg_location": os.getenv("FFMPEG_PATH", "ffmpeg"),
|
25
22
|
"match_filter": yt_dlp.match_filter_func(["!is_live"]),
|
26
23
|
}
|
27
24
|
|
25
|
+
if outtmpl is not None:
|
26
|
+
ydl_opts["outtmpl"] = outtmpl
|
27
|
+
|
28
|
+
ffmpeg_path = os.getenv("FFMPEG_PATH")
|
29
|
+
if ffmpeg_path is None:
|
30
|
+
ydl_opts["ffmpeg_location"] = ffmpeg_path
|
31
|
+
|
28
32
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
29
33
|
ydl.download([url])
|
30
34
|
|
31
|
-
return filename + ".mp3"
|
32
|
-
|
33
35
|
|
34
36
|
class YtdlpLoader(Loader):
|
35
37
|
def __init__(self, model: str = "tiny") -> None:
|
@@ -44,12 +46,16 @@ class YtdlpLoader(Loader):
|
|
44
46
|
self.load_audio = whisper.load_audio
|
45
47
|
|
46
48
|
def load(self, url: str) -> str:
|
47
|
-
|
48
|
-
|
49
|
+
temp_dir = Path(tempfile.gettempdir())
|
50
|
+
outtmpl = hashlib.sha512(url.encode("utf-8")).hexdigest()
|
51
|
+
path = (temp_dir / outtmpl).with_suffix(".mp3")
|
52
|
+
|
53
|
+
download_audio(url, outtmpl=outtmpl)
|
54
|
+
audio = self.load_audio(path)
|
49
55
|
|
50
56
|
# Clean up the audio file
|
51
|
-
os.remove(
|
57
|
+
os.remove(path)
|
52
58
|
|
53
|
-
logger.info("Transcribing audio file: {}",
|
59
|
+
logger.info("Transcribing audio file: {}", path)
|
54
60
|
result = self.model.transcribe(audio)
|
55
61
|
return result.get("text", "")
|
@@ -5,17 +5,17 @@ kabigon/firecrawl.py,sha256=-5AI9tla_684dtpubY_BRudqLgw28158WdwA1RjJvAA,778
|
|
5
5
|
kabigon/httpx.py,sha256=Zup9DURyWLqoWzaxBbCYAaV-5LSlHUuAcNyyUsZTVag,696
|
6
6
|
kabigon/loader.py,sha256=W2ZdSINQKjG-5XNYweM8lIl19JA4wwd7AE2pueHeO70,380
|
7
7
|
kabigon/pdf.py,sha256=PNOx-Dz_VpN-EVnVar_wJJZdxWrDZrAFE-gSuUR9q7o,1870
|
8
|
-
kabigon/playwright.py,sha256=
|
8
|
+
kabigon/playwright.py,sha256=etzxzAmwpATnB_ckxGU3IE4jgKBdlFDwtP1fN0u4Pr8,1959
|
9
9
|
kabigon/ptt.py,sha256=Gyp2nJrjptkjbwZJ9VEQHX0DEgKBe5QRQOmGVHUUgNA,896
|
10
10
|
kabigon/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
11
11
|
kabigon/reel.py,sha256=qOwWCvcp7xNKg0JDunq_Bsl8yqqMzrnAOI9k5mSqrOU,874
|
12
12
|
kabigon/twitter.py,sha256=aRqAiFxIwln6lteWdoF6SmvbzO62yBTQRzcB7UcVJwk,1046
|
13
13
|
kabigon/utils.py,sha256=eNTLtHLSB2erDac2HH3jWemgfr8Ou_ozwVb8h9BD-4g,922
|
14
14
|
kabigon/youtube.py,sha256=F9GpLa0iUy03wYU94RrrnrXa6ExqbG6CZpqx5bPENWE,1106
|
15
|
-
kabigon/youtube_ytdlp.py,sha256
|
16
|
-
kabigon/ytdlp.py,sha256=
|
17
|
-
kabigon-0.8.
|
18
|
-
kabigon-0.8.
|
19
|
-
kabigon-0.8.
|
20
|
-
kabigon-0.8.
|
21
|
-
kabigon-0.8.
|
15
|
+
kabigon/youtube_ytdlp.py,sha256=Y6h55wYF-5PdxLRxsznFtJDypCedD8g-hY9fgCnfvbg,722
|
16
|
+
kabigon/ytdlp.py,sha256=ex_at_1irwHgcl20Mm0mRZp-rTM92OHnVC5dWQCkI1c,1677
|
17
|
+
kabigon-0.8.9.dist-info/METADATA,sha256=T8EHDM6dcghksnn6mOQ1548AvmYBfYlCefo4eIF9DBo,1264
|
18
|
+
kabigon-0.8.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
19
|
+
kabigon-0.8.9.dist-info/entry_points.txt,sha256=O3FYAO9w-NQvlGMJrBvtrnGHSK2QkUnQBTa30YXRbVE,45
|
20
|
+
kabigon-0.8.9.dist-info/licenses/LICENSE,sha256=H2T3_RTgmcngMeC7p_SXT3GwBLkd2DaNgAZuxulcfiA,1066
|
21
|
+
kabigon-0.8.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|