kabigon 0.8.8__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/ytdlp.py +17 -11
- {kabigon-0.8.8.dist-info → kabigon-0.8.9.dist-info}/METADATA +1 -1
- {kabigon-0.8.8.dist-info → kabigon-0.8.9.dist-info}/RECORD +6 -6
- {kabigon-0.8.8.dist-info → kabigon-0.8.9.dist-info}/WHEEL +0 -0
- {kabigon-0.8.8.dist-info → kabigon-0.8.9.dist-info}/entry_points.txt +0 -0
- {kabigon-0.8.8.dist-info → kabigon-0.8.9.dist-info}/licenses/LICENSE +0 -0
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", "")
|
@@ -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=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
|