Compare commits
No commits in common. "6336eb921511706e6980a0507a0c937cf6351ab0" and "89d49f3e34b8ac77c93340930fa5d2f0ef008140" have entirely different histories.
6336eb9215
...
89d49f3e34
@ -3,13 +3,7 @@ from datetime import datetime, date
|
||||
|
||||
def get_relative_date(past_date, reference_date=None):
|
||||
"""
|
||||
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
|
||||
Return relative date as string.
|
||||
"""
|
||||
|
||||
if not past_date:
|
||||
@ -25,15 +19,7 @@ def get_relative_date(past_date, reference_date=None):
|
||||
if weeks == days == 0:
|
||||
# Played today, so return time instead
|
||||
return past_date.strftime("%H:%M")
|
||||
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"
|
||||
return f"{weeks} weeks, {days} days ago"
|
||||
|
||||
|
||||
def ms_to_mmss(ms, decimals=0, negative=False):
|
||||
|
||||
18
app/model.py
18
app/model.py
@ -130,6 +130,24 @@ class Playdates(Base):
|
||||
).delete()
|
||||
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):
|
||||
"""
|
||||
|
||||
@ -226,7 +226,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
# Clean up metadata
|
||||
self.previous_track = self.current_track
|
||||
if self.current_track_playlist_tab:
|
||||
self.current_track_playlist_tab.play_stopped()
|
||||
self.current_track_playlist_tab.clear_current()
|
||||
self.current_track_playlist_tab = None
|
||||
@ -543,7 +542,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
if not self.music.playing():
|
||||
DEBUG("musicmuster.stop_playing(): not playing", True)
|
||||
self.end_of_track_actions()
|
||||
return
|
||||
|
||||
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))
|
||||
|
||||
|
||||
def fade_point(audio_segment, fade_threshold=0,
|
||||
def fade_point(audio_segment, fade_threshold=Config.DBFS_FADE,
|
||||
chunk_size=Config.AUDIO_SEGMENT_CHUNK_SIZE):
|
||||
"""
|
||||
Returns the millisecond/index of the point where the volume drops below
|
||||
the maximum and doesn't get louder again.
|
||||
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
|
||||
@ -182,10 +182,6 @@ def fade_point(audio_segment, fade_threshold=0,
|
||||
|
||||
segment_length = audio_segment.duration_seconds * 1000 # ms
|
||||
trim_ms = segment_length - chunk_size
|
||||
max_vol = audio_segment.dBFS
|
||||
if fade_threshold == 0:
|
||||
fade_threshold = max_vol
|
||||
|
||||
while (
|
||||
audio_segment[trim_ms:trim_ms + chunk_size].dBFS < fade_threshold
|
||||
and trim_ms > 0): # noqa W503
|
||||
@ -245,7 +241,7 @@ def update_db(session):
|
||||
# is filename in database?
|
||||
track = Tracks.get_track_from_filename(session, os.path.basename(path))
|
||||
if not track:
|
||||
INFO(f"songdb.update_db: Adding to database: {path}")
|
||||
DEBUG(f"songdb.update_db: Adding to database: {path}")
|
||||
create_track_from_file(session, path)
|
||||
else:
|
||||
# Check track info matches found track
|
||||
@ -261,7 +257,7 @@ def update_db(session):
|
||||
for path in list(db_paths - os_paths):
|
||||
# Manage tracks listed in database but where path is invalid
|
||||
track = Tracks.get_track_from_path(session, path)
|
||||
INFO(f"songdb.update_db(): remove from database: {path=} {track=}")
|
||||
DEBUG(f"songdb.update_db(): remove from database: {path=} {track=}")
|
||||
|
||||
# Remove references from Playdates
|
||||
Playdates.remove_track(session, track.id)
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
#!/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