Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 10 of 10
  1. #1
    Senior Member Philip Meyer's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    5,596

    pathFromFileURL doesn't always work?

    I'm getting a track url from a Slim::Schema->rs('Track')->search(), and then passing this into Slim::Utils::Misc:athFromFileURL() to get a local filesystem path.

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

    [10:01:37.7146] Slim::Utils::Misc:athFromFileURL (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:athFromFileURL($trackurl);
    }

    Phil

  2. #2
    Senior Member cparker's Avatar
    Join Date
    Oct 2005
    Location
    Hampshire, United Kingdom
    Posts
    613

    Disclaimer; This may be complete rubbish :s

    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:athFromFileURL($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
    www.spicefly.com - ** Spicefly SugarCube ** - A hassle free acoustic journey through your music library using MusicIP. Plus the finest MusicIP installation guides, enhanced MIP Interface and SpyGlass MIP the Windows Automated MusicIP Headless Installer.

  3. #3
    Senior Member Philip Meyer's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    5,596

    pathFromFileURL doesn't always work?

    >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

  4. #4
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,058
    Quote Originally Posted by Philip Meyer View Post
    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:
    Code:
    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.

    Quote Originally Posted by Philip Meyer View Post
    BTW, how did you calculate $myos?
    I'm guessing:
    Code:
    my $myos = Slim::Utils::OSDetect::OS();
    Erland Isaksson (My homepage)
    Developer of many plugins/applets

  5. #5
    Senior Member Philip Meyer's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    5,596

    pathFromFileURL doesn't always work?

    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

  6. #6
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,058
    Quote Originally Posted by Philip Meyer View Post
    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.

    Quote Originally Posted by Philip Meyer View Post
    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.
    Erland Isaksson (My homepage)
    Developer of many plugins/applets

  7. #7
    Senior Member cparker's Avatar
    Join Date
    Oct 2005
    Location
    Hampshire, United Kingdom
    Posts
    613

    fileURLFromPath broken?

    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?
    www.spicefly.com - ** Spicefly SugarCube ** - A hassle free acoustic journey through your music library using MusicIP. Plus the finest MusicIP installation guides, enhanced MIP Interface and SpyGlass MIP the Windows Automated MusicIP Headless Installer.

  8. #8
    Senior Member cparker's Avatar
    Join Date
    Oct 2005
    Location
    Hampshire, United Kingdom
    Posts
    613

    Slim::Utils::Unicode::utf8on(Slim::Utils::Misc::fi leURLFromPath($MYTRACK));

    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??
    www.spicefly.com - ** Spicefly SugarCube ** - A hassle free acoustic journey through your music library using MusicIP. Plus the finest MusicIP installation guides, enhanced MIP Interface and SpyGlass MIP the Windows Automated MusicIP Headless Installer.

  9. #9
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,451

    pathFromFileURL doesn't always work?

    > 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

  10. #10
    Senior Member cparker's Avatar
    Join Date
    Oct 2005
    Location
    Hampshire, United Kingdom
    Posts
    613
    Quote Originally Posted by mherger View Post
    >
    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!)

    Quote Originally Posted by mherger View Post
    >
    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
    Last edited by cparker; 2008-08-21 at 03:03. Reason: Typo
    www.spicefly.com - ** Spicefly SugarCube ** - A hassle free acoustic journey through your music library using MusicIP. Plus the finest MusicIP installation guides, enhanced MIP Interface and SpyGlass MIP the Windows Automated MusicIP Headless Installer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •