Black reformatting, tidying
This commit is contained in:
parent
734d5cb545
commit
813b325029
@ -155,23 +155,21 @@ def get_file_metadata(filepath: str) -> dict:
|
|||||||
# Get title, artist, bitrate, duration, path
|
# Get title, artist, bitrate, duration, path
|
||||||
metadata: Dict[str, str | int | float] = get_tags(filepath)
|
metadata: Dict[str, str | int | float] = get_tags(filepath)
|
||||||
|
|
||||||
metadata['mtime'] = os.path.getmtime(filepath)
|
metadata["mtime"] = os.path.getmtime(filepath)
|
||||||
|
|
||||||
# Set start_gap, fade_at and silence_at
|
# Set start_gap, fade_at and silence_at
|
||||||
audio = get_audio_segment(filepath)
|
audio = get_audio_segment(filepath)
|
||||||
if not audio:
|
if not audio:
|
||||||
audio_values = dict(
|
audio_values = dict(start_gap=0, fade_at=0, silence_at=0)
|
||||||
start_gap=0,
|
|
||||||
fade_at=0,
|
|
||||||
silence_at=0
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
audio_values = dict(
|
audio_values = dict(
|
||||||
start_gap=leading_silence(audio),
|
start_gap=leading_silence(audio),
|
||||||
fade_at=int(round(fade_point(audio) / 1000, Config.MILLISECOND_SIGFIGS) * 1000),
|
fade_at=int(
|
||||||
|
round(fade_point(audio) / 1000, Config.MILLISECOND_SIGFIGS) * 1000
|
||||||
|
),
|
||||||
silence_at=int(
|
silence_at=int(
|
||||||
round(trailing_silence(audio) / 1000, Config.MILLISECOND_SIGFIGS) * 1000
|
round(trailing_silence(audio) / 1000, Config.MILLISECOND_SIGFIGS) * 1000
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
metadata |= audio_values
|
metadata |= audio_values
|
||||||
|
|
||||||
|
|||||||
@ -134,14 +134,11 @@ class NoteColours(Base):
|
|||||||
if not text:
|
if not text:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for rec in (
|
for rec in session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(NoteColours)
|
select(NoteColours)
|
||||||
.filter(NoteColours.enabled.is_(True))
|
.filter(NoteColours.enabled.is_(True))
|
||||||
.order_by(NoteColours.order)
|
.order_by(NoteColours.order)
|
||||||
)
|
).all():
|
||||||
.all()
|
|
||||||
):
|
|
||||||
if rec.is_regex:
|
if rec.is_regex:
|
||||||
flags = re.UNICODE
|
flags = re.UNICODE
|
||||||
if not rec.is_casesensitive:
|
if not rec.is_casesensitive:
|
||||||
@ -202,14 +199,11 @@ class Playdates(Base):
|
|||||||
def played_after(session: scoped_session, since: datetime) -> Sequence["Playdates"]:
|
def played_after(session: scoped_session, since: datetime) -> Sequence["Playdates"]:
|
||||||
"""Return a list of Playdates objects since passed time"""
|
"""Return a list of Playdates objects since passed time"""
|
||||||
|
|
||||||
return (
|
return session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(Playdates)
|
select(Playdates)
|
||||||
.where(Playdates.lastplayed >= since)
|
.where(Playdates.lastplayed >= since)
|
||||||
.order_by(Playdates.lastplayed)
|
.order_by(Playdates.lastplayed)
|
||||||
)
|
).all()
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Playlists(Base):
|
class Playlists(Base):
|
||||||
@ -285,32 +279,25 @@ class Playlists(Base):
|
|||||||
def get_all(cls, session: scoped_session) -> Sequence["Playlists"]:
|
def get_all(cls, session: scoped_session) -> Sequence["Playlists"]:
|
||||||
"""Returns a list of all playlists ordered by last use"""
|
"""Returns a list of all playlists ordered by last use"""
|
||||||
|
|
||||||
return (
|
return session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(cls)
|
select(cls)
|
||||||
.filter(cls.is_template.is_(False))
|
.filter(cls.is_template.is_(False))
|
||||||
.order_by(cls.tab.desc(), cls.last_used.desc())
|
.order_by(cls.tab.desc(), cls.last_used.desc())
|
||||||
)
|
).all()
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all_templates(cls, session: scoped_session) -> Sequence["Playlists"]:
|
def get_all_templates(cls, session: scoped_session) -> Sequence["Playlists"]:
|
||||||
"""Returns a list of all templates ordered by name"""
|
"""Returns a list of all templates ordered by name"""
|
||||||
|
|
||||||
return (
|
return session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(cls).filter(cls.is_template.is_(True)).order_by(cls.name)
|
select(cls).filter(cls.is_template.is_(True)).order_by(cls.name)
|
||||||
)
|
).all()
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_closed(cls, session: scoped_session) -> Sequence["Playlists"]:
|
def get_closed(cls, session: scoped_session) -> Sequence["Playlists"]:
|
||||||
"""Returns a list of all closed playlists ordered by last use"""
|
"""Returns a list of all closed playlists ordered by last use"""
|
||||||
|
|
||||||
return (
|
return session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(cls)
|
select(cls)
|
||||||
.filter(
|
.filter(
|
||||||
cls.tab.is_(None),
|
cls.tab.is_(None),
|
||||||
@ -318,9 +305,7 @@ class Playlists(Base):
|
|||||||
cls.deleted.is_(False),
|
cls.deleted.is_(False),
|
||||||
)
|
)
|
||||||
.order_by(cls.last_used.desc())
|
.order_by(cls.last_used.desc())
|
||||||
)
|
).all()
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_open(cls, session: scoped_session) -> Sequence[Optional["Playlists"]]:
|
def get_open(cls, session: scoped_session) -> Sequence[Optional["Playlists"]]:
|
||||||
@ -328,10 +313,9 @@ class Playlists(Base):
|
|||||||
Return a list of loaded playlists ordered by tab order.
|
Return a list of loaded playlists ordered by tab order.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return (
|
return session.scalars(
|
||||||
session.scalars(select(cls).where(cls.tab.is_not(None)).order_by(cls.tab))
|
select(cls).where(cls.tab.is_not(None)).order_by(cls.tab)
|
||||||
.all()
|
).all()
|
||||||
)
|
|
||||||
|
|
||||||
def mark_open(self, session: scoped_session, tab_index: int) -> None:
|
def mark_open(self, session: scoped_session, tab_index: int) -> None:
|
||||||
"""Mark playlist as loaded and used now"""
|
"""Mark playlist as loaded and used now"""
|
||||||
@ -433,12 +417,9 @@ class PlaylistRows(Base):
|
|||||||
def copy_playlist(session: scoped_session, src_id: int, dst_id: int) -> None:
|
def copy_playlist(session: scoped_session, src_id: int, dst_id: int) -> None:
|
||||||
"""Copy playlist entries"""
|
"""Copy playlist entries"""
|
||||||
|
|
||||||
src_rows = (
|
src_rows = session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(PlaylistRows).filter(PlaylistRows.playlist_id == src_id)
|
select(PlaylistRows).filter(PlaylistRows.playlist_id == src_id)
|
||||||
)
|
).all()
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
for plr in src_rows:
|
for plr in src_rows:
|
||||||
PlaylistRows(
|
PlaylistRows(
|
||||||
@ -512,14 +493,11 @@ class PlaylistRows(Base):
|
|||||||
Ensure the row numbers for passed playlist have no gaps
|
Ensure the row numbers for passed playlist have no gaps
|
||||||
"""
|
"""
|
||||||
|
|
||||||
plrs = (
|
plrs = session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(PlaylistRows)
|
select(PlaylistRows)
|
||||||
.where(PlaylistRows.playlist_id == playlist_id)
|
.where(PlaylistRows.playlist_id == playlist_id)
|
||||||
.order_by(PlaylistRows.plr_rownum)
|
.order_by(PlaylistRows.plr_rownum)
|
||||||
)
|
).all()
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
for i, plr in enumerate(plrs):
|
for i, plr in enumerate(plrs):
|
||||||
plr.plr_rownum = i
|
plr.plr_rownum = i
|
||||||
@ -536,14 +514,11 @@ class PlaylistRows(Base):
|
|||||||
PlaylistRows objects
|
PlaylistRows objects
|
||||||
"""
|
"""
|
||||||
|
|
||||||
plrs = (
|
plrs = session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(cls)
|
select(cls)
|
||||||
.where(cls.playlist_id == playlist_id, cls.id.in_(plr_ids))
|
.where(cls.playlist_id == playlist_id, cls.id.in_(plr_ids))
|
||||||
.order_by(cls.plr_rownum)
|
.order_by(cls.plr_rownum)
|
||||||
)
|
).all()
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
return plrs
|
return plrs
|
||||||
|
|
||||||
@ -581,14 +556,11 @@ class PlaylistRows(Base):
|
|||||||
have been played.
|
have been played.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
plrs = (
|
plrs = session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(cls)
|
select(cls)
|
||||||
.where(cls.playlist_id == playlist_id, cls.played.is_(True))
|
.where(cls.playlist_id == playlist_id, cls.played.is_(True))
|
||||||
.order_by(cls.plr_rownum)
|
.order_by(cls.plr_rownum)
|
||||||
)
|
).all()
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
return plrs
|
return plrs
|
||||||
|
|
||||||
@ -626,8 +598,7 @@ class PlaylistRows(Base):
|
|||||||
have not been played.
|
have not been played.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
plrs = (
|
plrs = session.scalars(
|
||||||
session.scalars(
|
|
||||||
select(cls)
|
select(cls)
|
||||||
.where(
|
.where(
|
||||||
cls.playlist_id == playlist_id,
|
cls.playlist_id == playlist_id,
|
||||||
@ -635,12 +606,17 @@ class PlaylistRows(Base):
|
|||||||
cls.played.is_(False),
|
cls.played.is_(False),
|
||||||
)
|
)
|
||||||
.order_by(cls.plr_rownum)
|
.order_by(cls.plr_rownum)
|
||||||
)
|
).all()
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
return plrs
|
return plrs
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def insert_row(
|
||||||
|
cls, session: scoped_session, playlist_id: int, new_row_number: int
|
||||||
|
) -> "PlaylistRows":
|
||||||
|
cls.move_rows_down(session, playlist_id, new_row_number, 1)
|
||||||
|
return cls(session, playlist_id, new_row_number)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def move_rows_down(
|
def move_rows_down(
|
||||||
session: scoped_session, playlist_id: int, starting_row: int, move_by: int
|
session: scoped_session, playlist_id: int, starting_row: int, move_by: int
|
||||||
|
|||||||
@ -3,15 +3,12 @@ from enum import auto, Enum
|
|||||||
from sqlalchemy import bindparam, update
|
from sqlalchemy import bindparam, update
|
||||||
from typing import List, Optional, TYPE_CHECKING
|
from typing import List, Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from dbconfig import scoped_session, Session
|
|
||||||
|
|
||||||
from PyQt6.QtCore import (
|
from PyQt6.QtCore import (
|
||||||
QAbstractTableModel,
|
QAbstractTableModel,
|
||||||
QModelIndex,
|
QModelIndex,
|
||||||
Qt,
|
Qt,
|
||||||
QVariant,
|
QVariant,
|
||||||
)
|
)
|
||||||
|
|
||||||
from PyQt6.QtGui import (
|
from PyQt6.QtGui import (
|
||||||
QBrush,
|
QBrush,
|
||||||
QColor,
|
QColor,
|
||||||
@ -42,9 +39,6 @@ class Col(Enum):
|
|||||||
NOTE = auto()
|
NOTE = auto()
|
||||||
|
|
||||||
|
|
||||||
HEADER_NOTES_COLUMN = 1
|
|
||||||
|
|
||||||
|
|
||||||
class PlaylistRowData:
|
class PlaylistRowData:
|
||||||
def __init__(self, plr: PlaylistRows) -> None:
|
def __init__(self, plr: PlaylistRows) -> None:
|
||||||
"""
|
"""
|
||||||
@ -120,7 +114,11 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def add_track(
|
def add_track(
|
||||||
self, playlist_id: int, track: Optional[Tracks], note: Optional[str]
|
self,
|
||||||
|
playlist_id: int,
|
||||||
|
new_row_number: int,
|
||||||
|
track_id: Optional[int],
|
||||||
|
note: Optional[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Add track if it's for our playlist
|
Add track if it's for our playlist
|
||||||
@ -130,14 +128,12 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
if playlist_id != self.playlist_id:
|
if playlist_id != self.playlist_id:
|
||||||
return
|
return
|
||||||
|
|
||||||
row_number = self.playlist.get_selected_row_number()
|
|
||||||
|
|
||||||
# Insert track if we have one
|
# Insert track if we have one
|
||||||
if track:
|
if track_id:
|
||||||
self.insert_track_row(row_number, track, note)
|
self.insert_track_row(new_row_number, track_id, note)
|
||||||
# If we only have a note, add as a header row
|
# If we only have a note, add as a header row
|
||||||
elif note:
|
elif note:
|
||||||
self.insert_header_row(row_number, note)
|
self.insert_header_row(new_row_number, note)
|
||||||
else:
|
else:
|
||||||
# No track, no note, no point
|
# No track, no note, no point
|
||||||
return
|
return
|
||||||
@ -364,16 +360,8 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
else:
|
else:
|
||||||
new_row_number = row_number
|
new_row_number = row_number
|
||||||
|
|
||||||
# Move rows below new row down
|
|
||||||
stmt = (
|
|
||||||
update(PlaylistRows)
|
|
||||||
.where(PlaylistRows.plr_rownum >= new_row_number)
|
|
||||||
.values({PlaylistRows.plr_rownum: PlaylistRows.plr_rownum + 1})
|
|
||||||
)
|
|
||||||
session.execute(stmt)
|
|
||||||
|
|
||||||
# Insert the new row and return it
|
# Insert the new row and return it
|
||||||
return PlaylistRows(session, self.playlist_id, new_row_number)
|
return PlaylistRows.insert_row(session, self.playlist_id, new_row_number)
|
||||||
|
|
||||||
def insert_track_row(
|
def insert_track_row(
|
||||||
self, row_number: Optional[int], track_id: int, text: Optional[str]
|
self, row_number: Optional[int], track_id: int, text: Optional[str]
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import threading
|
|||||||
|
|
||||||
import obsws_python as obs # type: ignore
|
import obsws_python as obs # type: ignore
|
||||||
|
|
||||||
# from collections import namedtuple
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, cast, List, Optional, Tuple, TYPE_CHECKING
|
from typing import Any, cast, List, Optional, Tuple, TYPE_CHECKING
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user