Skip to content

Commit

Permalink
Works on windows installed locally
Browse files Browse the repository at this point in the history
  • Loading branch information
kleag committed Aug 22, 2024
1 parent 5f592bc commit c3499d9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ dependencies = [
"torch >= 2.1.0",
"torchaudio >= 2.1.0",
"openunmix >= 1.3.0",
"pytubefix >= 6.1.2",
"moviepy >= 1.0.3"
"pytubefix >= 6.13.0",
"moviepy >= 1.0.3",
"PySoundFile >= 0.9.0.post1",
]
keywords = ["audio", "video", "track", "split", "gui", "qt"]

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
PySide6
openunmix
torch
pytubefix==6.1.2
pytubefix==6.13.0
moviepy==1.0.3
pydub
ffmpeg
PySoundFile

# setup requirements
setuptools>=54.0.0
Expand Down
9 changes: 5 additions & 4 deletions src/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class Worker(QThread):
extraction_done = Signal()
extraction_failed = Signal(str)

def __init__(self, url, out):
def __init__(self, url, yaas):
super().__init__()
self.update_status.connect(yaas.update_status)
# Get the writable location for application data
self.app_data_path = QStandardPaths.writableLocation(
QStandardPaths.AppDataLocation)
Expand All @@ -32,7 +33,7 @@ def __init__(self, url, out):
print(f'Created app_data_path {self.app_data_path}', file=sys.stderr)

self.url = url
self.out = out
self.out = yaas.args.out
QDir().mkpath(self.out)

def run(self):
Expand All @@ -53,7 +54,7 @@ def run(self):
os.remove(flac_path)

def download_audio(self, url):
self.update_status.emit(f"Downloading audio from {url}...")
self.update_status.emit(f"Downloading audio from {url} ...")
filename = ""
try:
if is_valid_video_url(url):
Expand All @@ -63,7 +64,7 @@ def download_audio(self, url):
video = YouTube(url)
config = Config(out_dir=self.app_data_path, timeout=5000,
max_retries=3)
self.update_status.emit(f"Downloading audio to {self.app_data_path}...")
self.update_status.emit(f"Downloading audio to {self.app_data_path} ...")
path = download_mp3(video, config)

self.update_status.emit(f'Converting video {path} to MP3 File...')
Expand Down
4 changes: 2 additions & 2 deletions src/yaas.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def start_process(self):
url = self.browser.url().url()
if url:
self.update_status(f"Splitting sound track of {url}")
self.worker = Worker(url, self.args.out)
self.worker.update_status.connect(self.update_status)
self.worker = Worker(url, self)
self.worker.ex_exit.connect(self.ex_exit)
# Change the cursor to busy
QApplication.setOverrideCursor(Qt.WaitCursor)
Expand Down Expand Up @@ -124,6 +123,7 @@ def extraction_failed(self, message: str):


def main():
os.environ["QTWEBENGINE_DISABLE_SANDBOX"] = "1"
app = QApplication(sys.argv)

main_window = MainWindow()
Expand Down
12 changes: 7 additions & 5 deletions src/yturl2mp3/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ def download_mp3(video: YouTube, config: Config) -> str:
"""
# returns the mp4 only containing audio
stream = video.streams.get_lowest_resolution()
stream.download(output_path=config.out_dir, timeout=config.timeout,
max_retries=config.max_retries,
skip_existing=True)
path_to_saved = stream.download(
output_path=config.out_dir, timeout=config.timeout,
max_retries=config.max_retries,
skip_existing=True)
path_to_saved = os.path.realpath(path_to_saved)
mp4_path = Path(config.out_dir) / stream.default_filename
return str(mp4_path)
return path_to_saved


def convert_mp4_to_mp3(path: str, delete_after: bool = True) -> str:
Expand All @@ -41,7 +43,7 @@ def convert_mp4_to_mp3(path: str, delete_after: bool = True) -> str:
mp4 = editor.VideoFileClip(path)

mp3 = mp4.audio
mp3.write_audiofile(mp3_path, verbose=False, logger=None)
mp3.write_audiofile(mp3_path, verbose=True, logger=None)

mp3.close()
mp4.close()
Expand Down

0 comments on commit c3499d9

Please sign in to comment.