Made the tracks get copied into the library on import.
This commit is contained in:
parent
259b453358
commit
4ae398c6aa
3 changed files with 43 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from PyQt6.QtWidgets import QTabWidget, QAbstractItemView
|
from PyQt6.QtWidgets import QTabWidget, QAbstractItemView
|
||||||
|
|
||||||
from ..player.playlist import Playlist
|
from ..player.playlist import Playlist
|
||||||
|
@ -114,6 +115,30 @@ class Library:
|
||||||
|
|
||||||
playlist.load()
|
playlist.load()
|
||||||
|
|
||||||
|
def import_tracks(self, tracks: list[str]):
|
||||||
|
playlist = Playlist(self.app, "Temporary Playlist", tracks, True)
|
||||||
|
|
||||||
|
self.replace_temporary_playlist(playlist)
|
||||||
|
|
||||||
|
self.load_playlist_views()
|
||||||
|
playlist.load()
|
||||||
|
|
||||||
|
def import_track(self, track):
|
||||||
|
artist_path = os.path.expanduser(f"{self.app.settings.library_path}/artists/{track.metadata.artist}")
|
||||||
|
|
||||||
|
if not os.path.exists(artist_path):
|
||||||
|
os.makedirs(artist_path)
|
||||||
|
|
||||||
|
new_track_path = f"{artist_path}/{track.path.split("/")[-1]}"
|
||||||
|
|
||||||
|
if track.path == new_track_path or os.path.exists(new_track_path): # track is already in the library
|
||||||
|
return
|
||||||
|
|
||||||
|
shutil.copyfile(track.path, new_track_path)
|
||||||
|
|
||||||
|
track.path = new_track_path
|
||||||
|
track.metadata.path = new_track_path
|
||||||
|
|
||||||
def open_playlist(self, playlist_path: str):
|
def open_playlist(self, playlist_path: str):
|
||||||
playlist = Playlist(self.app, "Temporary Playlist", playlist_path)
|
playlist = Playlist(self.app, "Temporary Playlist", playlist_path)
|
||||||
|
|
||||||
|
@ -124,7 +149,13 @@ class Library:
|
||||||
playlist.load()
|
playlist.load()
|
||||||
|
|
||||||
def import_playlist(self, playlist_path: str):
|
def import_playlist(self, playlist_path: str):
|
||||||
self.open_playlist(playlist_path)
|
playlist = Playlist(self.app, "Temporary Playlist", playlist_path, import_tracks=True)
|
||||||
|
|
||||||
|
self.replace_temporary_playlist(playlist)
|
||||||
|
|
||||||
|
self.load_playlist_views()
|
||||||
|
|
||||||
|
playlist.load()
|
||||||
|
|
||||||
def loaded_track(self, track_path: str):
|
def loaded_track(self, track_path: str):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -11,7 +11,7 @@ from ..wobuzzm3u import WobuzzM3U, WBZM3UData
|
||||||
|
|
||||||
|
|
||||||
class Playlist:
|
class Playlist:
|
||||||
def __init__(self, app, title: str, load_from=None):
|
def __init__(self, app, title: str, load_from=None, import_tracks: bool=False):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.title = title # playlist title
|
self.title = title # playlist title
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ class Playlist:
|
||||||
# if None, playlist should be already in the library and will be loaded from a .wbz.m3u
|
# if None, playlist should be already in the library and will be loaded from a .wbz.m3u
|
||||||
self.load_from = load_from
|
self.load_from = load_from
|
||||||
|
|
||||||
|
self.import_tracks = import_tracks
|
||||||
|
|
||||||
# add to unique names so if the playlist is loaded from disk,
|
# add to unique names so if the playlist is loaded from disk,
|
||||||
# no other playlist can be created using the same name
|
# no other playlist can be created using the same name
|
||||||
self.app.utils.unique_names.append(self.title)
|
self.app.utils.unique_names.append(self.title)
|
||||||
|
@ -94,6 +96,10 @@ class Playlist:
|
||||||
|
|
||||||
self.loading = False
|
self.loading = False
|
||||||
|
|
||||||
|
if self.import_tracks:
|
||||||
|
for track in self.tracks:
|
||||||
|
self.app.library.import_track(track)
|
||||||
|
|
||||||
for dock_id in self.views: # enable drag and drop on every view
|
for dock_id in self.views: # enable drag and drop on every view
|
||||||
view = self.views[dock_id]
|
view = self.views[dock_id]
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,10 @@ class Popups:
|
||||||
self.app.library.open_tracks(files)
|
self.app.library.open_tracks(files)
|
||||||
|
|
||||||
def import_tracks(self):
|
def import_tracks(self):
|
||||||
self.open_tracks() # placeholder
|
files = self.select_audio_files()
|
||||||
|
|
||||||
|
if files is not None and not files == []:
|
||||||
|
self.app.library.import_tracks(files)
|
||||||
|
|
||||||
def open_playlist(self):
|
def open_playlist(self):
|
||||||
playlist_path = self.select_playlist_file()
|
playlist_path = self.select_playlist_file()
|
||||||
|
|
Loading…
Add table
Reference in a new issue