Compare commits
7 Commits
89d49f3e34
...
6336eb9215
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6336eb9215 | ||
|
|
ee74deaa49 | ||
|
|
00cae6dc52 | ||
|
|
11e3536801 | ||
|
|
427afee8da | ||
|
|
b4da349a8c | ||
|
|
0836f74d17 |
@ -3,7 +3,13 @@ from datetime import datetime, date
|
|||||||
|
|
||||||
def get_relative_date(past_date, reference_date=None):
|
def get_relative_date(past_date, reference_date=None):
|
||||||
"""
|
"""
|
||||||
Return relative date as string.
|
Return how long before reference_date past_date is as string.
|
||||||
|
|
||||||
|
Params:
|
||||||
|
@past_date: datetime
|
||||||
|
@reference_date: datetime, defaults to current date and time
|
||||||
|
|
||||||
|
@return: string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not past_date:
|
if not past_date:
|
||||||
@ -19,7 +25,15 @@ def get_relative_date(past_date, reference_date=None):
|
|||||||
if weeks == days == 0:
|
if weeks == days == 0:
|
||||||
# Played today, so return time instead
|
# Played today, so return time instead
|
||||||
return past_date.strftime("%H:%M")
|
return past_date.strftime("%H:%M")
|
||||||
return f"{weeks} weeks, {days} days ago"
|
if weeks == 1:
|
||||||
|
weeks_str = "week"
|
||||||
|
else:
|
||||||
|
weeks_str = "weeks"
|
||||||
|
if days == 1:
|
||||||
|
days_str = "day"
|
||||||
|
else:
|
||||||
|
days_str = "days"
|
||||||
|
return f"{weeks} {weeks_str}, {days} {days_str} ago"
|
||||||
|
|
||||||
|
|
||||||
def ms_to_mmss(ms, decimals=0, negative=False):
|
def ms_to_mmss(ms, decimals=0, negative=False):
|
||||||
|
|||||||
18
app/model.py
18
app/model.py
@ -130,24 +130,6 @@ class Playdates(Base):
|
|||||||
).delete()
|
).delete()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def last_show(session, track):
|
|
||||||
"""
|
|
||||||
Return datetime track last played during show time or None
|
|
||||||
|
|
||||||
FIXME: hard coded times in here
|
|
||||||
"""
|
|
||||||
|
|
||||||
# dayofweek: 1 = Sunday, 2 = Monday, ..., 7 = Saturday.
|
|
||||||
friday = 6
|
|
||||||
after = time(20, 0)
|
|
||||||
|
|
||||||
return session.query(Playdates).filter(
|
|
||||||
(Playdates.track_id == track.id),
|
|
||||||
(func.dayofweek(Playdates.lastplayed) == friday),
|
|
||||||
(func.time(Playdates.lastplayed) > after),
|
|
||||||
).order_by(Playdates.lastplayed.desc()).first()
|
|
||||||
|
|
||||||
|
|
||||||
class Playlists(Base):
|
class Playlists(Base):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -226,9 +226,10 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
# Clean up metadata
|
# Clean up metadata
|
||||||
self.previous_track = self.current_track
|
self.previous_track = self.current_track
|
||||||
self.current_track_playlist_tab.play_stopped()
|
if self.current_track_playlist_tab:
|
||||||
self.current_track_playlist_tab.clear_current()
|
self.current_track_playlist_tab.play_stopped()
|
||||||
self.current_track_playlist_tab = None
|
self.current_track_playlist_tab.clear_current()
|
||||||
|
self.current_track_playlist_tab = None
|
||||||
self.current_track = None
|
self.current_track = None
|
||||||
self.playing = False
|
self.playing = False
|
||||||
|
|
||||||
@ -542,6 +543,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
if not self.music.playing():
|
if not self.music.playing():
|
||||||
DEBUG("musicmuster.stop_playing(): not playing", True)
|
DEBUG("musicmuster.stop_playing(): not playing", True)
|
||||||
|
self.end_of_track_actions()
|
||||||
return
|
return
|
||||||
|
|
||||||
self.previous_track_position = self.music.get_position()
|
self.previous_track_position = self.music.get_position()
|
||||||
|
|||||||
@ -168,11 +168,11 @@ def leading_silence(audio_segment, silence_threshold=Config.DBFS_SILENCE,
|
|||||||
return min(trim_ms, len(audio_segment))
|
return min(trim_ms, len(audio_segment))
|
||||||
|
|
||||||
|
|
||||||
def fade_point(audio_segment, fade_threshold=Config.DBFS_FADE,
|
def fade_point(audio_segment, fade_threshold=0,
|
||||||
chunk_size=Config.AUDIO_SEGMENT_CHUNK_SIZE):
|
chunk_size=Config.AUDIO_SEGMENT_CHUNK_SIZE):
|
||||||
"""
|
"""
|
||||||
Returns the millisecond/index of the point where the fade is down to
|
Returns the millisecond/index of the point where the volume drops below
|
||||||
fade_threshold and doesn't get louder again.
|
the maximum and doesn't get louder again.
|
||||||
audio_segment - the sdlg_search_database_uiegment to find silence in
|
audio_segment - the sdlg_search_database_uiegment to find silence in
|
||||||
fade_threshold - the upper bound for how quiet is silent in dFBS
|
fade_threshold - the upper bound for how quiet is silent in dFBS
|
||||||
chunk_size - chunk size for interating over the segment in ms
|
chunk_size - chunk size for interating over the segment in ms
|
||||||
@ -182,6 +182,10 @@ def fade_point(audio_segment, fade_threshold=Config.DBFS_FADE,
|
|||||||
|
|
||||||
segment_length = audio_segment.duration_seconds * 1000 # ms
|
segment_length = audio_segment.duration_seconds * 1000 # ms
|
||||||
trim_ms = segment_length - chunk_size
|
trim_ms = segment_length - chunk_size
|
||||||
|
max_vol = audio_segment.dBFS
|
||||||
|
if fade_threshold == 0:
|
||||||
|
fade_threshold = max_vol
|
||||||
|
|
||||||
while (
|
while (
|
||||||
audio_segment[trim_ms:trim_ms + chunk_size].dBFS < fade_threshold
|
audio_segment[trim_ms:trim_ms + chunk_size].dBFS < fade_threshold
|
||||||
and trim_ms > 0): # noqa W503
|
and trim_ms > 0): # noqa W503
|
||||||
@ -241,7 +245,7 @@ def update_db(session):
|
|||||||
# is filename in database?
|
# is filename in database?
|
||||||
track = Tracks.get_track_from_filename(session, os.path.basename(path))
|
track = Tracks.get_track_from_filename(session, os.path.basename(path))
|
||||||
if not track:
|
if not track:
|
||||||
DEBUG(f"songdb.update_db: Adding to database: {path}")
|
INFO(f"songdb.update_db: Adding to database: {path}")
|
||||||
create_track_from_file(session, path)
|
create_track_from_file(session, path)
|
||||||
else:
|
else:
|
||||||
# Check track info matches found track
|
# Check track info matches found track
|
||||||
@ -257,7 +261,7 @@ def update_db(session):
|
|||||||
for path in list(db_paths - os_paths):
|
for path in list(db_paths - os_paths):
|
||||||
# Manage tracks listed in database but where path is invalid
|
# Manage tracks listed in database but where path is invalid
|
||||||
track = Tracks.get_track_from_path(session, path)
|
track = Tracks.get_track_from_path(session, path)
|
||||||
DEBUG(f"songdb.update_db(): remove from database: {path=} {track=}")
|
INFO(f"songdb.update_db(): remove from database: {path=} {track=}")
|
||||||
|
|
||||||
# Remove references from Playdates
|
# Remove references from Playdates
|
||||||
Playdates.remove_track(session, track.id)
|
Playdates.remove_track(session, track.id)
|
||||||
|
|||||||
42
archive/play.py
Executable file
42
archive/play.py
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from pydub import AudioSegment
|
||||||
|
|
||||||
|
|
||||||
|
def fade_point(audio_segment, fade_threshold=-12, chunk_size=10):
|
||||||
|
"""
|
||||||
|
Returns the millisecond/index of the point where the fade is down to
|
||||||
|
fade_threshold and doesn't get louder again.
|
||||||
|
audio_segment - the sdlg_search_database_uiegment to find silence in
|
||||||
|
fade_threshold - the upper bound for how quiet is silent in dFBS
|
||||||
|
chunk_size - chunk size for interating over the segment in ms
|
||||||
|
"""
|
||||||
|
|
||||||
|
assert chunk_size > 0 # to avoid infinite loop
|
||||||
|
|
||||||
|
segment_length = audio_segment.duration_seconds * 1000 # ms
|
||||||
|
print(f"segment_length={int(segment_length/1000)}")
|
||||||
|
trim_ms = segment_length - chunk_size
|
||||||
|
|
||||||
|
max_vol = audio_segment.dBFS
|
||||||
|
print(f"{max_vol=}")
|
||||||
|
fade_threshold = max_vol
|
||||||
|
while (
|
||||||
|
audio_segment[trim_ms:trim_ms + chunk_size].dBFS < fade_threshold
|
||||||
|
and trim_ms > 0): # noqa W503
|
||||||
|
trim_ms -= chunk_size
|
||||||
|
|
||||||
|
# if there is no trailing silence, return lenght of track (it's less
|
||||||
|
# the chunk_size, but for chunk_size = 10ms, this may be ignored)
|
||||||
|
print(f"Fade last {int(segment_length - trim_ms)/1000} seconds")
|
||||||
|
|
||||||
|
|
||||||
|
print("Shout:")
|
||||||
|
segment = AudioSegment.from_mp3("../archive/shout.mp3")
|
||||||
|
fade_point(segment)
|
||||||
|
print("Champagne:")
|
||||||
|
segment = AudioSegment.from_mp3("../archive/champ.mp3")
|
||||||
|
fade_point(segment)
|
||||||
|
print("Be good:")
|
||||||
|
segment = AudioSegment.from_mp3("../archive/wibg.mp3")
|
||||||
|
fade_point(segment)
|
||||||
Loading…
Reference in New Issue
Block a user