Compare commits
4 Commits
de710b1dc7
...
2861511f1f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2861511f1f | ||
|
|
a8aa157484 | ||
|
|
71f3e4cda8 | ||
|
|
9467ae4ee5 |
@ -217,4 +217,5 @@ class TrackSequence:
|
||||
now = PlaylistTrack()
|
||||
previous = PlaylistTrack()
|
||||
|
||||
|
||||
track_sequence = TrackSequence()
|
||||
|
||||
@ -44,12 +44,12 @@ class Config(object):
|
||||
COLUMN_NAME_TITLE = "Title"
|
||||
DBFS_SILENCE = -50
|
||||
DEBUG_FUNCTIONS: List[Optional[str]] = []
|
||||
DEBUG_MODULES: List[Optional[str]] = ['dbconfig']
|
||||
DEBUG_MODULES: List[Optional[str]] = ["dbconfig"]
|
||||
DEFAULT_COLUMN_WIDTH = 200
|
||||
DISPLAY_SQL = False
|
||||
EPOCH = datetime.datetime(1970, 1, 1)
|
||||
ERRORS_FROM = ['noreply@midnighthax.com']
|
||||
ERRORS_TO = ['kae@midnighthax.com']
|
||||
ERRORS_FROM = ["noreply@midnighthax.com"]
|
||||
ERRORS_TO = ["kae@midnighthax.com"]
|
||||
FADE_CURVE_BACKGROUND = "lightyellow"
|
||||
FADE_CURVE_FOREGROUND = "blue"
|
||||
FADE_CURVE_MS_BEFORE_FADE = 5000
|
||||
@ -71,11 +71,11 @@ class Config(object):
|
||||
LOG_LEVEL_STDERR = logging.ERROR
|
||||
LOG_LEVEL_SYSLOG = logging.DEBUG
|
||||
LOG_NAME = "musicmuster"
|
||||
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
|
||||
MAIL_PORT = int(os.environ.get('MAIL_PORT') or 25)
|
||||
MAIL_SERVER = os.environ.get('MAIL_SERVER') or "woodlands.midnighthax.com"
|
||||
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
|
||||
MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None
|
||||
MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD")
|
||||
MAIL_PORT = int(os.environ.get("MAIL_PORT") or 25)
|
||||
MAIL_SERVER = os.environ.get("MAIL_SERVER") or "woodlands.midnighthax.com"
|
||||
MAIL_USERNAME = os.environ.get("MAIL_USERNAME")
|
||||
MAIL_USE_TLS = os.environ.get("MAIL_USE_TLS") is not None
|
||||
MAX_IMPORT_MATCHES = 5
|
||||
MAX_INFO_TABS = 5
|
||||
MAX_MISSING_FILES_TO_REPORT = 10
|
||||
@ -86,7 +86,7 @@ class Config(object):
|
||||
OBS_PASSWORD = "auster"
|
||||
OBS_PORT = 4455
|
||||
PLAY_SETTLE = 500000
|
||||
ROOT = os.environ.get('ROOT') or "/home/kae/music"
|
||||
ROOT = os.environ.get("ROOT") or "/home/kae/music"
|
||||
ROWS_FROM_ZERO = True
|
||||
IMPORT_DESTINATION = os.path.join(ROOT, "Singles")
|
||||
SCROLL_TOP_MARGIN = 3
|
||||
|
||||
@ -431,23 +431,6 @@ class PlaylistRows(Base):
|
||||
track_id=plr.track_id,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def delete_higher_rows(
|
||||
session: scoped_session, playlist_id: int, maxrow: int
|
||||
) -> None:
|
||||
"""
|
||||
Delete rows in given playlist that have a higher row number
|
||||
than 'maxrow'
|
||||
"""
|
||||
|
||||
session.execute(
|
||||
delete(PlaylistRows).where(
|
||||
PlaylistRows.playlist_id == playlist_id,
|
||||
PlaylistRows.plr_rownum > maxrow,
|
||||
)
|
||||
)
|
||||
session.flush()
|
||||
|
||||
@classmethod
|
||||
def deep_row(
|
||||
cls, session: scoped_session, playlist_id: int, row_number: int
|
||||
@ -488,6 +471,38 @@ class PlaylistRows(Base):
|
||||
|
||||
return session.scalars(stmt).unique().all()
|
||||
|
||||
@staticmethod
|
||||
def delete_higher_rows(
|
||||
session: scoped_session, playlist_id: int, maxrow: int
|
||||
) -> None:
|
||||
"""
|
||||
Delete rows in given playlist that have a higher row number
|
||||
than 'maxrow'
|
||||
"""
|
||||
|
||||
session.execute(
|
||||
delete(PlaylistRows).where(
|
||||
PlaylistRows.playlist_id == playlist_id,
|
||||
PlaylistRows.plr_rownum > maxrow,
|
||||
)
|
||||
)
|
||||
session.flush()
|
||||
|
||||
@staticmethod
|
||||
def delete_rows(
|
||||
session: scoped_session, playlist_id: int, row_numbers: List[int]
|
||||
) -> None:
|
||||
"""
|
||||
Delete passed rows in given playlist.
|
||||
"""
|
||||
|
||||
session.execute(
|
||||
delete(PlaylistRows).where(
|
||||
PlaylistRows.playlist_id == playlist_id,
|
||||
PlaylistRows.plr_rownum.in_(row_numbers),
|
||||
)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def fixup_rownumbers(session: scoped_session, playlist_id: int) -> None:
|
||||
"""
|
||||
|
||||
@ -740,10 +740,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
times a second; this function has much better resolution.
|
||||
"""
|
||||
|
||||
if (
|
||||
track_sequence.now.track_id is None
|
||||
or track_sequence.now.start_time is None
|
||||
):
|
||||
if track_sequence.now.track_id is None or track_sequence.now.start_time is None:
|
||||
return 0
|
||||
|
||||
now = datetime.now()
|
||||
@ -900,8 +897,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
plrs_to_move = [
|
||||
plr
|
||||
for plr in playlistrows
|
||||
if plr.id
|
||||
not in [track_sequence.now.plr_id, track_sequence.next.plr_id]
|
||||
if plr.id not in [track_sequence.now.plr_id, track_sequence.next.plr_id]
|
||||
]
|
||||
|
||||
rows_to_delete = [
|
||||
|
||||
@ -347,8 +347,11 @@ class PlaylistModel(QAbstractTableModel):
|
||||
Delete passed rows from model
|
||||
"""
|
||||
|
||||
# TODO
|
||||
print(f"Delete rows {row_numbers=}")
|
||||
with Session() as session:
|
||||
PlaylistRows.delete_rows(session, self.playlist_id, row_numbers)
|
||||
PlaylistRows.fixup_rownumbers(session, self.playlist_id)
|
||||
self.refresh_data(session)
|
||||
self.update_track_times()
|
||||
|
||||
def display_role(self, row: int, column: int, prd: PlaylistRowData) -> QVariant:
|
||||
"""
|
||||
@ -445,6 +448,17 @@ class PlaylistModel(QAbstractTableModel):
|
||||
|
||||
return QVariant(boldfont)
|
||||
|
||||
def get_rows_duration(self, row_numbers: List[int]) -> int:
|
||||
"""
|
||||
Return the total duration of the passed rows
|
||||
"""
|
||||
|
||||
duration = 0
|
||||
for row_number in row_numbers:
|
||||
duration += self.playlist_rows[row_number].duration
|
||||
|
||||
return duration
|
||||
|
||||
def headerData(
|
||||
self,
|
||||
section: int,
|
||||
@ -712,7 +726,9 @@ class PlaylistModel(QAbstractTableModel):
|
||||
|
||||
# Check to see whether any rows in track_sequence have moved
|
||||
if track_sequence.previous.plr_rownum in row_map:
|
||||
track_sequence.previous.plr_rownum = row_map[track_sequence.previous.plr_rownum]
|
||||
track_sequence.previous.plr_rownum = row_map[
|
||||
track_sequence.previous.plr_rownum
|
||||
]
|
||||
if track_sequence.now.plr_rownum in row_map:
|
||||
track_sequence.now.plr_rownum = row_map[track_sequence.now.plr_rownum]
|
||||
if track_sequence.next.plr_rownum in row_map:
|
||||
@ -923,7 +939,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
Sort selected rows by artist
|
||||
"""
|
||||
|
||||
self.sort_by_attribute(row_numbers, 'artist')
|
||||
self.sort_by_attribute(row_numbers, "artist")
|
||||
|
||||
def sort_by_attribute(self, row_numbers: List[int], attr_name: str) -> None:
|
||||
"""
|
||||
@ -935,8 +951,8 @@ class PlaylistModel(QAbstractTableModel):
|
||||
# interested in
|
||||
shortlist_rows = {k: self.playlist_rows[k] for k in row_numbers}
|
||||
sorted_list = [
|
||||
plr.plr_rownum for plr in
|
||||
sorted(shortlist_rows.values(), key=attrgetter(attr_name))
|
||||
plr.plr_rownum
|
||||
for plr in sorted(shortlist_rows.values(), key=attrgetter(attr_name))
|
||||
]
|
||||
self.move_rows(sorted_list, min(sorted_list))
|
||||
|
||||
@ -945,21 +961,21 @@ class PlaylistModel(QAbstractTableModel):
|
||||
Sort selected rows by duration
|
||||
"""
|
||||
|
||||
self.sort_by_attribute(row_numbers, 'duration')
|
||||
self.sort_by_attribute(row_numbers, "duration")
|
||||
|
||||
def sort_by_lastplayed(self, row_numbers: List[int]) -> None:
|
||||
"""
|
||||
Sort selected rows by lastplayed
|
||||
"""
|
||||
|
||||
self.sort_by_attribute(row_numbers, 'lastplayed')
|
||||
self.sort_by_attribute(row_numbers, "lastplayed")
|
||||
|
||||
def sort_by_title(self, row_numbers: List[int]) -> None:
|
||||
"""
|
||||
Sort selected rows by title
|
||||
"""
|
||||
|
||||
self.sort_by_attribute(row_numbers, 'title')
|
||||
self.sort_by_attribute(row_numbers, "title")
|
||||
|
||||
def supportedDropActions(self) -> Qt.DropAction:
|
||||
return Qt.DropAction.MoveAction | Qt.DropAction.CopyAction
|
||||
@ -985,7 +1001,10 @@ class PlaylistModel(QAbstractTableModel):
|
||||
continue
|
||||
|
||||
# Set start time for next row if we have a current track
|
||||
if row_number == track_sequence.next.plr_rownum and track_sequence.now.end_time:
|
||||
if (
|
||||
row_number == track_sequence.next.plr_rownum
|
||||
and track_sequence.now.end_time
|
||||
):
|
||||
stend.start_time = track_sequence.now.end_time
|
||||
stend.end_time = stend.start_time + timedelta(milliseconds=prd.duration)
|
||||
next_start_time = stend.end_time
|
||||
|
||||
1915
app/playlists.py
1915
app/playlists.py
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,6 @@ test_tracks = [
|
||||
|
||||
|
||||
def create_model_with_tracks(session: scoped_session) -> "playlistmodel.PlaylistModel":
|
||||
|
||||
playlist = Playlists(session, "test playlist")
|
||||
model = playlistmodel.PlaylistModel(playlist.id)
|
||||
|
||||
@ -228,14 +227,12 @@ def test_insert_header_row_middle(monkeypatch, session):
|
||||
|
||||
|
||||
def test_create_model_with_tracks(monkeypatch, session):
|
||||
|
||||
monkeypatch.setattr(playlistmodel, "Session", session)
|
||||
model = create_model_with_tracks(session)
|
||||
assert len(model.playlist_rows) == len(test_tracks)
|
||||
|
||||
|
||||
def test_timing_one_track(monkeypatch, session):
|
||||
|
||||
START_ROW = 0
|
||||
END_ROW = 2
|
||||
|
||||
@ -267,4 +264,3 @@ def test_timing_one_track(monkeypatch, session):
|
||||
# model.edit_role(model.rowCount(), playlistmodel.Col.NOTE.value, prd)
|
||||
# == note_text
|
||||
# )
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user