kabigon 0.8.2__py3-none-any.whl → 0.8.3__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 +12 -75
- {kabigon-0.8.2.dist-info → kabigon-0.8.3.dist-info}/METADATA +2 -2
- {kabigon-0.8.2.dist-info → kabigon-0.8.3.dist-info}/RECORD +6 -6
- {kabigon-0.8.2.dist-info → kabigon-0.8.3.dist-info}/WHEEL +0 -0
- {kabigon-0.8.2.dist-info → kabigon-0.8.3.dist-info}/entry_points.txt +0 -0
- {kabigon-0.8.2.dist-info → kabigon-0.8.3.dist-info}/licenses/LICENSE +0 -0
kabigon/ytdlp.py
CHANGED
@@ -1,45 +1,15 @@
|
|
1
|
-
# import functools
|
2
1
|
import hashlib
|
3
2
|
import os
|
4
|
-
|
5
|
-
# import subprocess
|
6
3
|
import tempfile
|
7
|
-
from typing import Final
|
8
4
|
|
9
|
-
# import numpy as np
|
10
5
|
import yt_dlp
|
11
6
|
from loguru import logger
|
12
7
|
|
13
8
|
from .loader import Loader
|
14
9
|
|
15
|
-
try:
|
16
|
-
import whisper
|
17
|
-
except ImportError:
|
18
|
-
logger.info("OpenAI Whisper not installed. Please install it with `pip install openai-whisper`.")
|
19
|
-
|
20
|
-
DEFAULT_FFMPEG_PATH: Final[str] = "ffmpeg"
|
21
|
-
|
22
|
-
|
23
|
-
def hash_url(url: str) -> str:
|
24
|
-
return hashlib.sha512(url.encode("utf-8")).hexdigest()
|
25
|
-
|
26
|
-
|
27
|
-
def get_ffmpeg_path() -> str:
|
28
|
-
path = os.getenv("FFMPEG_PATH")
|
29
|
-
if not path:
|
30
|
-
path = DEFAULT_FFMPEG_PATH
|
31
|
-
logger.warning("FFMPEG_PATH not set, using default: {}", DEFAULT_FFMPEG_PATH)
|
32
|
-
|
33
|
-
return path
|
34
|
-
|
35
10
|
|
36
11
|
def download_audio(url: str) -> str:
|
37
|
-
|
38
|
-
|
39
|
-
filename = os.path.join(
|
40
|
-
tempfile.gettempdir(),
|
41
|
-
hash_url(url),
|
42
|
-
)
|
12
|
+
filename = os.path.join(tempfile.gettempdir(), hashlib.sha512(url.encode("utf-8")).hexdigest())
|
43
13
|
|
44
14
|
ydl_opts = {
|
45
15
|
"format": "bestaudio/best",
|
@@ -51,7 +21,7 @@ def download_audio(url: str) -> str:
|
|
51
21
|
}
|
52
22
|
],
|
53
23
|
"outtmpl": filename,
|
54
|
-
"ffmpeg_location":
|
24
|
+
"ffmpeg_location": os.getenv("FFMPEG_PATH", "ffmpeg"),
|
55
25
|
"match_filter": yt_dlp.match_filter_func(["!is_live"]),
|
56
26
|
}
|
57
27
|
|
@@ -61,58 +31,25 @@ def download_audio(url: str) -> str:
|
|
61
31
|
return filename + ".mp3"
|
62
32
|
|
63
33
|
|
64
|
-
# def load_audio(file: str, sr: int = 16000):
|
65
|
-
# """
|
66
|
-
# Open an audio file and read as mono waveform, resampling as necessary
|
67
|
-
|
68
|
-
# Parameters
|
69
|
-
# ----------
|
70
|
-
# file: str
|
71
|
-
# The audio file to open
|
72
|
-
|
73
|
-
# sr: int
|
74
|
-
# The sample rate to resample the audio if necessary
|
75
|
-
|
76
|
-
# Returns
|
77
|
-
# -------
|
78
|
-
# A NumPy array containing the audio waveform, in float32 dtype.
|
79
|
-
# """
|
80
|
-
# ffmpeg_path = get_ffmpeg_path()
|
81
|
-
|
82
|
-
# # This launches a subprocess to decode audio while down-mixing
|
83
|
-
# # and resampling as necessary. Requires the ffmpeg CLI in PATH.
|
84
|
-
# # fmt: off
|
85
|
-
# cmd = [
|
86
|
-
# ffmpeg_path,
|
87
|
-
# "-nostdin",
|
88
|
-
# "-threads", "0",
|
89
|
-
# "-i", file,
|
90
|
-
# "-f", "s16le",
|
91
|
-
# "-ac", "1",
|
92
|
-
# "-acodec", "pcm_s16le",
|
93
|
-
# "-ar", str(sr),
|
94
|
-
# "-"
|
95
|
-
# ]
|
96
|
-
# # fmt: on
|
97
|
-
# try:
|
98
|
-
# out = subprocess.run(cmd, capture_output=True, check=True).stdout
|
99
|
-
# except subprocess.CalledProcessError as e:
|
100
|
-
# raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e
|
101
|
-
|
102
|
-
# return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0
|
103
|
-
|
104
|
-
|
105
34
|
class YtdlpLoader(Loader):
|
106
35
|
def __init__(self, model: str = "tiny") -> None:
|
36
|
+
try:
|
37
|
+
import whisper
|
38
|
+
except ImportError as e:
|
39
|
+
raise ImportError(
|
40
|
+
"OpenAI Whisper not installed. Please install it with `pip install openai-whisper`."
|
41
|
+
) from e
|
42
|
+
|
107
43
|
self.model = whisper.load_model(model)
|
44
|
+
self.load_audio = whisper.load_audio
|
108
45
|
|
109
46
|
def load(self, url: str) -> str:
|
110
47
|
audio_file = download_audio(url)
|
111
|
-
|
112
|
-
audio = whisper.load_audio(audio_file)
|
48
|
+
audio = self.load_audio(audio_file)
|
113
49
|
|
114
50
|
# Clean up the audio file
|
115
51
|
os.remove(audio_file)
|
116
52
|
|
53
|
+
logger.info("Transcribing audio file: {}", audio_file)
|
117
54
|
result = self.model.transcribe(audio)
|
118
55
|
return result.get("text", "")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: kabigon
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.3
|
4
4
|
Author-email: narumi <toucans-cutouts0f@icloud.com>
|
5
5
|
License-File: LICENSE
|
6
6
|
Requires-Python: >=3.10
|
@@ -29,7 +29,7 @@ Description-Content-Type: text/markdown
|
|
29
29
|
## Installation
|
30
30
|
|
31
31
|
```shell
|
32
|
-
pip install kabigon
|
32
|
+
pip install kabigon[all]
|
33
33
|
playwright install chromium
|
34
34
|
```
|
35
35
|
|
@@ -12,9 +12,9 @@ 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/ytdlp.py,sha256=
|
16
|
-
kabigon-0.8.
|
17
|
-
kabigon-0.8.
|
18
|
-
kabigon-0.8.
|
19
|
-
kabigon-0.8.
|
20
|
-
kabigon-0.8.
|
15
|
+
kabigon/ytdlp.py,sha256=OGVrKRGXY_eHePgDmN52Kkui12NN44LsIPonD_61QBM,1501
|
16
|
+
kabigon-0.8.3.dist-info/METADATA,sha256=uidye_pVnhpAivxY26MlZMSascT1MmuMjBuCAw84Ics,1292
|
17
|
+
kabigon-0.8.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
18
|
+
kabigon-0.8.3.dist-info/entry_points.txt,sha256=O3FYAO9w-NQvlGMJrBvtrnGHSK2QkUnQBTa30YXRbVE,45
|
19
|
+
kabigon-0.8.3.dist-info/licenses/LICENSE,sha256=H2T3_RTgmcngMeC7p_SXT3GwBLkd2DaNgAZuxulcfiA,1066
|
20
|
+
kabigon-0.8.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|