Crude track import
This commit is contained in:
parent
1abee60827
commit
fe4b1f8b5e
@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import webbrowser
|
||||
import os.path
|
||||
import psutil
|
||||
import sys
|
||||
import urllib.parse
|
||||
import webbrowser
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
@ -36,6 +37,7 @@ from sqlalchemy.orm.exc import DetachedInstanceError
|
||||
from ui.dlg_search_database_ui import Ui_Dialog
|
||||
from ui.dlg_SelectPlaylist_ui import Ui_dlgSelectPlaylist
|
||||
from ui.main_window_ui import Ui_MainWindow
|
||||
from utilities import create_track_from_file
|
||||
|
||||
|
||||
class TrackData:
|
||||
@ -85,23 +87,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.check_audacity()
|
||||
self.timer.start(Config.TIMER_MS)
|
||||
|
||||
# def add_file(self) -> None:
|
||||
# # TODO: V2 enahancement to import tracks
|
||||
# dlg = QFileDialog()
|
||||
# dlg.setFileMode(QFileDialog.ExistingFiles)
|
||||
# dlg.setViewMode(QFileDialog.Detail)
|
||||
# dlg.setDirectory(Config.ROOT)
|
||||
# dlg.setNameFilter("Music files (*.flac *.mp3)")
|
||||
|
||||
# if dlg.exec_():
|
||||
# with Session() as session:
|
||||
# for fname in dlg.selectedFiles():
|
||||
# track = create_track_from_file(session, fname)
|
||||
# # Add to playlist on screen
|
||||
# # If we don't specify "repaint=False", playlist will
|
||||
# # also be saved to database
|
||||
# self.visible_playlist_tab().insert_track(session, track)
|
||||
|
||||
def set_main_window_size(self) -> None:
|
||||
"""Set size of window from database"""
|
||||
|
||||
@ -188,6 +173,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.actionEnable_controls.triggered.connect(
|
||||
self.enable_play_next_controls)
|
||||
self.actionExport_playlist.triggered.connect(self.export_playlist_tab)
|
||||
self.actionImport.triggered.connect(self.import_track)
|
||||
self.actionFade.triggered.connect(self.fade)
|
||||
self.actionMoveSelected.triggered.connect(self.move_selected)
|
||||
self.actionNewPlaylist.triggered.connect(self.create_playlist)
|
||||
@ -272,6 +258,18 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# Just return if there's no visible playlist tab
|
||||
return
|
||||
|
||||
def create_playlist_tab(self, session: Session,
|
||||
playlist: Playlists) -> None:
|
||||
"""
|
||||
Take the passed playlist database object, create a playlist tab and
|
||||
add tab to display.
|
||||
"""
|
||||
|
||||
playlist_tab: PlaylistTab = PlaylistTab(
|
||||
musicmuster=self, session=session, playlist_id=playlist.id)
|
||||
idx: int = self.tabPlaylist.addTab(playlist_tab, playlist.name)
|
||||
self.tabPlaylist.setCurrentIndex(idx)
|
||||
|
||||
def disable_play_next_controls(self) -> None:
|
||||
"""
|
||||
Disable "play next" keyboard controls
|
||||
@ -379,6 +377,25 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
self.stop_playing(fade=True)
|
||||
|
||||
def import_track(self) -> None:
|
||||
"""Import track file"""
|
||||
|
||||
dlg = QFileDialog()
|
||||
dlg.setFileMode(QFileDialog.ExistingFiles)
|
||||
dlg.setViewMode(QFileDialog.Detail)
|
||||
# TODO: remove hardcoded directory
|
||||
dlg.setDirectory(os.path.join(Config.ROOT, "Singles"))
|
||||
dlg.setNameFilter("Music files (*.flac *.mp3)")
|
||||
|
||||
if dlg.exec_():
|
||||
with Session() as session:
|
||||
for fname in dlg.selectedFiles():
|
||||
track = create_track_from_file(session, fname)
|
||||
# Add to playlist on screen
|
||||
# If we don't specify "repaint=False", playlist will
|
||||
# also be saved to database
|
||||
self.visible_playlist_tab().insert_track(session, track)
|
||||
|
||||
def load_last_playlists(self):
|
||||
"""Load the playlists that we loaded at end of last session"""
|
||||
|
||||
@ -387,18 +404,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.create_playlist_tab(session, playlist)
|
||||
playlist.mark_open(session)
|
||||
|
||||
def create_playlist_tab(self, session: Session,
|
||||
playlist: Playlists) -> None:
|
||||
"""
|
||||
Take the passed playlist database object, create a playlist tab and
|
||||
add tab to display.
|
||||
"""
|
||||
|
||||
playlist_tab: PlaylistTab = PlaylistTab(
|
||||
musicmuster=self, session=session, playlist_id=playlist.id)
|
||||
idx: int = self.tabPlaylist.addTab(playlist_tab, playlist.name)
|
||||
self.tabPlaylist.setCurrentIndex(idx)
|
||||
|
||||
def move_selected(self) -> None:
|
||||
"""Move selected rows to another playlist"""
|
||||
|
||||
|
||||
@ -752,14 +752,17 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1280</width>
|
||||
<height>29</height>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>Fi&le</string>
|
||||
</property>
|
||||
<addaction name="actionImport"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionE_xit"/>
|
||||
<addaction name="separator"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuPlaylist">
|
||||
<property name="title">
|
||||
@ -1011,6 +1014,14 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<string>Enable controls</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionImport">
|
||||
<property name="text">
|
||||
<string>Import...</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Shift+I</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="icons.qrc"/>
|
||||
|
||||
@ -349,7 +349,7 @@ class Ui_MainWindow(object):
|
||||
self.gridLayout_6.addLayout(self.horizontalLayout_2, 3, 0, 1, 1)
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 1280, 29))
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 1280, 24))
|
||||
self.menubar.setObjectName("menubar")
|
||||
self.menuFile = QtWidgets.QMenu(self.menubar)
|
||||
self.menuFile.setObjectName("menuFile")
|
||||
@ -441,7 +441,12 @@ class Ui_MainWindow(object):
|
||||
self.actionAdd_note.setObjectName("actionAdd_note")
|
||||
self.actionEnable_controls = QtWidgets.QAction(MainWindow)
|
||||
self.actionEnable_controls.setObjectName("actionEnable_controls")
|
||||
self.actionImport = QtWidgets.QAction(MainWindow)
|
||||
self.actionImport.setObjectName("actionImport")
|
||||
self.menuFile.addAction(self.actionImport)
|
||||
self.menuFile.addSeparator()
|
||||
self.menuFile.addAction(self.actionE_xit)
|
||||
self.menuFile.addSeparator()
|
||||
self.menuPlaylist.addAction(self.actionNewPlaylist)
|
||||
self.menuPlaylist.addAction(self.actionOpenPlaylist)
|
||||
self.menuPlaylist.addAction(self.actionClosePlaylist)
|
||||
@ -546,4 +551,6 @@ class Ui_MainWindow(object):
|
||||
self.actionAdd_note.setText(_translate("MainWindow", "Add note..."))
|
||||
self.actionAdd_note.setShortcut(_translate("MainWindow", "Ctrl+T"))
|
||||
self.actionEnable_controls.setText(_translate("MainWindow", "Enable controls"))
|
||||
self.actionImport.setText(_translate("MainWindow", "Import..."))
|
||||
self.actionImport.setShortcut(_translate("MainWindow", "Ctrl+Shift+I"))
|
||||
import icons_rc
|
||||
|
||||
@ -6,6 +6,13 @@ import shutil
|
||||
import tempfile
|
||||
|
||||
from config import Config
|
||||
from helpers import (
|
||||
fade_point,
|
||||
get_audio_segment,
|
||||
get_tags,
|
||||
leading_silence,
|
||||
trailing_silence,
|
||||
)
|
||||
from log import DEBUG, INFO
|
||||
from models import Notes, Playdates, Session, Tracks
|
||||
from mutagen.flac import FLAC
|
||||
@ -66,23 +73,24 @@ def create_track_from_file(session, path, normalise=None, interactive=False):
|
||||
INFO(msg)
|
||||
INFO("-" * len(msg))
|
||||
INFO("Get track info...")
|
||||
t = get_music_info(path)
|
||||
t = get_tags(path)
|
||||
title = t['title']
|
||||
artist = t['artist']
|
||||
if interactive:
|
||||
INFO(f" Title: \"{title}\"")
|
||||
INFO(f" Artist: \"{artist}\"")
|
||||
# Check for duplicate
|
||||
tracks = Tracks.search_titles(session, title)
|
||||
if interactive and tracks:
|
||||
print("Found the following possible matches:")
|
||||
for track in tracks:
|
||||
print(f'"{track.title}" by {track.artist}')
|
||||
response = input("Continue [c] or abort [a]?")
|
||||
if not response:
|
||||
return
|
||||
if response[0].lower() not in ['c', 'y']:
|
||||
return
|
||||
if interactive:
|
||||
tracks = Tracks.search_titles(session, title)
|
||||
if tracks:
|
||||
print("Found the following possible matches:")
|
||||
for track in tracks:
|
||||
print(f'"{track.title}" by {track.artist}')
|
||||
response = input("Continue [c] or abort [a]?")
|
||||
if not response:
|
||||
return
|
||||
if response[0].lower() not in ['c', 'y']:
|
||||
return
|
||||
track = Tracks.get_or_create(session, path)
|
||||
track.title = title
|
||||
track.artist = artist
|
||||
|
||||
Loading…
Reference in New Issue
Block a user