Compare commits

..

No commits in common. "bb648488d648658b08a6e7dc225c2bd31879ef46" and "1ea2f7b5312914bec1178b6330304fa6608781c2" have entirely different histories.

8 changed files with 19 additions and 156 deletions

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="musicmuster_dev@localhost" uuid="49514dbe-26ec-4cb2-b457-06666d93ac47">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://localhost:3306/musicmuster_dev</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -1,6 +1,5 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Default" />
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="PROJECT" dialect="MariaDB" />
</component>
</project>

View File

@ -39,8 +39,8 @@ prepend_sys_path = .
# are written from script.py.mako
# output_encoding = utf-8
sqlalchemy.url = mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_dev
# sqlalchemy.url = mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_prod
sqlalchemy.url = mysql+mysqldb://songdb:songdb@localhost/musicmuster
[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run

View File

@ -1,8 +1,6 @@
#!/usr/bin/python3
import os.path
import re
import sqlalchemy
from datetime import datetime
@ -40,54 +38,6 @@ Session = sessionmaker(bind=engine)
# Database classes
class NoteColours(Base):
__tablename__ = 'notecolours'
id = Column(Integer, primary_key=True, autoincrement=True)
substring = Column(String(256), index=False)
hexcolour = Column(String(6), index=False)
enabled = Column(Boolean, default=True, index=True)
is_regex = Column(Boolean, default=False, index=False)
is_casesensitive = Column(Boolean, default=False, index=False)
order = Column(Integer, index=True)
def __repr__(self):
return (
f"<NoteColour(id={self.id}, substring={self.substring}, colour={self.hexcolour}>"
)
@staticmethod
def get_colour(session, text):
"""
Parse text and return colour string if match, else None
Currently ignore is_regex and is_casesensitive
"""
for rec in (
session.query(NoteColours)
.filter(NoteColours.enabled == True)
.order_by(NoteColours.order)
.all()
):
if rec.is_regex:
if rec.is_casesensitive:
p = re.compile(rec.substring)
else:
p = re.compile(rec.substring, re.IGNORECASE)
if p.match(text):
return '#' + rec.hexcolour
else:
if rec.is_casesensitive:
if rec.substring in text:
return '#' + rec.hexcolour
else:
if rec.substring.lower() in text.lower():
return '#' + rec.hexcolour
return None
class Notes(Base):
__tablename__ = 'notes'
@ -165,7 +115,7 @@ class Playdates(Base):
last_played = session.query(Playdates.lastplayed).filter(
(Playdates.track_id == track_id)
).order_by(Playdates.lastplayed.desc()).first()
).order_by(Playdates.lastplayed.desc()).first()
if last_played:
return last_played[0]
else:
@ -271,11 +221,11 @@ class Playlists(Base):
return (
session.query(Playlists)
.filter(
.filter(
(Playlists.loaded == False) | # noqa E712
(Playlists.loaded == None)
)
.order_by(Playlists.last_used.desc())
.order_by(Playlists.last_used.desc())
).all()
@staticmethod
@ -292,8 +242,8 @@ class Playlists(Base):
return (
session.query(Playlists)
.filter(Playlists.loaded == True) # noqa E712
.order_by(Playlists.last_used.desc())
.filter(Playlists.loaded == True) # noqa E712
.order_by(Playlists.last_used.desc())
).all()
def get_notes(self):
@ -303,8 +253,8 @@ class Playlists(Base):
def get_playlist(session, playlist_id):
return (
session.query(Playlists)
.filter(
Playlists.id == playlist_id # noqa E712
.filter(
Playlists.id == playlist_id # noqa E712
)
).one()
@ -367,7 +317,7 @@ class PlaylistTracks(Base):
f"to_playlist_id={to_playlist_id})"
)
max_row = session.query(func.max(PlaylistTracks.row)).filter(
PlaylistTracks.playlist_id == to_playlist_id).scalar()
PlaylistTracks.playlist_id == to_playlist_id).scalar()
if max_row is None:
# Destination playlist is empty; use row 0
new_row = 0
@ -501,7 +451,6 @@ class Tracks(Base):
f"<Track(id={self.id}, title={self.title}, "
f"artist={self.artist}, path={self.path}>"
)
# Not currently used 1 June 2021
# @staticmethod
# def get_note(session, id):
@ -627,16 +576,16 @@ class Tracks(Base):
def search_artists(session, text):
return (
session.query(Tracks)
.filter(Tracks.artist.ilike(f"%{text}%"))
.order_by(Tracks.title)
.filter(Tracks.artist.ilike(f"%{text}%"))
.order_by(Tracks.title)
).all()
@staticmethod
def search_titles(session, text):
return (
session.query(Tracks)
.filter(Tracks.title.ilike(f"%{text}%"))
.order_by(Tracks.title)
.filter(Tracks.title.ilike(f"%{text}%"))
.order_by(Tracks.title)
).all()
@staticmethod

View File

@ -20,7 +20,7 @@ from datetime import datetime, timedelta
from helpers import get_relative_date, open_in_audacity
from log import DEBUG, ERROR
from model import (
Notes, Playdates, Playlists, PlaylistTracks, Session, Settings, Tracks, NoteColours
Notes, Playdates, Playlists, PlaylistTracks, Session, Settings, Tracks
)
from songdb import create_track_from_file, update_meta
@ -1041,10 +1041,11 @@ class PlaylistTab(QTableWidget):
if row_time:
next_start_time = row_time
# Set colour
note_colour = Config.COLOUR_NOTES_PLAYLIST
note_text = self.item(row, self.COL_TITLE).text()
note_colour = NoteColours.get_colour(session, note_text)
if not note_colour:
note_colour = Config.COLOUR_NOTES_PLAYLIST
for colour_token in Config.NOTE_COLOURS.keys():
if note_text.lower().startswith(colour_token.lower()):
note_colour = Config.NOTE_COLOURS[colour_token]
self._set_row_colour(
row, QColor(note_colour)
)

View File

@ -1,36 +0,0 @@
"""Add NoteColours table
Revision ID: a5aada49f2fc
Revises: 2cc37d3cf07f
Create Date: 2022-02-05 17:34:54.880473
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'a5aada49f2fc'
down_revision = '2cc37d3cf07f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('notecolours',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('substring', sa.String(length=256), nullable=True),
sa.Column('hexcolour', sa.String(length=6), nullable=True),
sa.Column('enabled', sa.Boolean(), nullable=True),
sa.Column('is_regex', sa.Boolean(), nullable=True),
sa.Column('is_casesensitive', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('notecolours')
# ### end Alembic commands ###

View File

@ -1,32 +0,0 @@
"""Add order to colours table
Revision ID: c55992d1fe5f
Revises: a5aada49f2fc
Create Date: 2022-02-05 21:28:36.391312
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c55992d1fe5f'
down_revision = 'a5aada49f2fc'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('notecolours', sa.Column('order', sa.Integer(), nullable=True))
op.create_index(op.f('ix_notecolours_enabled'), 'notecolours', ['enabled'], unique=False)
op.create_index(op.f('ix_notecolours_order'), 'notecolours', ['order'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_notecolours_order'), table_name='notecolours')
op.drop_index(op.f('ix_notecolours_enabled'), table_name='notecolours')
op.drop_column('notecolours', 'order')
# ### end Alembic commands ###