Modify buy list generation to append new missing songs instead of overwriting
This commit is contained in:
1 parent
2dcd4be86d
commit
723e12fe11
1 file changed
+47
-12
@@ -363,18 +363,53 @@ def main():
|
|||||||
|
|
||||||
# Create Amazon buy list for missing songs
|
# Create Amazon buy list for missing songs
|
||||||
if missing:
|
if missing:
|
||||||
print(f"\n{len(missing)} songs not found in your library. Creating Amazon buy list...")
|
print(f"\n{len(missing)} songs not found in your library. Updating Amazon buy list...")
|
||||||
with open('amazon_buy_list.txt', 'w') as f:
|
|
||||||
f.write("Songs not in your library - Amazon search links:\n\n")
|
# Read existing buy list
|
||||||
for song in missing:
|
existing_songs = set()
|
||||||
artist = song['artist']
|
if os.path.exists('amazon_buy_list.txt'):
|
||||||
title = song['title']
|
try:
|
||||||
# Create Amazon search URL
|
with open('amazon_buy_list.txt', 'r') as f:
|
||||||
query = urllib.parse.quote(f"{artist} {title}")
|
content = f.read()
|
||||||
url = f"https://www.amazon.com/s?k={query}&i=digital-music"
|
lines = content.split('\n')
|
||||||
f.write(f"{artist} - {title}\n{url}\n\n")
|
i = 0
|
||||||
print(f" - {artist} - {title}: {url}")
|
while i < len(lines):
|
||||||
print("Buy list saved to amazon_buy_list.txt")
|
if lines[i].startswith('Songs not in your library'):
|
||||||
|
i += 2 # Skip header
|
||||||
|
continue
|
||||||
|
if lines[i].strip() and not lines[i].startswith('http'):
|
||||||
|
if ' - ' in lines[i]:
|
||||||
|
artist, title = lines[i].split(' - ', 1)
|
||||||
|
existing_songs.add((artist.strip(), title.strip()))
|
||||||
|
i += 1
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Warning: Could not read existing buy list: {e}")
|
||||||
|
|
||||||
|
# Filter new missing songs
|
||||||
|
new_missing = []
|
||||||
|
for song in missing:
|
||||||
|
key = (song['artist'], song['title'])
|
||||||
|
if key not in existing_songs:
|
||||||
|
new_missing.append(song)
|
||||||
|
existing_songs.add(key)
|
||||||
|
|
||||||
|
if new_missing:
|
||||||
|
with open('amazon_buy_list.txt', 'a') as f: # Append mode
|
||||||
|
if not os.path.exists('amazon_buy_list.txt') or os.path.getsize('amazon_buy_list.txt') == 0:
|
||||||
|
f.write("Songs not in your library - Amazon search links:\n\n")
|
||||||
|
for song in new_missing:
|
||||||
|
artist = song['artist']
|
||||||
|
title = song['title']
|
||||||
|
# Create Amazon search URL
|
||||||
|
query = urllib.parse.quote(f"{artist} {title}")
|
||||||
|
url = f"https://www.amazon.com/s?k={query}&i=digital-music"
|
||||||
|
f.write(f"{artist} - {title}\n{url}\n\n")
|
||||||
|
print(f" - {artist} - {title}: {url}")
|
||||||
|
print(f"Added {len(new_missing)} new songs to buy list.")
|
||||||
|
else:
|
||||||
|
print("No new songs to add to buy list.")
|
||||||
|
|
||||||
|
print("Buy list updated.")
|
||||||
|
|
||||||
# Log completion
|
# Log completion
|
||||||
end_time = datetime.now()
|
end_time = datetime.now()
|
||||||
|
|||||||
Reference in new issue
Block a user