stampede / itunes-navidrome-migration Goto Github PK
View Code? Open in Web Editor NEWPython scripts to transfer iTunes history to a new Navidrome installation
License: The Unlicense
Python scripts to transfer iTunes history to a new Navidrome installation
License: The Unlicense
I'm trying to migrate my iTunes library error and I've noticed this error:
(env) C:\Users\sterl\Desktop\itunes-navidrome-migration-master>itunestoND.py
This script will migrate certain data from your ITunes library to your Navidrome database.
Back up all your data in case it doesn't work properly on your setup. NO WARRANTIES. NO PROMISES.
The script will DELETE existing data you have in your Navidrome database so it can start "fresh".
Type PROCEED to continue, or Q to quit: PROCEED
Enter the path to the Navidrome database: C:\Users\sterl\Desktop\itunes-navidrome-migration-master\navidrome.db
Enter the path to the Itunes database: C:\Users\sterl\Desktop\itunes-navidrome-migration-master\Library.xml
Parsing Itunes library. This may take a while.
Traceback (most recent call last):
File "C:\Users\sterl\Desktop\itunes-navidrome-migration-master\itunestoND.py", line 82, in <module>
with open(itdb_path, 'r') as f: soup = BeautifulSoup(f, 'lxml-xml')
File "C:\Users\sterl\Desktop\itunes-navidrome-migration-master\env\lib\site-packages\bs4\__init__.py", line 312, in __init__
markup = markup.read()
File "C:\Users\sterl\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 129421: character maps to <undefined>
Which seems like the issue can be fixed by adding the encoding="utf8"
flag to the open statement that opens the Library.xml file on line 82, in my case, I have a lot of songs in my library using unicode characters (typically Japanese ones) in a lot of fields, after parsing the Library.xml with the utf8 encoding, the results in the navidrome.db aren't as expected:
the play count for all of the songs are still 0, and the date added field are all the the same, not the ones indicated in the iTunes library
my guess is that there's some mismatch with the unicode characters in the Library.xml and the navidrome.db but I'm not too sure
these two fields are the most important to me so any help here would be great
Hi, I noticed that the ratings for a large number of my tracks were not being imported into the Navidrome database. I eventually tracked it down to the following code:
try:
play_count = int(it_song_entry.find('key', string='Play Count').next_sibling.text)
last_played = it_song_entry.find('key', string='Play Date UTC').next_sibling.text[:-1] # slice off the trailing 'Z'
last_played = datetime.datetime.strptime(last_played, '%Y-%m-%dT%H:%M:%S') # convert from string to datetime object. Example string: '20>
except AttributeError: continue
When I replaced except AttributeError: continue
with the following all of my ratings were successfully imported:
except AttributeError:
play_count = 0
last_played = datetime.datetime.strptime("1900-01-01 00:00:00",'%Y-%m-%d %H:%M:%S')
I think the lack of a play count or last play date in the iTunes XML triggers the exception which then causes update_playstats to fail because it does not have all of the variables populated for these actions:
update_playstats(artists, artist_id, play_count, last_played)
update_playstats(albums, album_id, play_count, last_played)
update_playstats(files, song_id, play_count, last_played, rating=song_rating)
I'm happy with 1900-01-01 00:00:00 as a default last_played date but this might suit everyone. I don't know how one would insert a null date.
Once again, thank you for these scripts.
Hi thank you for writing these scripts. I'm always on the look out for scripts that allow me to migrate my iTunes library to other applications.
The iTunes Library file can contain information about purchased and cloud items as well as local audio files. I think this is causing itunestoND.py to crash with the following error:
File "itunestoND.py", line 114, in <module>
song_path = unquote(it_song_entry.find('key', string='Location').next_sibling.text)
AttributeError: 'NoneType' object has no attribute 'next_sibling'
For example Movies use the key: <key>Movie</key><true/>
and do not have a Location key.
Some items such as Podcasts use an iTunes URL such as:
<key>Location</key><string>https://itunesu-assets.itunes.apple.com/itunes-assets/CobaltPublic7/v4/REMOVEDLONGSTRING</string>
I'm wondering if the script should only process XML entries where the location is a file:// URL.
Regards.
Hello, would it be possible to add support for the date added and "loved" fields to carry over to navidrome?
From what I've experienced, as of right now, the "date added" is not overwritten by the date added field migrated from iTunes, and it would be nice to have the "loved" field from iTunes show up as a favourite in navidrome
From a look at itunestoND.py
and the output of each it_song_entry
I can see that the key "Loved" exists if only if it's true
So I believe it would be simple to check each it_song_entry
for the field like loved = it_song_entry.find('key', string='Loved')
and a simple check if(loved != None)
Also the date added field seems to be formatted in the exact same way as the last added field:
I'm just unfamiliar about how to implement this with the existing way you update playstatistics, so some advice or assistance would be appreciated.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.