Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
deeffest authored Jun 7, 2024
1 parent 31d9372 commit 30b3b93
Show file tree
Hide file tree
Showing 16 changed files with 962 additions and 102 deletions.
2 changes: 1 addition & 1 deletion core/about_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def open_changelog(self):
self.window.open_changelog()

def _init_window(self):
self.setWindowTitle("About")
self.setWindowTitle("About this app")
self.setWindowFlag(Qt.WindowContextHelpButtonHint, False)
self.setFixedSize(self.size())
self.setWindowIcon(
Expand Down
1 change: 0 additions & 1 deletion core/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ QToolTip {
background-color: rgb(44,44,44);
border: 1px solid rgb(93,93,93);
color: white;
padding: 3px;
}
Binary file modified core/download_script.exe
Binary file not shown.
40 changes: 21 additions & 19 deletions core/download_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,55 @@
import subprocess
import os

def sanitize_filename(filename):
illegal_chars = '<>:"/\\|?*'
for char in illegal_chars:
filename = filename.replace(char, '_')
return filename

def download_track(url, download_path, download_type):
os.chdir(download_path)
if download_type == "track":
yt = YouTube(url)
stream = yt.streams.get_highest_resolution()
filename = stream.download(output_path=download_path)
filename = stream.download()

name, ext = os.path.splitext(filename)
existing_file = os.path.join(download_path, f"{name}.mp3")
input_file = filename
output_file = f"{name}.mp3"
name, ext = os.path.splitext(os.path.basename(filename))
name = sanitize_filename(name)
output_file = f"{name}.mp3"

try:
subprocess.run(["ffmpeg", "-i", input_file, "-y", output_file], creationflags=subprocess.CREATE_NO_WINDOW)
subprocess.run(["ffmpeg", "-i", filename, "-y", output_file], creationflags=subprocess.CREATE_NO_WINDOW)
except FileNotFoundError:
print("FFmpeg is not found. Conversion will be skipped.")
return

os.remove(input_file)

sys.exit(0)

os.remove(filename)

elif download_type == "playlist":
playlist = Playlist(url)
playlist_name = playlist.title.replace("/", "_")
playlist_name = sanitize_filename(playlist.title)
folder_path = os.path.join(download_path, playlist_name)

if not os.path.exists(folder_path):
os.makedirs(folder_path)

os.chdir(folder_path)
for video in playlist.videos:
stream = video.streams.filter(type='video', progressive=True, file_extension='mp4').order_by('resolution').desc().first()
filename = stream.download(output_path=folder_path)
filename = stream.download()

name, ext = os.path.splitext(filename)
existing_file = os.path.join(folder_path, f"{name}.mp3")
input_file = filename
name, ext = os.path.splitext(os.path.basename(filename))
name = sanitize_filename(name)
output_file = f"{name}.mp3"

try:
subprocess.run(["ffmpeg", "-i", input_file, "-y", output_file], creationflags=subprocess.CREATE_NO_WINDOW)
subprocess.run(["ffmpeg", "-i", filename, "-y", output_file], creationflags=subprocess.CREATE_NO_WINDOW)
except FileNotFoundError:
print("FFmpeg is not found. Conversion for this file will be skipped.")
continue

os.remove(input_file)

sys.exit(0)
os.remove(filename)

if __name__ == "__main__":
if len(sys.argv) != 4:
Expand Down
3 changes: 3 additions & 0 deletions core/js/get_titile_and_author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var title = document.querySelector('.title.style-scope.ytmusic-player-bar').innerText;
var author = document.querySelector('.byline.style-scope.ytmusic-player-bar.complex-string').innerText;
[title, author];
106 changes: 69 additions & 37 deletions core/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from PyQt5.QtCore import QSize, Qt, QUrl, QTimer
from PyQt5.QtWinExtras import QWinThumbnailToolBar, \
QWinThumbnailToolButton
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
from PyQt5.QtWebEngineWidgets import QWebEngineSettings, \
QWebEnginePage
from PyQt5 import uic

from qfluentwidgets import InfoBar, InfoBarPosition, \
setTheme, setThemeColor, Theme, SplashScreen, \
PushButton, MessageBox
Expand Down Expand Up @@ -57,16 +57,22 @@ def __init__(
self._init_connect()

def _init_attributes(self):
self.timer_active = False
pass

def _init_connect(self):
self.webview.titleChanged.connect(self.update_window_title)
self.webview.urlChanged.connect(self.update_url)
self.webview.loadProgress.connect(self.on_load_progress)
self.label.mousePressEvent = self.open_in_browser
self.tool_btn_previous.clicked.connect(self.previous_track)
self.tool_btn_next.clicked.connect(self.next_track)
self.tool_btn_play_pause.clicked.connect(self.play_pause_track)
self.ToolButton.clicked.connect(self.go_back)
self.ToolButton_2.clicked.connect(self.go_forward)
self.ToolButton_3.clicked.connect(self.go_home)
self.ToolButton_4.clicked.connect(self.go_reload)
self.ToolButton_5.clicked.connect(self.go_download)
self.ToolButton_6.clicked.connect(self.open_mini_player)
self.ToolButton_7.clicked.connect(self.open_settings_dialog)

def _init_shortcuts(self):
shortcuts = {
Expand All @@ -87,6 +93,7 @@ def _init_content(self):
self._init_webview()
self._init_splash_screen()
self.label_3.hide()
self.label.setText(f"{self.name} {self.version}")

def _init_webview(self):
self.webview = WebEngineView()
Expand Down Expand Up @@ -148,20 +155,20 @@ def go_home(self):
def go_reload(self):
self.webview.reload()

def go_download(self, download_type):
def go_download(self):
if hasattr(self, "dots_timer"):
w = MessageBox(f"The current download request is denied.",
"Wait for the app to finish the current track/playlist download.", self)
w.cancelButton.hide()
w.exec_()
return

if download_type == "track":
if not "watch" in self.webview.url().toString():
return
elif download_type == "playlist":
if not "playlist" in self.webview.url().toString():
return
if "watch" in self.webview.url().toString():
download_type = "track"
elif "playlist" in self.webview.url().toString():
download_type = "playlist"
else:
return

last_download_path = self.settings.value(
"last_download_path",
Expand Down Expand Up @@ -279,10 +286,12 @@ def handleFullscreen(self, request):
request.accept()
self.showFullScreen()
self.frame_2.hide()
self.horizontalFrame.hide()
else:
request.accept()
self.showNormal()
self.frame_2.show()
self.horizontalFrame.show()

def open_in_browser(self, event):
if event.button() == Qt.LeftButton:
Expand Down Expand Up @@ -328,6 +337,12 @@ def open_about_dialog(self):
)
Dlg.exec_()

def handle_copy(self):
self.webpage.triggerAction(QWebEnginePage.Copy)

def handle_paste(self):
self.webpage.triggerAction(QWebEnginePage.Paste)

def create_win_toolbar_buttons(self):
self.tool_btn_previous = QWinThumbnailToolButton(self.win_toolbar)
self.tool_btn_previous.setToolTip('Previous')
Expand Down Expand Up @@ -400,35 +415,37 @@ def set_play_pause_icon(self, is_paused):
))
self.tray_icon.play_pause_action.setIcon(QIcon(
f"{self.current_dir}/resources/icons/disabled_icons/pause_white_24dp.svg"
))

def _init_window(self):
self.setWindowTitle(self.name)
self.setWindowIcon(QIcon(
f"{self.current_dir}/resources/icons/icon.ico")
)
if self.settings.value("save_last_window_size", "true") == "true":
size = self.settings.value("last_window_size", QSize(800,600))
else:
size = QSize(800,600)
self.resize(size)

self._move_window_to_center()
self.raise_()
self.activateWindow()

))

def update_window_title(self, title):
self.setWindowTitle(title)
self.tray_icon.setToolTip(title)
self.update_play_pause_icon()

def update_url(self, url):
self.label.setText(url.toString())
self.label.setMaximumWidth(int(self.width() * 0.8))
self.label.setToolTip(f"{self.label.text()}<br><br>Click to open the current URL in the browser.")
self.LineEdit.setText(url.toString())

self.settings.setValue("last_url", url.toString())


if not self.webpage.history().canGoForward():
self.ToolButton_2.setEnabled(False)
else:
self.ToolButton_2.setEnabled(True)
if not self.webpage.history().canGoBack():
self.ToolButton.setEnabled(False)
else:
self.ToolButton.setEnabled(True)

if "watch" in url.toString():
self.ToolButton_5.setEnabled(True)
self.ToolButton_6.setEnabled(True)
elif "playlist" in url.toString():
self.ToolButton_5.setEnabled(True)
self.ToolButton_6.setEnabled(False)
else:
self.ToolButton_5.setEnabled(False)
self.ToolButton_6.setEnabled(False)

if "watch" in url.toString():
self.tool_btn_previous.setEnabled(True)
self.tool_btn_previous.setIcon(QIcon(
Expand Down Expand Up @@ -483,6 +500,21 @@ def update_url(self, url):
self.tray_icon.next_track_action.setIcon(QIcon(
f"{self.current_dir}/resources/icons/disabled_icons/skip_next_white_24dp.svg"
))

def _init_window(self):
self.setWindowTitle(self.name)
self.setWindowIcon(QIcon(
f"{self.current_dir}/resources/icons/icon.ico")
)
if self.settings.value("save_last_window_size", "true") == "true":
size = self.settings.value("last_window_size", QSize(800,600))
else:
size = QSize(800,600)
self.resize(size)

self._move_window_to_center()
self.raise_()
self.activateWindow()

def check_for_updates(self):
try:
Expand Down Expand Up @@ -557,21 +589,21 @@ def resizeEvent(self, event):
self.settings.setValue("last_window_size", event.size())
self.label.setMaximumWidth(int(self.width() * 0.8))

def exit_app(self):
sys.exit(0)

def closeEvent(self, event):
if self.settings.value("hide_window_in_tray", "true") == "true":
self.hide()
self.tray_icon.show()
event.ignore()
else:
if "watch" in self.webview.url().toString():
w = MessageBox(f"Confirmation of exit",
w = MessageBox(f"Confirmation of exit ✖️",
"Do you really want to quit the app? The current playback will stop.", self)
if w.exec_():
self.exit_app()
else:
event.ignore()
else:
self.exit_app()
self.exit_app()

def exit_app(self):
sys.exit(0)
Loading

0 comments on commit 30b3b93

Please sign in to comment.