Compare commits

...

5 Commits

Author SHA1 Message Date
Keith Edmunds
1da0668807 Preserve bitrate when importing track 2022-09-30 18:54:23 +01:00
Keith Edmunds
1ce009ee73 Playlist deals with invalid track_id 2022-09-30 18:53:04 +01:00
Keith Edmunds
5d1078dea0 Debug output to try to track down why titles are changing 2022-09-30 18:26:13 +01:00
Keith Edmunds
e1ceb5e8e3 Update bitrate displayed if db differs from display 2022-09-30 18:25:51 +01:00
Keith Edmunds
912ed0b1eb Use symbols for columns 2022-09-30 18:24:50 +01:00
2 changed files with 40 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import tempfile
from mutagen.flac import FLAC # type: ignore
from mutagen.mp3 import MP3 # type: ignore
from pydub import effects
from pydub.utils import mediainfo
from config import Config
from datetime import datetime
@ -202,6 +203,7 @@ def normalise_track(path):
f"File type {ftype} not implemented"
)
bitrate = mediainfo(path)['bit_rate']
audio = get_audio_segment(path)
if not audio:
return
@ -221,7 +223,8 @@ def normalise_track(path):
# Overwrite original file with normalised output
normalised = effects.normalize(audio)
try:
normalised.export(path, format=os.path.splitext(path)[1][1:])
normalised.export(path, format=os.path.splitext(path)[1][1:],
bitrate=bitrate)
# Fix up permssions and ownership
os.chown(path, stats.st_uid, stats.st_gid)
os.chmod(path, stats.st_mode)

View File

@ -1051,6 +1051,19 @@ class PlaylistTab(QTableWidget):
track = None
if track_id:
track = session.get(Tracks, track_id)
if not track:
# We have a track_id but we can't find the track.
# Update playlist_row accordingly
missing_track = playlist_row.track_id
playlist_row.track_id = None
if note_text:
note_text += f"track_id {missing_track} not found"
else:
note_text = f"track_id {missing_track} not found"
playlist_row.note = note_text
session.commit()
note_item = QTableWidgetItem(note_text)
self.setItem(row, HEADER_NOTES_COLUMN, note_item)
if track:
# Reset colour in case it was current/next/unplayable
@ -1073,6 +1086,10 @@ class PlaylistTab(QTableWidget):
# Highlight low bitrates
if track.bitrate:
bitrate_str = str(track.bitrate)
bitrate_item = self.item(row, BITRATE)
if bitrate_item.text() != bitrate_str:
bitrate_item.setText(bitrate_str)
if track.bitrate < Config.BITRATE_LOW_THRESHOLD:
cell_colour = Config.COLOUR_BITRATE_LOW
elif track.bitrate < Config.BITRATE_OK_THRESHOLD:
@ -1161,6 +1178,11 @@ class PlaylistTab(QTableWidget):
# Does it delimit a section?
if section_start_plr is not None:
if note_text.endswith("-"):
log.debug(
"line 1165: "
f"self._update_note_text({section_start_plr=},"
f"self._get_section_timing_string({section_time=})"
)
self._update_note_text(
section_start_plr,
self._get_section_timing_string(section_time)
@ -1182,12 +1204,16 @@ class PlaylistTab(QTableWidget):
# Have we had a section start but not end?
if section_start_plr is not None:
log.debug(
"line 1191: "
f"self._update_note_text({section_start_plr=},"
f"self._get_section_timing_string({section_time=})"
)
self._update_note_text(
section_start_plr,
self._get_section_timing_string(section_time, no_end=True)
)
#
# # ########## Internally called functions ##########
def _add_track(self, row: int) -> None:
@ -1203,14 +1229,11 @@ class PlaylistTab(QTableWidget):
plr.track_id = track.id
session.commit()
# Update attributes of row
self.item(row, columns["userdata"].idx).setData(
self.ROW_TRACK_ID, track.id)
self.item(row, columns["start_gap"].idx).setText(
str(track.start_gap))
self.item(row, columns["title"].idx).setText(str(track.title))
self.item(row, columns["artist"].idx).setText(str(track.artist))
self.item(row, columns["duration"].idx).setText(
ms_to_mmss(track.duration))
self.item(row, USERDATA).setData(self.ROW_TRACK_ID, track.id)
self.item(row, START_GAP).setText(str(track.start_gap))
self.item(row, TITLE).setText(str(track.title))
self.item(row, ARTIST).setText(str(track.artist))
self.item(row, DURATION).setText(ms_to_mmss(track.duration))
last_playtime = Playdates.last_played(session, track.id)
last_played_str = get_relative_date(last_playtime)
self.item(row, LASTPLAYED).setText(last_played_str)
@ -1392,7 +1415,10 @@ class PlaylistTab(QTableWidget):
def _get_note_text_time(text: str) -> Optional[datetime]:
"""Return time specified as @hh:mm:ss in text"""
try:
match = start_time_re.search(text)
except TypeError:
return None
if not match:
return None