Compare commits
2 Commits
1a4f842f1f
...
1a16b1022d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a16b1022d | ||
|
|
69fb10fcd9 |
@ -197,6 +197,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.btnSongInfo.clicked.connect(self.song_info_search)
|
||||
self.btnStop.clicked.connect(self.stop)
|
||||
self.spnVolume.valueChanged.connect(self.change_volume)
|
||||
self.tabPlaylist.tabCloseRequested.connect(self.close_tab)
|
||||
|
||||
self.timer.timeout.connect(self.tick)
|
||||
|
||||
@ -228,6 +229,15 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
index = self.tabPlaylist.currentIndex()
|
||||
self.tabPlaylist.removeTab(index)
|
||||
|
||||
def close_tab(self, index):
|
||||
if self.tabPlaylist.widget(index) == self.current_track_playlist_tab:
|
||||
self.statusbar.showMessage("Can't close current track playlist",
|
||||
5000)
|
||||
elif self.tabPlaylist.widget(index) == self.next_track_playlist_tab:
|
||||
self.statusbar.showMessage("Can't close next track playlist", 5000)
|
||||
else:
|
||||
self.tabPlaylist.removeTab(index)
|
||||
|
||||
def create_note(self, session, text):
|
||||
"""
|
||||
Create note
|
||||
|
||||
@ -14,11 +14,13 @@ from mutagen.mp3 import MP3
|
||||
from pydub import AudioSegment, effects
|
||||
from tinytag import TinyTag
|
||||
|
||||
# Globals (I know)
|
||||
messages = []
|
||||
|
||||
def main():
|
||||
"Main loop"
|
||||
|
||||
INFO("Starting")
|
||||
DEBUG("Starting")
|
||||
|
||||
# Parse command line
|
||||
p = argparse.ArgumentParser()
|
||||
@ -36,25 +38,25 @@ def main():
|
||||
|
||||
# Run as required
|
||||
if args.update:
|
||||
INFO("Updating database")
|
||||
DEBUG("Updating database")
|
||||
with Session() as session:
|
||||
update_db(session)
|
||||
elif args.full_update:
|
||||
INFO("Full update of database")
|
||||
DEBUG("Full update of database")
|
||||
with Session() as session:
|
||||
full_update_db(session)
|
||||
elif args.fname:
|
||||
fname = os.path.realpath(args.fname)
|
||||
with Session() as session:
|
||||
create_track_from_file(session, fname, verbose=True)
|
||||
create_track_from_file(session, fname, interactive=True)
|
||||
|
||||
else:
|
||||
INFO("No action specified")
|
||||
|
||||
INFO("Finished")
|
||||
DEBUG("Finished")
|
||||
|
||||
|
||||
def create_track_from_file(session, path, verbose=False):
|
||||
def create_track_from_file(session, path, interactive=False):
|
||||
"""
|
||||
Create track in database from passed path, or update database entry
|
||||
if path already in database.
|
||||
@ -62,7 +64,7 @@ def create_track_from_file(session, path, verbose=False):
|
||||
Return track.
|
||||
"""
|
||||
|
||||
if verbose:
|
||||
if interactive:
|
||||
str = f"Importing {path}"
|
||||
INFO(str)
|
||||
INFO("-" * len(str))
|
||||
@ -70,7 +72,7 @@ def create_track_from_file(session, path, verbose=False):
|
||||
t = get_music_info(path)
|
||||
title = t['title']
|
||||
artist = t['artist']
|
||||
if verbose:
|
||||
if interactive:
|
||||
INFO(f" Title: \"{title}\"")
|
||||
INFO(f" Artist: \"{artist}\"")
|
||||
# Check for duplicate
|
||||
@ -90,7 +92,7 @@ def create_track_from_file(session, path, verbose=False):
|
||||
track.duration = int(round(
|
||||
t['duration'], Config.MILLISECOND_SIGFIGS) * 1000)
|
||||
|
||||
if verbose:
|
||||
if interactive:
|
||||
INFO("Parse for start, fade and silence...")
|
||||
audio = get_audio_segment(path)
|
||||
track.start_gap = leading_silence(audio)
|
||||
@ -102,7 +104,7 @@ def create_track_from_file(session, path, verbose=False):
|
||||
session.commit()
|
||||
|
||||
if Config.NORMALISE_ON_IMPORT:
|
||||
if verbose:
|
||||
if interactive:
|
||||
INFO("Normalise...")
|
||||
# Check type
|
||||
ftype = os.path.splitext(path)[1][1:]
|
||||
@ -329,8 +331,7 @@ def update_db(session):
|
||||
# is filename in database?
|
||||
track = Tracks.get_track_from_filename(session, os.path.basename(path))
|
||||
if not track:
|
||||
INFO(f"songdb.update_db: Adding to database: {path}")
|
||||
create_track_from_file(session, path)
|
||||
messages.append(f"Track missing from database: {path}")
|
||||
else:
|
||||
# Check track info matches found track
|
||||
t = get_music_info(path)
|
||||
@ -345,7 +346,7 @@ def update_db(session):
|
||||
for path in list(db_paths - os_paths):
|
||||
# Manage tracks listed in database but where path is invalid
|
||||
track = Tracks.get_track_from_path(session, path)
|
||||
INFO(f"songdb.update_db(): remove from database: {path=} {track=}")
|
||||
messages.append(f"Remove from database: {path=} {track=}")
|
||||
|
||||
# Remove references from Playdates
|
||||
Playdates.remove_track(session, track.id)
|
||||
@ -364,6 +365,12 @@ def update_db(session):
|
||||
# Remove Track entry pointing to invalid path
|
||||
Tracks.remove_path(session, path)
|
||||
|
||||
# Output messages (so if running via cron, these will get sent to
|
||||
# user)
|
||||
if messages:
|
||||
print("Messages")
|
||||
print("\n".join(messages))
|
||||
|
||||
|
||||
def update_meta(session, track, artist=None, title=None):
|
||||
"""
|
||||
|
||||
@ -468,7 +468,7 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tabsClosable">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="movable">
|
||||
<bool>true</bool>
|
||||
|
||||
@ -208,7 +208,7 @@ class Ui_MainWindow(object):
|
||||
self.gridLayout_3.addWidget(self.frame_5, 1, 0, 1, 1)
|
||||
self.tabPlaylist = QtWidgets.QTabWidget(self.centralwidget)
|
||||
self.tabPlaylist.setDocumentMode(False)
|
||||
self.tabPlaylist.setTabsClosable(False)
|
||||
self.tabPlaylist.setTabsClosable(True)
|
||||
self.tabPlaylist.setMovable(True)
|
||||
self.tabPlaylist.setObjectName("tabPlaylist")
|
||||
self.gridLayout_3.addWidget(self.tabPlaylist, 2, 0, 1, 1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user