Fix iPod transfer: create Music/F00 dir and iTunesCDB on first run
- copy_track_to_ipod: create target directory via os.makedirs - sync_itunescdb: create iTunesCDB from scratch if missing - sync_itunescdb: create iTunesCDB.ext with hash if missing
This commit is contained in:
parent
cc429eed31
commit
ab912c2e49
@ -206,6 +206,7 @@ class Nano7Database:
|
|||||||
|
|
||||||
target_dir = self.find_free_music_dir()
|
target_dir = self.find_free_music_dir()
|
||||||
target_path = os.path.join(self.music_base, target_dir, new_name)
|
target_path = os.path.join(self.music_base, target_dir, new_name)
|
||||||
|
os.makedirs(os.path.dirname(target_path), exist_ok=True)
|
||||||
shutil.copy2(filepath, target_path)
|
shutil.copy2(filepath, target_path)
|
||||||
|
|
||||||
relative_path = f"{target_dir}/{new_name}"
|
relative_path = f"{target_dir}/{new_name}"
|
||||||
@ -1102,7 +1103,15 @@ class Nano7Database:
|
|||||||
# Compute new SHA1 hash
|
# Compute new SHA1 hash
|
||||||
new_hash = hashlib.sha1(lib_data).hexdigest()
|
new_hash = hashlib.sha1(lib_data).hexdigest()
|
||||||
|
|
||||||
# Read existing iTunesCDB to extract the header (first 244 bytes)
|
# Read existing iTunesCDB to extract the header (first bytes before zlib)
|
||||||
|
if not os.path.exists(self.cdb_path):
|
||||||
|
header = b"\x00" * 244
|
||||||
|
header = b"mhfd" + struct.pack("<I", 244) + header[8:]
|
||||||
|
compressed = zlib.compress(lib_data)
|
||||||
|
with open(self.cdb_path, "wb") as f:
|
||||||
|
f.write(header + compressed)
|
||||||
|
logger.info(f"Created iTunesCDB: compressed={len(compressed)} bytes")
|
||||||
|
else:
|
||||||
with open(self.cdb_path, "rb") as f:
|
with open(self.cdb_path, "rb") as f:
|
||||||
cdb_data = f.read()
|
cdb_data = f.read()
|
||||||
|
|
||||||
@ -1126,6 +1135,9 @@ class Nano7Database:
|
|||||||
f.write(header + compressed)
|
f.write(header + compressed)
|
||||||
|
|
||||||
# Update hash in iTunesCDB.ext
|
# Update hash in iTunesCDB.ext
|
||||||
|
if not os.path.exists(self.cdb_ext_path):
|
||||||
|
ext_content = f"[iTunesCDB]\nitunesdb_hash={new_hash}\n"
|
||||||
|
else:
|
||||||
with open(self.cdb_ext_path, "r") as f:
|
with open(self.cdb_ext_path, "r") as f:
|
||||||
ext_content = f.read()
|
ext_content = f.read()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user