Skip to content

Commit

Permalink
fixed some metadata injection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Davis-Software committed Jun 17, 2024
1 parent b700e6d commit 7a225db
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions .idea/JuicySerato.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion juicy_serato.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


a = Analysis(
['juicy_serato\\__main__.py'],
['juicy_serato/__main__.py'],
pathex=[],
binaries=[],
datas=[],
Expand Down
25 changes: 17 additions & 8 deletions juicy_serato/_juicer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os
import tqdm
import click
import struct
import shutil

from mutagen import MutagenError

from juicy_serato.djuced.djuced_db_parser import DJucedDBParser
from juicy_serato.serato.serato_db_parser import SeratoDBParser
from juicy_serato.serato.serato_structs import CueEntry
Expand All @@ -24,18 +28,23 @@ def inject(self, use_tqdm: bool = True):
continue

markers = list()
skipped_first = False
for i, cue in enumerate(track.cues):
if i == 0 and track.cues[0].cuepos == track.cues[1].cuepos:
skipped_first = True
continue
cues = filter(lambda c: c.cuename.startswith("Cue") and c.cuenumber <= 8, track.cues)
for i, cue in enumerate(cues):
cue_number = cue.cuenumber - 1 if cue.cuenumber - 1 >= 0 else 0
marker = CueEntry(field1=b"\x00", field4=b"\x00", field6=b"\x00\x00",
color=get_serato_color(cue.cueColor), position=int(cue.cuepos*1000),
name=cue.cuename, index=i if not skipped_first else i - 1)
name=cue.cuename, index=cue_number)
markers.append(marker)

with SeratoDBParser(file) as parser:
parser.set_markers(markers)
try:
with SeratoDBParser(file) as parser:
parser.set_markers(markers)
except MutagenError:
click.echo(click.style(f"Failed to read '{track.filename}'", fg="red"))
except ValueError:
click.echo(click.style(f"Failed to save metadata to '{track.filename}'", fg="red"))
except struct.error:
click.echo(click.style(f"Failed to parse '{track.filename}'", fg="red"))

def copy(self, location, use_tqdm: bool = True):
if not os.path.exists(location):
Expand Down
19 changes: 10 additions & 9 deletions juicy_serato/serato/serato_db_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import struct

from mutagen import File
from mutagen.id3 import GEOB, error
from mutagen.id3 import GEOB

from .serato_utils import get_entry_type, read_bytes

Expand Down Expand Up @@ -105,22 +105,23 @@ def get_markers(self):

def set_markers(self, markers: list):
data = self._dump_markers(markers)

frame = GEOB(
encoding=3,
mime="application/octet-stream",
desc="Serato Markers2",
data=data
)

if "GEOB:Serato Markers_" in self.audio.tags:
self.audio.tags.pop("GEOB:Serato Markers_")
if "GEOB:Serato Markers2" in self.audio.tags:
self.audio.tags.pop("GEOB:Serato Markers2")
if hasattr(self.audio, "tags") and self.audio.tags:
if "GEOB:Serato Markers_" in self.audio.tags:
self.audio.tags.pop("GEOB:Serato Markers_")
if "GEOB:Serato Markers2" in self.audio.tags:
self.audio.tags.pop("GEOB:Serato Markers2")

try:
self.audio.tags["GEOB:Serato Markers2"] = frame
except error:
if not hasattr(self.audio, "tags") or not self.audio.tags:
self.audio.add_tags()
self.audio.tags["GEOB:Serato Markers2"] = frame

self.audio.tags["GEOB:Serato Markers2"] = frame

self._changes_made = True
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "juicy_serato"
version = "0.0.1"
version = "0.0.2"
authors = [
{ name="Davis_Software", email="[email protected]" },
]
Expand Down

0 comments on commit 7a225db

Please sign in to comment.