auto
This commit is contained in:
parent
316ad13d18
commit
88c0435173
50
main.py
50
main.py
@ -41,6 +41,7 @@ from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent, QAudioProbe
|
|||||||
from PyQt5.QtGui import QClipboard, QCloseEvent, QFont, QPixmap, QResizeEvent
|
from PyQt5.QtGui import QClipboard, QCloseEvent, QFont, QPixmap, QResizeEvent
|
||||||
from utils import (
|
from utils import (
|
||||||
delete_album_art,
|
delete_album_art,
|
||||||
|
get_id3_tags,
|
||||||
scan_for_music,
|
scan_for_music,
|
||||||
initialize_db,
|
initialize_db,
|
||||||
add_files_to_database,
|
add_files_to_database,
|
||||||
@ -323,15 +324,20 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
def on_play_clicked(self) -> None:
|
def on_play_clicked(self) -> None:
|
||||||
"""Updates the Play & Pause buttons when clicked"""
|
"""Updates the Play & Pause buttons when clicked"""
|
||||||
|
pixmapi = QStyle.StandardPixmap.SP_MediaPlay
|
||||||
|
play_icon = self.style().standardIcon(pixmapi) # type: ignore
|
||||||
|
pixmapi = QStyle.StandardPixmap.SP_MediaPause
|
||||||
|
pause_icon = self.style().standardIcon(pixmapi) # type: ignore
|
||||||
if self.player.state() == QMediaPlayer.State.PlayingState:
|
if self.player.state() == QMediaPlayer.State.PlayingState:
|
||||||
self.player.pause()
|
self.player.pause()
|
||||||
self.playButton.setText("▶️")
|
self.playButton.setText(None)
|
||||||
|
self.playButton.setIcon(pause_icon)
|
||||||
else:
|
else:
|
||||||
if self.player.state() == QMediaPlayer.State.PausedState:
|
if self.player.state() == QMediaPlayer.State.PausedState:
|
||||||
self.player.play()
|
self.player.play()
|
||||||
self.playButton.setText("⏸️")
|
self.playButton.setText(None)
|
||||||
|
self.playButton.setIcon(play_icon)
|
||||||
else:
|
else:
|
||||||
self.play_audio_file()
|
|
||||||
self.playButton.setText("👽")
|
self.playButton.setText("👽")
|
||||||
|
|
||||||
def on_previous_clicked(self) -> None:
|
def on_previous_clicked(self) -> None:
|
||||||
@ -354,7 +360,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
def setup_fonts(self):
|
def setup_fonts(self):
|
||||||
"""Initializes font sizes and behaviors for various UI components"""
|
"""Initializes font sizes and behaviors for various UI components"""
|
||||||
font: QFont = QFont()
|
font: QFont = QFont()
|
||||||
font.setPointSize(16)
|
font.setPointSize(12)
|
||||||
font.setBold(True)
|
font.setBold(True)
|
||||||
self.artistLabel: QLabel
|
self.artistLabel: QLabel
|
||||||
self.artistLabel.setFont(font)
|
self.artistLabel.setFont(font)
|
||||||
@ -363,7 +369,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
)
|
)
|
||||||
|
|
||||||
font: QFont = QFont()
|
font: QFont = QFont()
|
||||||
font.setPointSize(16)
|
font.setPointSize(12)
|
||||||
font.setBold(False)
|
font.setBold(False)
|
||||||
self.titleLabel.setFont(font)
|
self.titleLabel.setFont(font)
|
||||||
self.titleLabel.setTextInteractionFlags(
|
self.titleLabel.setTextInteractionFlags(
|
||||||
@ -371,7 +377,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
)
|
)
|
||||||
|
|
||||||
font: QFont = QFont()
|
font: QFont = QFont()
|
||||||
font.setPointSize(16)
|
font.setPointSize(12)
|
||||||
font.setItalic(True)
|
font.setItalic(True)
|
||||||
self.albumLabel.setFont(font)
|
self.albumLabel.setFont(font)
|
||||||
self.albumLabel.setTextInteractionFlags(
|
self.albumLabel.setTextInteractionFlags(
|
||||||
@ -385,7 +391,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
/ "config.ini"
|
/ "config.ini"
|
||||||
)
|
)
|
||||||
self.config.read(cfg_file)
|
self.config.read(cfg_file)
|
||||||
debug("CONFIG LOADED")
|
debug("load_config()")
|
||||||
|
|
||||||
def get_thread_pool(self) -> QThreadPool:
|
def get_thread_pool(self) -> QThreadPool:
|
||||||
"""Returns the threadpool instance"""
|
"""Returns the threadpool instance"""
|
||||||
@ -408,15 +414,16 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
else:
|
else:
|
||||||
self.status_bar.showMessage(message)
|
self.status_bar.showMessage(message)
|
||||||
|
|
||||||
def play_audio_file(self, filepath: str) -> None:
|
def play_audio_file(self, filepath=None) -> None:
|
||||||
"""
|
"""
|
||||||
Start playback of `tableView.current_song_filepath` & moves playback slider
|
Start playback of `tableView.current_song_filepath` & moves playback slider
|
||||||
"""
|
"""
|
||||||
# self.tableView.set_current_song_filepath()
|
if not filepath:
|
||||||
|
filepath = self.tableView.set_current_song_filepath()
|
||||||
# get metadata
|
# get metadata
|
||||||
self.current_song_metadata = self.tableView.get_current_song_metadata()
|
metadata = get_id3_tags(filepath)[0]
|
||||||
# read the file
|
# read the file
|
||||||
url = QUrl.fromLocalFile(self.tableView.get_current_song_filepath())
|
url = QUrl.fromLocalFile(filepath)
|
||||||
# load the audio content
|
# load the audio content
|
||||||
content = QMediaContent(url)
|
content = QMediaContent(url)
|
||||||
# set the player to play the content
|
# set the player to play the content
|
||||||
@ -424,25 +431,12 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
# self.player.setMedia(QUrl("gst-pipeline: videotestsrc ! autovideosink"))
|
# self.player.setMedia(QUrl("gst-pipeline: videotestsrc ! autovideosink"))
|
||||||
self.player.play() # play
|
self.player.play() # play
|
||||||
self.move_slider() # mover
|
self.move_slider() # mover
|
||||||
# self.player.setPlaybackRate(1.5)
|
|
||||||
|
|
||||||
# assign "now playing" labels & album artwork
|
# assign "now playing" labels & album artwork
|
||||||
if self.current_song_metadata is not None:
|
if metadata is not None:
|
||||||
artist = (
|
artist = metadata["TPE1"][0] if "TPE1" in metadata else None
|
||||||
self.current_song_metadata["TPE1"][0]
|
album = metadata["TALB"][0] if "TALB" in metadata else None
|
||||||
if "TPE1" in self.current_song_metadata
|
title = metadata["TIT2"][0] if "TIT2" in metadata else None
|
||||||
else None
|
|
||||||
)
|
|
||||||
album = (
|
|
||||||
self.current_song_metadata["TALB"][0]
|
|
||||||
if "TALB" in self.current_song_metadata
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
title = (
|
|
||||||
self.current_song_metadata["TIT2"][0]
|
|
||||||
if "TIT2" in self.current_song_metadata
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
self.artistLabel.setText(artist)
|
self.artistLabel.setText(artist)
|
||||||
self.albumLabel.setText(album)
|
self.albumLabel.setText(album)
|
||||||
self.titleLabel.setText(title)
|
self.titleLabel.setText(title)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user