Bug 17530 - iTunes Plugin on Linux can fail to find files with Unicode paths
: iTunes Plugin on Linux can fail to find files with Unicode paths
Status: REOPENED
Product: Logitech Media Server
Classification: Unclassified
Component: iTunes
: 7.6.1
: Other Debian Linux
: P1 major with 7 votes (vote)
: 7.6.x
Assigned To: Andy Grundman
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-09-01 18:09 UTC by Klaus Koehnlein
Modified: 2015-11-02 17:05 UTC (History)
4 users (show)

See Also:
Category: ---


Attachments
Fixes problems in scanning iTunes playlist (17.04 KB, text/x-perl-script)
2015-11-02 17:05 UTC, Baskaran
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Klaus Koehnlein 2011-09-01 18:09:12 UTC
When the iTunes Plugin/Scanner tries to locate and map a file containing non-ASCII characters, it translates it into ISO-8859-1 code. Therefore, the file name is not found (file not found error in the scanner log).

Example: Path/File name: Lälö/Lélô/01 Ôlá.mp4

Extract of Scanner Log:
[11-09-02 03:03:32.5479] Slim::Plugin::iTunes::Common::normalize_location (364) Normalized file://localhost/M:/Media/iTunes1/iTunes%20Media/Music/L%C3%A4l%C3%A4/L%C3%A9l%C3%B4/01%20%C3%94l%C3%A1.m4a to file:///share/Media/iTunes1/iTunes%20Media/Music/L%C3%A4l%C3%A4/L%C3%A9l%C3%B4/01%20%C3%94l%C3%A1.m4a

[11-09-02 03:03:32.8597] Slim::Plugin::iTunes::Common::normalize_location (364) Normalized file://localhost/M:/Media/iTunes1/iTunes%20Media/Music/L%C3%A4l%C3%A4/L%C3%A9l%C3%B4/01%20%C3%94l%C3%A1.m4a to file:///M:/Media/iTunes1/iTunes%20Media/Music/L%C3%A4l%C3%A4/L%C3%A9l%C3%B4/01%20%C3%94l%C3%A1.m4a

[11-09-02 03:03:32.8668] Slim::Plugin::iTunes::Importer::handleTrack (319) File not found: /M:/Media/iTunes1/iTunes Media/Music/Lälä/Lélô/01 Ôlá.m4a

This happens on a Sheevaplug running Debian Linux, default locale en_US.utf8. The iTunes library and music folder are on a USB-mounted drive (ext3 format).
Comment 1 Klaus Koehnlein 2011-09-02 03:02:28 UTC
After hours of troubleshooting with 7.6.1, I finaly downgraded to 7.5.6 and iTunes integration works perfectly again, even with non-ASCII and non-ISO characters. So definitely the problems seems to be related to version 7.6.x and the switch to SQLite.

Please fix it, since scanning times under 7.5.6 are very long.
Comment 2 Peter LARSSON 2011-09-06 10:27:52 UTC
*** This bug has been confirmed by popular vote. ***
Comment 3 Michael Herger 2011-09-07 05:20:56 UTC
Could you please give us some information about your server, in particular about its locale configuration?
Comment 4 Klaus Koehnlein 2011-09-08 02:19:10 UTC
My server is a Sheevaplug running Debian from Squeezeplug V3.50 (www.squeezeplug.de).

Default locale is set to en_US.UTF8

SBS info screen reads: Debian-EN-utf8

iTunes library (xml) file and media folder are on external usb hard disk, ext3 formatted, mounted as /share

library file: /share/Media/iTunes1/iTunes Music Library.xml
media folder: /share/Media/iTunes1/iTunes%20Media/
Comment 5 Klaus Koehnlein 2011-09-09 00:58:46 UTC
Just checked my Squeezeplug, Debian and Perl versions:

-> Linux SqueezePlug 2.6.37 #3 PREEMPT Sat Jan 22 22:39:36 MST 2011 armv5tel
-> Debian 6.0.2
-> Perl v5.10.1 built for arm-linux-gnueabi-thread-multi

Hope this helps
Klaus
Comment 6 Patrick Favre 2011-09-09 03:04:49 UTC
Problem occurs on Synology NAS DS210j, firmware 3.2, official Synology SBS package 7.6.1.
Was exactly the same with 7.5.1.
Comment 7 Thomas_S 2011-09-09 14:10:31 UTC
Same Problem: Files with german characters not found while scanning iTunes Library.xml.

Synology Disk Station 710+, Mac with OSX 10.6 an iTunes, Music Library and iTunes Library.xml via AFP on Synology.

Two nights with testing and frustration: Squeezebox 7.5.4 and now Version: 7.6.1 - r33110. 
The Folder Scanner find these Files but the iTunes Scanner has a simple encoding BUG!
Comment 8 Andy Grundman 2011-09-13 14:31:07 UTC
Klaus: I think we're on the wrong track here, with UTF-8 vs. ISO-8859-1, etc. Looking at your initial report, the file that fails has an "M:/Media" path when it should be /share. The log line right before it has the correct /share path, so something is going wrong there.

I was unable to reproduce this, although I tested with an XML file from my Mac. I will do another test with Windows drive letters.
Comment 9 SVN Bot 2011-09-13 14:31:20 UTC
 == Auto-comment from SVN commit #33433 to the slim repo by agrundman ==
 == http://svn.slimdevices.com/slim?view=revision&revision=33433 ==

Bug 17530, log failed iTunes filenames using Data::Dump
Comment 10 Klaus Koehnlein 2011-09-13 14:55:02 UTC
Andy: Thanks for looking into this.

I realised the wrong path substitution "M:/Media". It seems that the scanner falls back to M:/Media since it can't find the file with special characters under the /share path.

There is a comment in the importer.pm program which descibes that rule:

# Bug 3402 
# If the file can't be found using itunes_library_music_path,
# we want to fall back to the real file path from the XML file
Comment 11 Andy Grundman 2011-09-13 14:59:05 UTC
Klaus: Try clearing your setting for "iTunes Media Folder". This value is not needed when running on Linux.
Comment 12 Klaus Koehnlein 2011-09-13 15:02:33 UTC
OK. I'll try that when I'm back home on Friday.
Comment 13 Andy Grundman 2011-09-14 06:59:50 UTC
OK I was wrong, "iTunes Media Folder" is needed because it it used to search/replace the media path in the URLs.

And I was finally able to reproduce this!
Comment 14 SVN Bot 2011-09-14 07:57:02 UTC
 == Auto-comment from SVN commit #33449 to the slim repo by agrundman ==
 == http://svn.slimdevices.com/slim?view=revision&revision=33449 ==

Fixed bug 17530, UTF-8 paths with the Perl UTF8 flag enabled don't work when passed to stat(), so we need to remove the UTF8 flag in pathFromFileURL
Comment 15 Andy Grundman 2011-09-14 07:59:03 UTC
I fixed this in 7.6.2 by the way, so you can test it without possibly running into any 7.7 issues as well.
Comment 16 Klaus Koehnlein 2011-09-16 09:16:41 UTC
Thanks Andy!
7.6.2 works for me. All songs with international characters are found.
Scanning times (approx. 5000 titles) are 4 times faster than with 7.5.6.
Klaus
Comment 17 Thomas_S 2011-10-05 07:54:31 UTC
I have replaced this Misc.pm (from http://svn.slimdevices.com/slim?view=revision&revision=33449) in   the today's Synology Package (7.6.1) but unfortunately it does not help and a 7.6.2 Update from Synology will take months...
Comment 18 Klaus Koehnlein 2011-11-10 12:15:40 UTC
This bug seems to be back in LMS 7.7.1~33681.
I upgraded today and the iTunes Scanner does not find Unicode paths.
Went back to 7.6.2 and everything works fine.
Andy, can you please check it again.
Klaus
Comment 19 M.Klar 2011-11-13 11:22:23 UTC
Same situation here. Was fixed, is broken again at least since LMS 7.7.1 - r33641
Comment 20 Mario St-Laurent 2011-12-10 11:34:48 UTC
This bug appeared once more with the latest version of LMS 7.7.1 -33747-i386-readynas.bin : (
Comment 21 Mario St-Laurent 2011-12-10 11:39:39 UTC
For your information, all my playlist with songs, artist or album who have international character like é,è,à,ù, etc. doesn't appear.

I have a ReadyNas Ultra 2 Plus. It think it was OK before this nightly beta release.
Comment 22 M.Klar 2012-06-05 03:58:15 UTC
Upgraded to 7.7.2. Did a "delete and rescan" right after the upgrade. Tracks with international characters appeared in the library as they should. Hurray!

BUT: I did a reboot of my server (ubuntu) afterwards and now it's broken again. Did a "delete and rescan". And every other options available. Tracks with international characters are missing again.

SO: Itunes importer is broken for non-english users for almost a year!!!!!
Comment 23 yihyan 2012-09-26 19:01:57 UTC
Yup, upgraded to 7.7.2 from 7.7.0, this issue resurfaced. Anyone care to comment about this?
Comment 24 Baskaran 2015-07-16 03:32:38 UTC
This seems to affect my Synology but not my Mac OS X, both scanning the same music folder and the xml file.

I see a failure in Importer.pm file in the following code block:

if (Slim::Music::Info::isFileURL($url)) {
    if ( !$file || !-r $file ) {
        // I followed the execution to here.
        # Use Data::Dump to log exactly what the wrong file path is, avoiding UTF-8 output issues
          require Data::Dump;
          $log->warn("File not found: " . Data::Dump::dump($file));
    }
}

I will spend more time tracking this. Does anyone have any hints or tips for me?

Thanks,

Baskaran
Comment 25 Baskaran 2015-07-16 03:33:33 UTC
BTW, I am running LMS 7.9.

Baskaran

(In reply to comment #24)
> This seems to affect my Synology but not my Mac OS X, both scanning the same
> music folder and the xml file.
> 
> I see a failure in Importer.pm file in the following code block:
> 
> if (Slim::Music::Info::isFileURL($url)) {
>     if ( !$file || !-r $file ) {
>         // I followed the execution to here.
>         # Use Data::Dump to log exactly what the wrong file path is,
> avoiding UTF-8 output issues
>           require Data::Dump;
>           $log->warn("File not found: " . Data::Dump::dump($file));
>     }
> }
> 
> I will spend more time tracking this. Does anyone have any hints or tips for
> me?
> 
> Thanks,
> 
> Baskaran
Comment 26 Baskaran 2015-07-19 01:17:25 UTC
I have identified two possible work-arounds so far:

Work-around 1:

Change code at Import.pm:246 from:

	my $url = $class->normalize_location($location);

to:

	my $url = $class->normalize_location($location, 'fallback');

Before the change I see this logged:

[15-07-18 17:40:18.0859] Slim::Plugin::iTunes::Common::normalize_location (366) Normalized file:///Volumes/music/iTunes/iTunes%20Media/Music/Anu%CC%81na/Anu%CC%81na/01%20Media%20Vita.m4a to file:///volume1/music/iTunes/iTunes%20Media/Musicffile:///volume1/music/iTunes/iTunes%20Media/Musicifile:///volume1/music/iTunes/iTunes%20Media/Musiclfile:///volume1/music/iTunes/iTunes%20Media/Musicefile:///volume1/music/iTunes/iTunes%20Media/Music:file:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/MusicVfile:///volume1/music/iTunes/iTunes%20Media/Musicofile:///volume1/music/iTunes/iTunes%20Media/Musiclfile:///volume1/music/iTunes/iTunes%20Media/Musicufile:///volume1/music/iTunes/iTunes%20Media/Musicmfile:///volume1/music/iTunes/iTunes%20Media/Musicefile:///volume1/music/iTunes/iTunes%20Media/Musicsfile:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/Musicmfile:///volume1/music/iTunes/iTunes%20Media/Musicufile:///volume1/music/iTunes/iTunes%20Media/Musicsfile:///volume1/music/iTunes/iTunes%20Media/Musicifile:///volume1/music/iTunes/iTunes%20Media/Musiccfile:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/Musicifile:///volume1/music/iTunes/iTunes%20Media/MusicTfile:///volume1/music/iTunes/iTunes%20Media/Musicufile:///volume1/music/iTunes/iTunes%20Media/Musicnfile:///volume1/music/iTunes/iTunes%20Media/Musicefile:///volume1/music/iTunes/iTunes%20Media/Musicsfile:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/Musicifile:///volume1/music/iTunes/iTunes%20Media/MusicTfile:///volume1/music/iTunes/iTunes%20Media/Musicufile:///volume1/music/iTunes/iTunes%20Media/Musicnfile:///volume1/music/iTunes/iTunes%20Media/Musicefile:///volume1/music/iTunes/iTunes%20Media/Musicsfile:///volume1/music/iTunes/iTunes%20Media/Music%file:///volume1/music/iTunes/iTunes%20Media/Music2file:///volume1/music/iTunes/iTunes%20Media/Music0file:///volume1/music/iTunes/iTunes%20Media/MusicMfile:///volume1/music/iTunes/iTunes%20Media/Musicefile:///volume1/music/iTunes/iTunes%20Media/Musicdfile:///volume1/music/iTunes/iTunes%20Media/Musicifile:///volume1/music/iTunes/iTunes%20Media/Musicafile:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/MusicMfile:///volume1/music/iTunes/iTunes%20Media/Musicufile:///volume1/music/iTunes/iTunes%20Media/Musicsfile:///volume1/music/iTunes/iTunes%20Media/Musicifile:///volume1/music/iTunes/iTunes%20Media/Musiccfile:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/MusicAfile:///volume1/music/iTunes/iTunes%20Media/Musicnfile:///volume1/music/iTunes/iTunes%20Media/Musicufile:///volume1/music/iTunes/iTunes%20Media/Music%file:///volume1/music/iTunes/iTunes%20Media/MusicCfile:///volume1/music/iTunes/iTunes%20Media/MusicCfile:///volume1/music/iTunes/iTunes%20Media/Music%file:///volume1/music/iTunes/iTunes%20Media/Music8file:///volume1/music/iTunes/iTunes%20Media/Music1file:///volume1/music/iTunes/iTunes%20Media/Musicnfile:///volume1/music/iTunes/iTunes%20Media/Musicafile:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/MusicAfile:///volume1/music/iTunes/iTunes%20Media/Musicnfile:///volume1/music/iTunes/iTunes%20Media/Musicufile:///volume1/music/iTunes/iTunes%20Media/Music%file:///volume1/music/iTunes/iTunes%20Media/MusicCfile:///volume1/music/iTunes/iTunes%20Media/MusicCfile:///volume1/music/iTunes/iTunes%20Media/Music%file:///volume1/music/iTunes/iTunes%20Media/Music8file:///volume1/music/iTunes/iTunes%20Media/Music1file:///volume1/music/iTunes/iTunes%20Media/Musicnfile:///volume1/music/iTunes/iTunes%20Media/Musicafile:///volume1/music/iTunes/iTunes%20Media/Music/file:///volume1/music/iTunes/iTunes%20Media/Music0file:///volume1/music/iTunes/iTunes%20Media/Music1file:///volume1/music/iTunes/iTunes%20Media/Music%file:///volume1/music/iTunes/iTunes%20Media/Music2file:///volume1/music/iTunes/iTunes%20Media/Music0file:///volume1/music/iTunes/iTunes%20Media/MusicMfile:///volume1/music/iTunes/iTunes%20Media/Musicefile:///volume1/music/iTunes/iTunes%20Media/Musicdfile:///volume1/music/iTunes/iTunes%20Media/Musicifile:///volume1/music/iTunes/iTunes%20Media/Musicafile:///volume1/music/iTunes/iTunes%20Media/Music%file:///volume1/music/iTunes/iTunes%20Media/Music2file:///volume1/music/iTunes/iTunes%20Media/Music0file:///volume1/music/iTunes/iTunes%20Media/MusicVfile:///volume1/music/iTunes/iTunes%20Media/Musicifile:///volume1/music/iTunes/iTunes%20Media/Musictfile:///volume1/music/iTunes/iTunes%20Media/Musicafile:///volume1/music/iTunes/iTunes%20Media/Music.file:///volume1/music/iTunes/iTunes%20Media/Musicmfile:///volume1/music/iTunes/iTunes%20Media/Music4file:///volume1/music/iTunes/iTunes%20Media/Musicafile:///volume1/music/iTunes/iTunes%20Media/Music

After the change I see this logged:

[15-07-18 17:46:34.3806] Slim::Plugin::iTunes::Common::normalize_location (366) Normalized file:///Volumes/music/iTunes/iTunes%20Media/Music/Anu%CC%81na/Anu%CC%81na/01%20Media%20Vita.m4a to file:///Volumes/music/iTunes/iTunes%20Media/Music/Anu%CC%81na/Anu%CC%81na/01%20Media%20Vita.m4a

The first log looks very strange!

The following check fails with the strange value for $file:

			if (!-e $file && -e Slim::Utils::Unicode::recomposeUnicode( $file ))
			
In addition the path "/Volumes/music/iTunes/iTunes Media/Music/Anúna/Anúna/01 Media Vita.m4a" needs to be recomposed in order to get a valid file path.

If the above work-around is risky, here is another work-around.

Work-around 2:

Here is the diff:

diff Importer.pm Importer_orig.pm 
274a275,282
> 		# Bug 5339
> 		# iTunes uses decomposed utf-8 (on a MAC), which corresponds to the decomposed UTF-8 file path on an HFS+ volume.
> 		# if the file is moved to a different path on an NFS or SMB file system, the path is automagically
> 		# converted into composed utf-8.
> 		if (!-e $file && -e Slim::Utils::Unicode::recomposeUnicode( $file )) {
> 			$file = Slim::Utils::Unicode::recomposeUnicode( $file );
> 		}
> 
280c288
< 		if (!-e $file && $prefs->get('music_path')) {
---
> 		elsif (!-e $file && $prefs->get('music_path')) {
285,292d292
< 		# Bug 5339
< 		# iTunes uses decomposed utf-8 (on a MAC), which corresponds to the decomposed UTF-8 file path on an HFS+ volume.
< 		# if the file is moved to a different path on an NFS or SMB file system, the path is automagically
< 		# converted into composed utf-8.
< 		if (!-e $file && -e Slim::Utils::Unicode::recomposeUnicode( $file )) {
< 			$file = Slim::Utils::Unicode::recomposeUnicode( $file );
< 		}
< 

With either work-arounds, the value of $file at Import:pm:299 is: /Volumes/music/iTunes/iTunes Media/Music/Anúna/Anúna/01 Media Vita.m4a	

Without one of these work-arounds, the value of $file at Import:pm:299 is: /Volumes/music/iTunes/iTunes Media/Music/Anúna/Anúna/01 Media Vita.m4a, which is invalid.
Comment 27 Baskaran 2015-07-19 18:27:01 UTC
It looks like the current implementation is sensitive to order of key-value pairs in the iTunes Library.xml. It expects to find "Music Folder" key at the beginning. iTunes 12.x updates moved that key to the bottom of the plist.
Comment 28 Baskaran 2015-07-19 20:10:57 UTC
I believe the root-cause of problem with importing iTunes playlists with tracks that contain UTF-8 is the failure to get the "Music Folder" path from "iTunes Library.xml" file before invoking normalize_location() function.

The XML parsing code that retrieves the value of "Music Folder" key is sensitive to where the key is located. With iTunes 12.0 this key has moved to bottom of the file. So the parser code gets to it only after parsing all the playlists and that is too late.

I have experimented with a fix that gets this key before parsing the xml file for playlists. The following diff to Importer.pm takes should work regardless of the order of the keys in the xml file.

diff Importer.pm Importer_orig.pm 
16d15
< use XML::Simple;
118,148d116
< sub getMusicFolder {
< 	my $class = shift;
< 	my $file  = shift || $class->findMusicLibraryFile;
< 	my $type = 'Music Folder';
< 	my $myfolder = undef;
< 
< 	open(XML, $file) or do {
< 		print("Couldn't open [$file]: [$@]");
< 	};
< 
< 	while(<XML>) {
< 		if (/<key>$type/) {
< 			$myfolder = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><dict>" .$_."</dict>";
< 		}
< 	}
< 
< 	close(XML);
< 
< 	if ($myfolder) {
< 		my $parser = XML::Simple->new;
< 		my $data = $parser->XMLin($myfolder);
< 		
< 		undef $myfolder;
< 		$myfolder = ${$data}{'string'};
< 		$class->iTunesLibraryBasePath( $class->strip_automounter($myfolder) );
< 		if ( main::INFOLOG && $log->is_info ) {
< 			$log->info("Found the music folder: ", $class->iTunesLibraryBasePath);
< 		}
< 	}
< }
< 
204,205d171
< 	$class->getMusicFolder;
< 	
353d318
< 		#$file  = Slim::Utils::Misc::pathFromFileURL($url);
570c535
< 		#$class->iTunesLibraryBasePath( $class->strip_automounter($value) );
---
> 		$class->iTunesLibraryBasePath( $class->strip_automounter($value) );
572,574c537,539
< 		#if ( main::INFOLOG && $log->is_info ) {
< 		#	$log->info("Found the music folder: ", $class->iTunesLibraryBasePath);
< 		#}
---
> 		if ( main::INFOLOG && $log->is_info ) {
> 			$log->info("Found the music folder: ", $class->iTunesLibraryBasePath);
> 		}
Comment 29 Baskaran 2015-11-02 17:05:47 UTC
Created attachment 7746 [details]
Fixes problems in scanning iTunes playlist

Please see my last comment in this bug for more details.