Code Monkey home page Code Monkey logo

itunes-navidrome-migration's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

itunes-navidrome-migration's Issues

support for unicode characters

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:
image

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

Exceptions with play_count and last_played cause rating import to fail

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.

Non Music Entries in XML file crash script

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.

[Feature request] Support for "Date Added" and "Favourite" fields

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
image
image

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
image
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:
image

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.