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 May 12, 2024
1 parent bcd144b commit 77dc597
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 215 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(self.name)
self.setWindowTitle("About")
self.setWindowFlag(Qt.WindowContextHelpButtonHint, False)
self.setFixedSize(self.size())
self.setWindowIcon(QIcon(
Expand Down
4 changes: 3 additions & 1 deletion core/download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ def download_external_process(self, url, download_path, download_type):
stderr=PIPE
)
error = process.communicate()
error_message = error[1].decode('cp1251', errors='replace')

if process.returncode == 0:
self.downloadFinished.emit(download_path)
else:
self.downloadError.emit(str(error))
self.downloadError.emit(str(error_message))

except Exception as e:
self.downloadError.emit(str(e))
Binary file modified core/download_script.exe
Binary file not shown.
16 changes: 13 additions & 3 deletions core/download_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ def download_track(url, download_path, download_type):
input_file = filename
output_file = f"{name}.mp3"

subprocess.run(["ffmpeg", "-i", input_file, "-y", output_file], creationflags=subprocess.CREATE_NO_WINDOW)
try:
subprocess.run(["ffmpeg", "-i", input_file, "-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)

elif download_type == "playlist":
Expand All @@ -61,7 +66,12 @@ def download_track(url, download_path, download_type):
input_file = filename
output_file = f"{name}.mp3"

subprocess.run(["ffmpeg", "-i", input_file, "-y", output_file], creationflags=subprocess.CREATE_NO_WINDOW)
try:
subprocess.run(["ffmpeg", "-i", input_file, "-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)
Expand Down
85 changes: 36 additions & 49 deletions core/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def _init_shortcuts(self):

def _init_content(self):
self._init_webview()
self._init_splash_screen()
self._init_splash_screen()
self.label_3.hide()

def _init_webview(self):
self.webview = WebEngineView()
Expand Down Expand Up @@ -131,20 +132,10 @@ def _init_splash_screen(self):
self.splash_screen_is_over = False

self.splashScreen = SplashScreen(self.windowIcon(), self)
self.splashScreen.titleBar.hide()
self.splashScreen.setIconSize(QSize(102, 102))
self.show()

def copy_selected_text(self):
selected_text = self.webpage.selectedText()
clipboard = QApplication.clipboard()
clipboard.setText(selected_text)

def paste_copied_text(self):
clipboard = QApplication.clipboard()
text = clipboard.text()
if text:
self.webpage.runJavaScript('document.activeElement.value = "{}";'.format(text))

def go_back(self):
self.webview.back()

Expand Down Expand Up @@ -203,25 +194,27 @@ def go_download(self, download_type):
args=(url, download_path, download_type)
).start()

self.add_download_progress()
self.add_download_progress(download_type)

def add_download_progress(self):
self.label_2.setText("Downloading...")
def add_download_progress(self, download_type):
self.label_2.setText(f"Downloading {download_type}...")
self.label_3.show()
self.dots_count = 0
self.dots_timer = QTimer(self)
self.dots_timer.timeout.connect(self.update_dots)
self.dots_timer.timeout.connect(lambda: self.update_dots(download_type))
self.dots_timer.start(500)

def update_dots(self):
def update_dots(self, download_type):
self.dots_count = (self.dots_count + 1) % 4
dots = "." * self.dots_count
self.label_2.setText("Downloading" + dots)
self.label_2.setText(f"Downloading {download_type}" + dots)

def stop_download_progress(self):
if hasattr(self, 'dots_timer'):
self.dots_timer.stop()
del self.dots_timer
self.label_2.setText("")
self.label_3.hide()

def on_download_finished(self, download_path):
self.stop_download_progress()
Expand All @@ -236,11 +229,12 @@ def on_download_finished(self, download_path):
parent=self
)
open_path_btn = PushButton("Download Path")
open_path_btn.clicked.connect(lambda: self.open_download_path(download_path))
open_path_btn.clicked.connect(lambda: self.open_download_path(download_path, path_msg_box))
path_msg_box.addWidget(open_path_btn)

def open_download_path(self, download_path):
def open_download_path(self, download_path, path_msg_box):
os.startfile(download_path)
path_msg_box.close()

def on_download_error(self, error_message):
self.stop_download_progress()
Expand All @@ -255,18 +249,21 @@ def on_download_error(self, error_message):
parent=self
)
open_error_btn = PushButton("Error Message")
open_error_btn.clicked.connect(lambda: self.open_temp_error(error_message))
open_error_btn.clicked.connect(lambda: self.open_temp_error(error_message, error_msg_box))
error_msg_box.addWidget(open_error_btn)

def open_temp_error(self, error_message):
def open_temp_error(self, error_message, error_msg_box):
import tempfile
with tempfile.NamedTemporaryFile(suffix=".txt", delete=False) as f:
if isinstance(error_message, str):
error_message = error_message.encode('utf-8')

with tempfile.NamedTemporaryFile(suffix=".txt", delete=False, mode='w') as f:
if isinstance(error_message, bytes):
error_message = error_message.decode('utf-8')
f.write(error_message)
f.flush()
os.startfile(f.name)

error_msg_box.close()

def open_mini_player(self):
if not "watch" in self.webview.url().toString():
return
Expand Down Expand Up @@ -304,7 +301,7 @@ def on_load_progress(self, progress):
self.splashScreen.finish()

if self.settings.value("check_for_updates_at_startup", "true") == "true":
self.check_for_updates(startup=True)
self.check_for_updates()
self.splash_screen_is_over = True

with open(f"{self.current_dir}/core/js/add_styles.js", "r") as js_file:
Expand Down Expand Up @@ -487,7 +484,7 @@ def update_url(self, url):
f"{self.current_dir}/resources/icons/disabled_win_toolbar_icons/skip_next_white_24dp.svg"
))

def check_for_updates(self, startup=None):
def check_for_updates(self):
try:
response = requests.get(
"https://api.github.com/repos/deeffest/Youtube-Music-Desktop-Player/releases/latest")
Expand All @@ -497,8 +494,8 @@ def check_for_updates(self, startup=None):
if item_version != self.version:
update_msg_box = InfoBar.new(
icon=f"{self.current_dir}/resources/icons/upgrade_white_24dp.svg",
title=f"New update {item_version} is available!",
content="",
title="",
content=f"New update {item_version} is available!",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM,
Expand All @@ -512,25 +509,15 @@ def check_for_updates(self, startup=None):
sys.exit(),
]
)
update_msg_box.addWidget(download_btn)
else:
if not startup:
InfoBar.info(
title="No new updates found",
content="Wait for it...",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=-1,
parent=self
)
update_msg_box.addWidget(download_btn)

except Exception as e:
InfoBar.error(
title="Update search error:",
content=f"{e}",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
position=InfoBarPosition.BOTTOM,
duration=-1,
parent=self
)
Expand All @@ -539,19 +526,19 @@ def open_changelog(self):
try:
response = requests.get(
"https://api.github.com/repos/deeffest/Youtube-Music-Desktop-Player/releases/latest")
if response.status_code == 200:
data = response.json()
item_notes = data.get("body")
w = MessageBox(f"Change log of the latest version", item_notes, self)
w.cancelButton.hide()
w.exec_()
data = response.json()
item_notes = data.get("body")
w = MessageBox(f"Change log of the latest version", item_notes, self)
w.cancelButton.hide()
w.exec_()

except Exception as e:
InfoBar.error(
title="Error in opening the change log:",
content=f"{e}",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
position=InfoBarPosition.BOTTOM,
duration=-1,
parent=self
)
Expand Down
61 changes: 6 additions & 55 deletions core/mini_player_dialog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5.QtCore import Qt, QRectF, QUrl
from PyQt5.QtGui import QPixmap, QIcon, QPainter, QPen, \
QColor, QMouseEvent, QPainterPath, QBrush
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.uic import loadUi

import requests
Expand All @@ -21,9 +20,6 @@ def __init__(
self.name = name
self.window = parent
self.settings = settings
self.drag_position = None
self.isDragging = False
self.radius = 12

loadUi(
f'{self.current_dir}/core/ui/mini_player_dialog.ui', self
Expand All @@ -40,22 +36,16 @@ def _init_content(self):
self.change_info(self.window.webview.url())
self.update_play_pause_icon()

self.ToolButton.setIcon(
QIcon(f"{self.current_dir}/resources/icons/close_white_24dp.svg"))
self.TransparentToolButton.setIcon(
QIcon(f"{self.current_dir}/resources/icons/skip_previous_white_24dp.svg"))
self.TransparentToolButton_3.setIcon(
QIcon(f"{self.current_dir}/resources/icons/skip_next_white_24dp.svg"))
self.PillToolButton.setIcon(
QIcon(f"{self.current_dir}/resources/icons/push_pin_white_24dp.svg"))

def _init_connect(self):
self.ToolButton.clicked.connect(self.close)
self.TransparentToolButton_2.clicked.connect(self.play_pause_track)
self.TransparentToolButton.clicked.connect(self.window.previous_track)
self.TransparentToolButton_3.clicked.connect(self.window.next_track)
self.window.webview.titleChanged.connect(self.title_changed)
self.PillToolButton.clicked.connect(self.toggle_on_top_hint)

def _init_attributes(self):
self.previous_url = self.window.webview.url()
Expand Down Expand Up @@ -93,40 +83,14 @@ def displayImage(self, url: str) -> None:
except Exception as e:
print(e)

def mouseMoveEvent(self, event: QMouseEvent):
if event.buttons() == Qt.LeftButton and self.drag_position and self.isDragging:
self.move(event.globalPos() - self.drag_position)
super(MiniPlayerDlg, self).mouseMoveEvent(event)

def mousePressEvent(self, event: QMouseEvent):
if event.button() == Qt.LeftButton and event.y() <= 50:
self.drag_position = event.globalPos() - self.frameGeometry().topLeft()
self.isDragging = True
super(MiniPlayerDlg, self).mousePressEvent(event)

def mouseReleaseEvent(self, event: QMouseEvent):
if event.button() == Qt.LeftButton:
self.isDragging = False
super(MiniPlayerDlg, self).mouseReleaseEvent(event)

def toggle_on_top_hint(self):
if self.windowFlags() & Qt.WindowStaysOnTopHint:
self.setWindowFlag(Qt.WindowStaysOnTopHint, False)
self.PillToolButton.setChecked(False)
else:
self.setWindowFlag(Qt.WindowStaysOnTopHint)
self.PillToolButton.setChecked(True)
self.show()

def _init_window(self):
self.window.hide()
self.window.tray_icon.hide()

self.setWindowTitle(self.name)
self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_NoSystemBackground, True)
self.setAttribute(Qt.WA_TranslucentBackground, True)
self.setFixedSize(360, 180)
self.setWindowTitle("Mini-Player")
self.setWindowFlags(Qt.Window)
self.setWindowFlag(Qt.WindowStaysOnTopHint)
self.setFixedSize(360, 150)
self.setWindowIcon(QIcon(
f"{self.current_dir}/resources/icons/icon.ico"))
self.move_to_top_right_corner()
Expand Down Expand Up @@ -158,19 +122,6 @@ def title_changed(self, title):
self.previous_url = self.window.webview.url()

self.update_play_pause_icon()
self.setWindowTitle(title)

def _shape(self):
path = QPainterPath()
path.addRoundedRect(QRectF(0, 0, self.width(), self.height()), self.radius, self.radius)
return path

def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.fillPath(self._shape(), QBrush(QColor(0, 0, 0, 192)))
painter.setPen(QPen(QColor(64, 64, 64), 2))
painter.drawPath(self._shape())

def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
Expand Down
2 changes: 1 addition & 1 deletion core/options_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def set_temp_hide_window_in_tray(self, state):
self.temp_settings["hide_window_in_tray"] = state

def _init_window(self):
self.setWindowTitle(self.name)
self.setWindowTitle("Settings")
self.setWindowFlag(Qt.WindowContextHelpButtonHint, False)
self.setFixedSize(self.size())
self.setWindowIcon(QIcon(
Expand Down
Loading

0 comments on commit 77dc597

Please sign in to comment.