kabigon 0.8.8__py3-none-any.whl → 0.8.10__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/ytdlp.py +21 -15
- {kabigon-0.8.8.dist-info → kabigon-0.8.10.dist-info}/METADATA +1 -1
- {kabigon-0.8.8.dist-info → kabigon-0.8.10.dist-info}/RECORD +6 -6
- {kabigon-0.8.8.dist-info → kabigon-0.8.10.dist-info}/WHEEL +0 -0
- {kabigon-0.8.8.dist-info → kabigon-0.8.10.dist-info}/entry_points.txt +0 -0
- {kabigon-0.8.8.dist-info → kabigon-0.8.10.dist-info}/licenses/LICENSE +0 -0
kabigon/ytdlp.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import hashlib
|
2
1
|
import os
|
3
|
-
import
|
2
|
+
import uuid
|
3
|
+
from pathlib import Path
|
4
4
|
|
5
5
|
import yt_dlp
|
6
6
|
from loguru import logger
|
@@ -8,9 +8,7 @@ from loguru import logger
|
|
8
8
|
from .loader import Loader
|
9
9
|
|
10
10
|
|
11
|
-
def download_audio(url: str) ->
|
12
|
-
filename = os.path.join(tempfile.gettempdir(), hashlib.sha512(url.encode("utf-8")).hexdigest())
|
13
|
-
|
11
|
+
def download_audio(url: str, outtmpl: str | None = None) -> None:
|
14
12
|
ydl_opts = {
|
15
13
|
"format": "bestaudio/best",
|
16
14
|
"postprocessors": [
|
@@ -20,16 +18,20 @@ def download_audio(url: str) -> str:
|
|
20
18
|
"preferredquality": "192",
|
21
19
|
}
|
22
20
|
],
|
23
|
-
"outtmpl": filename,
|
24
|
-
"ffmpeg_location": os.getenv("FFMPEG_PATH", "ffmpeg"),
|
25
21
|
"match_filter": yt_dlp.match_filter_func(["!is_live"]),
|
26
22
|
}
|
27
23
|
|
24
|
+
if outtmpl is not None:
|
25
|
+
ydl_opts["outtmpl"] = outtmpl
|
26
|
+
|
27
|
+
ffmpeg_path = os.getenv("FFMPEG_PATH")
|
28
|
+
if ffmpeg_path is not None:
|
29
|
+
ydl_opts["ffmpeg_location"] = ffmpeg_path
|
30
|
+
|
31
|
+
logger.info("Downloading audio from URL: {} with options: {}", url, ydl_opts)
|
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
|
+
outtmpl = uuid.uuid4().hex[:20]
|
50
|
+
path = str(Path(outtmpl).with_suffix(".mp3"))
|
51
|
+
download_audio(url, outtmpl=outtmpl)
|
49
52
|
|
50
|
-
|
51
|
-
|
53
|
+
try:
|
54
|
+
audio = self.load_audio(path)
|
55
|
+
logger.info("Transcribing audio file: {}", path)
|
56
|
+
result = self.model.transcribe(audio)
|
57
|
+
finally:
|
58
|
+
# Clean up the audio file
|
59
|
+
os.remove(path)
|
52
60
|
|
53
|
-
logger.info("Transcribing audio file: {}", audio_file)
|
54
|
-
result = self.model.transcribe(audio)
|
55
61
|
return result.get("text", "")
|
@@ -13,9 +13,9 @@ 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
15
|
kabigon/youtube_ytdlp.py,sha256=Y6h55wYF-5PdxLRxsznFtJDypCedD8g-hY9fgCnfvbg,722
|
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.
|
16
|
+
kabigon/ytdlp.py,sha256=4AjPY0W8IxbEhCNVXpi_KbBQLGrWn5ThrchhffcJIIU,1718
|
17
|
+
kabigon-0.8.10.dist-info/METADATA,sha256=XGIIEjC0MWovjzhfXrnXsBE3XxGN2V82Y9Y3eiQTjpQ,1265
|
18
|
+
kabigon-0.8.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
19
|
+
kabigon-0.8.10.dist-info/entry_points.txt,sha256=O3FYAO9w-NQvlGMJrBvtrnGHSK2QkUnQBTa30YXRbVE,45
|
20
|
+
kabigon-0.8.10.dist-info/licenses/LICENSE,sha256=H2T3_RTgmcngMeC7p_SXT3GwBLkd2DaNgAZuxulcfiA,1066
|
21
|
+
kabigon-0.8.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|