PDA

View Full Version : pathFromFileURL doesn't always work?



Philip Meyer
2008-08-17, 03:12
I'm getting a track url from a Slim::Schema->rs('Track')->search(), and then passing this into Slim::Utils::Misc::pathFromFileURL() to get a local filesystem path.

I'm seeing some warnings in the log such as:

[10:01:37.7146] Slim::Utils::Misc::pathFromFileURL (451) Warning: Path isn't a file URL: M:\Music\Phil's Music\Rips\Coldplay\X&Y\08 - A Message.flac


Also, I'm passing the path into HTTP get requests to MusicIP, which doesn't recognise the file paths if they have accented characters, for example "Schicke Führs & Fröhling" instead of "Schicke Führs & Fröhling".

I'm thinking that there's no real need for me to store files locally with special characters (just keep them in my tags), but I often create file names from the content of tags, so it would be nice to get this working.

Any ideas what I should be doing?


my @notMixableTracks = Slim::Schema->rs('Track')->search({'audio' => '1', 'remote' => '0', 'musicmagic_mixable' => undef});
for my $track (@notMixableTracks) {
my $trackurl = $track->url;

my $path = Slim::Utils::Misc::pathFromFileURL($trackurl);
}

Phil

cparker
2008-08-18, 05:20
Hey so you are having fun with the encoding as well huh :)

I had some success with something like;

my $nextURL = Slim::Player::Playlist::url($client);
$mytitle = Slim::Utils::Unicode::utf8on(Slim::Utils::Misc::pa thFromFileURL($nextURL));

Then something like this;

if ($myos eq 'win' || $myos eq 'mac') {
$mytitle = URI::Escape::uri_escape($mytitle);
} else {
$mytitle = Slim::Utils::Misc::escape($mytitle);
}
$mytitle = Slim::Utils::Unicode::utf8encode_locale($mytitle);

# Then send $mytitle to MusicIP URL request

Though to be honest, I wrote the code and then left it for a few weeks and then came back and couldnt remember where I was.. but hopefully something there may help you :)

I had problems with the receiving data from MIP (with foreign chars) and then trying to convert this to a state that SC would then queue up correctly, so if you crack it, let me know so I can copy your code :)

Best of Luck!
Cheers

Philip Meyer
2008-08-18, 11:59
>Though to be honest, I wrote the code and then left it for a few weeks
>and then came back and couldnt remember where I was.. but hopefully
>something there may help you :)
>
Many thanks - I'll have a play.

It seems quite horrendous to need to call various conversion functions. As this would seem to be necessary for anyone wanting to get a path from a file url, perhaps it should be part of what PathFromFileURL does?

BTW, how did you calculate $myos?

Phil

erland
2008-08-18, 12:15
It seems quite horrendous to need to call various conversion functions. As this would seem to be necessary for anyone wanting to get a path from a file url, perhaps it should be part of what PathFromFileURL does?

From the code it looks like the following if-statement fails:


if ($url !~ /^file:\/\//i) {
logWarning("Path isn't a file URL: $url");
return $url;
}


I wonder if regular expressions like this really doesn't work with non ascii characters or if you are having some encoding issue.

If there is an encoding issue it could be be pretty messy because then the problem probably differs depending on which OS and default encoding you are using, I've had quite a few issues in my plugins related to this. If you decide to use the utf8on or one of the encode/decode functions, make sure you verify this with all possible encodings and operating systems because it can differ.

It feels like we would see a lot of issues in other places if pathFromFileURL didn't work with non ascii characters, so I'm suspecting you have some king of setup specific issue.



BTW, how did you calculate $myos?

I'm guessing:


my $myos = Slim::Utils::OSDetect::OS();

Philip Meyer
2008-08-18, 15:51
I tried applying cparker's suggested fix to encode paths for MusicIP queries and it's working.

>It feels like we would see a lot of issues in other places if
>pathFromFileURL didn't work with non ascii characters, so I'm
>suspecting you have some king of setup specific issue.
>
I'm not noticing the "Path isn't a file URL" warning now from within my changes to the MusicIP scanning phase; it is reported during other scanner phases though (not sure exactly where it is invoked from).

I looked in my database and found that there are several urls for tracks (and some folders too) with without "file://". These are generally items that my wife would play from Browse Music Folder.

SELECT * FROM tracks t where url not like '%://%'

Also where I've added albums as favorites, they appear in the tracks table. eg. I have an entry tracks.url='db:album.titlesearch=IN%20RAINBOWS'.

Is there a reason why pressing play on items from Browse Music Folder would add items into the tracks table without being valid urls? Is that a bug?

> my $myos = Slim::Utils::OSDetect::OS();
Thanks.

Phil

erland
2008-08-18, 21:40
I looked in my database and found that there are several urls for tracks (and some folders too) with without "file://". These are generally items that my wife would play from Browse Music Folder.

SELECT * FROM tracks t where url not like '%://%'

Also where I've added albums as favorites, they appear in the tracks table. eg. I have an entry tracks.url='db:album.titlesearch=IN%20RAINBOWS'.

Favorite urls looks different than tracks url.
I'm not sure why favorite urls like this is added to the database but I suppose there is a reason.



Is there a reason why pressing play on items from Browse Music Folder would add items into the tracks table without being valid urls? Is that a bug?

No idea, someone else will have to answer this.
It feels strange to me too.

cparker
2008-08-20, 15:17
Hi

Interestingly I noticed today that fileURLFromPath doesnt seem to work as expected??

Original paths are run through it like this;
Slim::Utils::Unicode::utf8on(Slim::Utils::Misc::fi leURLFromPath($MYTRACK));

Original Path; C:\Documents and Settings\u\My Documents\My Music\80s dance\Curtis Mayfield - Move On Up.mp3
Returns;
file:///C:/Documents%20and%20Settings/u/My%20Documents/My%20Music/80s%20dance/Curtis%20Mayfield%20-%20Move%20On%20Up.mp3

Original Path;
\\Fatcat\charlie\music-unsorted\MOS-New\Ministry of Sound - Smoking Beats\CD1\(12) [SMOKIN BEATS] Jamiroquai - Blow Your Mind.mp3
Returns;
///charlie/music-unsorted/MOS-New/Ministry%20of%20Sound%20-%20Smoking%20Beats/CD1/(12)%20[SMOKIN%20BEATS]%20Jamiroquai%20-%20Blow%20Your%20Mind.mp3

Seems to chew the front off a path if its UNC

NOTE: UNC paths are held in the database as;
file:////Fatcat/charlie/music-unsorted/MOS-New/Ministry%20of%20Sound%20-%20Smoking%20Beats/CD1/(12)%20[SMOKIN%20BEATS]%20Jamiroquai%20-%20Blow%20Your%20Mind.mp3

So how do you get around this?

cparker
2008-08-21, 02:22
Also noticed that if the path/filename has a foreign character seems to break;

C:\Documents and Settings\u\My Documents\My Music\80s dance\DISCO-DJ WARE-80s-Disco Classics-Urban Dance Mix (80's DJ ED).mp3

[08-08-21 10:13:15.8599] Slim::Control::Request::notify (1942) Error: Failed notify: Can't locate object method "host" via package "URI::_foreign" at /<C:\program Files\squeezeCenter\server\squeezecenter.exe>Slim/Utils/Misc.pm line 510.

Function in the Misc.pm file is;

sub fileURLFromPath {
my $path = shift;

if ($pathToFileCache{$path}) {
return $pathToFileCache{$path};
}

return $path if (Slim::Music::Info::isURL($path));

my $uri = URI::file->new( fixPathCase($path) );
$uri->host(''); #<<<<<<<<<<<<<<<<<<<<**** THIS IS THE BREAK POINT LINE 510

my $file = $uri->as_string;

if (scalar keys %pathToFileCache > 32) {
%pathToFileCache = ();
}

$pathToFileCache{$path} = $file;

return $file;
}


Any ideas how to get around this, surely there is a fix for this?? Is it a bug??

mherger
2008-08-21, 02:42
> Any ideas how to get around this, surely there is a fix for this?? Is
> it a bug??

This character set / path stuff is a minefield. We're much better now, but the infinite number of configurations is hard to manage. What exact constellation are you using (what's running SC, where are the files, what character sets are used on these machines etc.?

It's best you look at some of our code which does already what you're trying to do.

--

Michael

cparker
2008-08-21, 03:02
>
This character set / path stuff is a minefield. We're much better now, but the infinite number of configurations is hard to manage. What exact constellation are you using (what's running SC, where are the files, what character sets are used on these machines etc.?
Michael

Hi Michael

Its XP running English UK so Latin1 I would guess. The files are split across a local drive and a NAS box.

So for local example;
C:\Documents and Settings\u\My Documents\My Music\80s dance\Fine Young Cannibals\The Raw & the Cooked\10 Ever Fallen in Love-.mp3

For the NAS box;
\\fatcat\media\My Music\80s90s\Jefferson Starship - We Built This City.mp3

So is pretty vanilla, I'm not running anything strange. (I havent even dared go near Unix/Linux yet!)


>
It's best you look at some of our code which does already what you're trying to do.

Yeah I would love to do this, but I havent found any so far that I can borrow most plugins are "internet grab and display" and dont really touch file stuff.

As the database holds the file URLs with file:// my NAS example would not be found in a db search, unless I fudge it and add file:// but then I also noticed this breaks if there are foreign chars in the filenames.

Would be great if you have any examples as I cant imagine I'm doing anything that isnt already done somewhere :s Currently searching around at the moment...

Cheers