Skip to content

Commit 2a5e80d

Browse files
committed
Refactor FFmpeg integration and update CI workflows for resource management
- Moved FFmpeg checking logic to a separate module for better organization. - Updated Linux and macOS CI workflows to manage FFmpeg resources more effectively. - Removed obsolete CLI test workflow. - Enhanced downloader to specify FFmpeg location dynamically. - Added logging for FFmpeg path in the main window.
1 parent 5e74c66 commit 2a5e80d

7 files changed

Lines changed: 127 additions & 106 deletions

File tree

.github/workflows/linux-build.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ jobs:
2929
run: |
3030
wget https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz
3131
tar xf ffmpeg-master-latest-linux64-gpl.tar.xz
32-
mv ffmpeg-master-latest-linux64-gpl/bin/ffmpeg ffmpeg
33-
chmod +x ffmpeg
32+
mkdir -p resources
33+
mv ffmpeg-master-latest-linux64-gpl/bin/ffmpeg resources/
34+
chmod +x resources/ffmpeg
3435
3536
- name: Download appimagetool
3637
run: |
@@ -42,22 +43,25 @@ jobs:
4243
pyinstaller --noconfirm --onefile --windowed --name YoutubeGo \
4344
--add-data "assets:assets" \
4445
--add-data "ui/themes:ui/themes" \
45-
--add-data "ffmpeg:." \
46+
--add-data "resources:resources" \
4647
main.py
4748
4849
rm -rf AppDir
4950
mkdir -p AppDir/usr/bin
51+
mkdir -p AppDir/usr/share/youtubego
5052
cp dist/YoutubeGo AppDir/usr/bin/
53+
cp -r resources AppDir/usr/share/youtubego/
5154
cp assets/app.png AppDir/
5255
echo -e "[Desktop Entry]\nName=YoutubeGo\nExec=YoutubeGo\nIcon=app\nType=Application\nCategories=AudioVideo;Video;Utility;" > AppDir/YoutubeGo.desktop
5356
ln -sf usr/bin/YoutubeGo AppDir/AppRun
5457
chmod +x AppDir/AppRun
5558
5659
./appimagetool-x86_64.AppImage --appimage-extract-and-run AppDir
60+
mv YoutubeGo-*-x86_64.AppImage YoutubeGo-x86_64.AppImage
5761
5862
- name: Upload to GitHub Releases
5963
uses: softprops/action-gh-release@v1
6064
with:
61-
files: '*.AppImage'
65+
files: YoutubeGo-x86_64.AppImage
6266
env:
6367
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

.github/workflows/macos-build.yml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Release for macOS
1+
name: Build and Release macOS App
22

33
on:
44
push:
@@ -27,23 +27,56 @@ jobs:
2727
run: |
2828
curl -L https://evermeet.cx/ffmpeg/ffmpeg-6.1.zip -o ffmpeg.zip
2929
unzip ffmpeg.zip
30-
chmod +x ffmpeg
30+
mkdir -p resources
31+
mv ffmpeg resources/
32+
chmod +x resources/ffmpeg
3133
32-
- name: Build macOS App and ZIP
34+
- name: Build macOS App
3335
run: |
34-
pyinstaller --noconfirm --windowed --name YoutubeGo \
36+
pyinstaller --noconfirm --onefile --windowed --name YoutubeGo \
3537
--add-data "assets:assets" \
3638
--add-data "ui/themes:ui/themes" \
37-
--add-data "ffmpeg:." \
39+
--add-data "resources:resources" \
3840
main.py
39-
mkdir -p output
40-
cp -r dist/YoutubeGo.app output/
41-
cd output
42-
zip -r YoutubeGo-macOS.zip YoutubeGo.app
41+
42+
mkdir -p "YoutubeGo.app/Contents/MacOS"
43+
mkdir -p "YoutubeGo.app/Contents/Resources"
44+
cp dist/YoutubeGo "YoutubeGo.app/Contents/MacOS/"
45+
cp -r resources "YoutubeGo.app/Contents/Resources/"
46+
cp assets/app.png "YoutubeGo.app/Contents/Resources/"
47+
48+
# Create Info.plist
49+
cat > "YoutubeGo.app/Contents/Info.plist" << EOL
50+
<?xml version="1.0" encoding="UTF-8"?>
51+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
52+
<plist version="1.0">
53+
<dict>
54+
<key>CFBundleExecutable</key>
55+
<string>YoutubeGo</string>
56+
<key>CFBundleIconFile</key>
57+
<string>app</string>
58+
<key>CFBundleIdentifier</key>
59+
<string>com.youtubego.app</string>
60+
<key>CFBundleName</key>
61+
<string>YoutubeGo</string>
62+
<key>CFBundlePackageType</key>
63+
<string>APPL</string>
64+
<key>CFBundleShortVersionString</key>
65+
<string>4.4</string>
66+
<key>LSMinimumSystemVersion</key>
67+
<string>10.13</string>
68+
<key>NSHighResolutionCapable</key>
69+
<true/>
70+
</dict>
71+
</plist>
72+
EOL
73+
74+
# Create DMG
75+
hdiutil create -volname "YoutubeGo" -srcfolder "YoutubeGo.app" -ov -format UDZO "YoutubeGo.dmg"
4376
4477
- name: Upload to GitHub Releases
4578
uses: softprops/action-gh-release@v1
4679
with:
47-
files: output/YoutubeGo-macOS.zip
80+
files: '*.dmg'
4881
env:
4982
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

.github/workflows/youtubego-cli-tests.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

core/downloader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ def run(self):
159159
"merge_output_format": self.task.output_format.lower(),
160160
"postprocessors": [{
161161
"key": "FFmpegVideoRemuxer",
162-
"preferedformat": self.task.output_format.lower()
163-
}]
162+
"preferedformat": self.task.output_format.lower(),
163+
"when": "post_process"
164+
}],
165+
"ffmpeg_location": self.task.ffmpeg_path if hasattr(self.task, 'ffmpeg_path') else None
164166
})
165167
except Exception as e:
166168
self.log_signal.emit(f"Format configuration failed, falling back to basic format: {str(e)}")

core/ffmpeg_checker.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
import platform
3+
import subprocess
4+
5+
def check_ffmpeg():
6+
try:
7+
app_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
8+
candidates = []
9+
10+
if platform.system() == "Windows":
11+
candidates += [
12+
os.path.join(app_dir, "ffmpeg.exe"),
13+
os.path.join(app_dir, "bin", "ffmpeg.exe"),
14+
os.path.join(app_dir, "resources", "ffmpeg.exe"),
15+
]
16+
else:
17+
candidates += [
18+
os.path.join(app_dir, "ffmpeg"),
19+
os.path.join(app_dir, "bin", "ffmpeg"),
20+
os.path.join(app_dir, "resources", "ffmpeg"),
21+
os.path.join(app_dir, "usr", "share", "youtubego", "resources", "ffmpeg"),
22+
os.path.join(os.path.dirname(app_dir), "Resources", "ffmpeg"),
23+
]
24+
25+
for path in candidates:
26+
if os.path.exists(path) and os.access(path, os.X_OK):
27+
return True, path
28+
29+
if platform.system() == "Windows":
30+
result = subprocess.run(["where", "ffmpeg"], capture_output=True, text=True)
31+
else:
32+
result = subprocess.run(["which", "ffmpeg"], capture_output=True, text=True)
33+
34+
if result.returncode == 0:
35+
ffmpeg_path = result.stdout.strip().splitlines()[0]
36+
if os.path.exists(ffmpeg_path) and os.access(ffmpeg_path, os.X_OK):
37+
test_cmd = f'"{ffmpeg_path}" -version'
38+
test_result = subprocess.run(test_cmd, shell=True, capture_output=True)
39+
if test_result.returncode == 0:
40+
return True, ffmpeg_path
41+
42+
common_paths = []
43+
if platform.system() == "Windows":
44+
common_paths = [
45+
os.path.join(os.environ.get("ProgramFiles", "C:\\Program Files"), "ffmpeg", "bin", "ffmpeg.exe"),
46+
os.path.join(os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)"), "ffmpeg", "bin", "ffmpeg.exe")
47+
]
48+
elif platform.system() == "Darwin":
49+
common_paths = [
50+
"/usr/local/bin/ffmpeg",
51+
"/opt/homebrew/bin/ffmpeg",
52+
os.path.expanduser("~/homebrew/bin/ffmpeg")
53+
]
54+
else:
55+
common_paths = [
56+
"/usr/bin/ffmpeg",
57+
"/usr/local/bin/ffmpeg",
58+
"/snap/bin/ffmpeg"
59+
]
60+
61+
for path in common_paths:
62+
if os.path.exists(path) and os.access(path, os.X_OK):
63+
return True, path
64+
65+
return False, ""
66+
67+
except Exception as e:
68+
print(f"Error checking FFmpeg: {str(e)}")
69+
return False, ""

main.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,9 @@
11
import sys
22
import os
3-
import platform
4-
import subprocess
53
from PyQt5.QtWidgets import QApplication
64
from PyQt5.QtCore import QSharedMemory, QSystemSemaphore, Qt
75
from ui.main_window import MainWindow
8-
9-
def check_ffmpeg():
10-
11-
try:
12-
app_dir = os.path.dirname(os.path.abspath(__file__))
13-
candidates = []
14-
if platform.system() == "Windows":
15-
candidates += [
16-
os.path.join(app_dir, "ffmpeg.exe"),
17-
os.path.join(app_dir, "bin", "ffmpeg.exe"),
18-
os.path.join(app_dir, "resources", "ffmpeg.exe"),
19-
]
20-
else:
21-
candidates += [
22-
os.path.join(app_dir, "ffmpeg"),
23-
os.path.join(app_dir, "bin", "ffmpeg"),
24-
os.path.join(app_dir, "resources", "ffmpeg"),
25-
]
26-
for path in candidates:
27-
if os.path.exists(path) and os.access(path, os.X_OK):
28-
return True, path
29-
30-
if platform.system() == "Windows":
31-
result = subprocess.run(["where", "ffmpeg"], capture_output=True, text=True)
32-
else:
33-
result = subprocess.run(["which", "ffmpeg"], capture_output=True, text=True)
34-
if result.returncode == 0:
35-
ffmpeg_path = result.stdout.strip().splitlines()[0]
36-
if os.path.exists(ffmpeg_path) and os.access(ffmpeg_path, os.X_OK):
37-
test_cmd = f'"{ffmpeg_path}" -version'
38-
test_result = subprocess.run(test_cmd, shell=True, capture_output=True)
39-
if test_result.returncode == 0:
40-
return True, ffmpeg_path
41-
42-
common_paths = []
43-
if platform.system() == "Windows":
44-
common_paths = [
45-
os.path.join(os.environ.get("ProgramFiles", "C:\\Program Files"), "ffmpeg", "bin", "ffmpeg.exe"),
46-
os.path.join(os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)"), "ffmpeg", "bin", "ffmpeg.exe")
47-
]
48-
elif platform.system() == "Darwin":
49-
common_paths = [
50-
"/usr/local/bin/ffmpeg",
51-
"/opt/homebrew/bin/ffmpeg",
52-
os.path.expanduser("~/homebrew/bin/ffmpeg")
53-
]
54-
else:
55-
common_paths = [
56-
"/usr/bin/ffmpeg",
57-
"/usr/local/bin/ffmpeg",
58-
"/snap/bin/ffmpeg"
59-
]
60-
for path in common_paths:
61-
if os.path.exists(path) and os.access(path, os.X_OK):
62-
return True, path
63-
return False, ""
64-
except Exception as e:
65-
print(f"Error checking FFmpeg: {str(e)}")
66-
return False, ""
6+
from core.ffmpeg_checker import check_ffmpeg
677

688
def main():
699
shared_mem = QSharedMemory("YoutubeGO4.4")

ui/main_window.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def __init__(self, ffmpeg_found=None, ffmpeg_path=None):
3636
self.setGeometry(100, 100, 1280, 800)
3737
self.ffmpeg_found = ffmpeg_found if ffmpeg_found is not None else False
3838
self.ffmpeg_path = ffmpeg_path if ffmpeg_path is not None else ""
39+
if self.ffmpeg_found and self.ffmpeg_path:
40+
print(f"FFmpeg path set to: {self.ffmpeg_path}")
3941
self.ffmpeg_label = QLabel()
4042
self.log_dock_visible = True
4143
self.show_logs_btn = AnimatedButton("Logs")

0 commit comments

Comments
 (0)