Kodi Community Forum

Full Version: Files.PrepareDownload -> Use path -> 401 Unauthorized
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi.

I want to download/stream a file with a direct url. I'm using the "Files.PrepareDownload" function to this.
I can get the file path correctly with this function, but when I use the resulting path in a browser, I always get 401 Unauthorized as a response and can't download the file.

is there something basic I'm missing? Couldn't find any info about this.

Thanks in advance!
Please provide more details about your request and the URL you try to use. Is the file part of one of your sources defined in XBMC/Kodi?
(2014-10-01, 16:50)Montellese Wrote: [ -> ]Please provide more details about your request and the URL you try to use. Is the file part of one of your sources defined in XBMC/Kodi?

Thank you for your response.
First I send an HTTP post to http://192.168.1.90:8080/jsonrpc with the body

Code:
{"jsonrpc": "2.0", "method": "Files.PrepareDownload", "params": { "path": "/media/Toshiba/filmes/Angry Video Game Nerd- The Movie-HD.mp4" }, "id": 1}

and I get this response:

Code:
{"id":1,"jsonrpc":"2.0","result":{"details":{"path":"vfs/%2fmedia%2fToshiba%2ffilmes%2fAngry%20Video%20Game%20Nerd-%20The%20Movie-HD.mp4"},"mode":"redirect","protocol":"http"}}

The I access
Code:
http://192.168.1.90:8080/vfs/%2fmedia%2fToshiba%2ffilmes%2fAngry%20Video%20Game%20Nerd-%20The%20Movie-HD.mp4
in Chrome on my windows PC and I always get the aforementioned error.

The file is inside my movies folder which was added to the XMBC library and is available to play throught the "Movies" section in XBMC.

Thanks again!
You are using an RPI and are facing a "bug" that I reported many times but was never addressed Sad

On rpi the /media is automatically scrapped without being added as a source, so you have the media in your library but no way to access them from outside.

The easy solution is just to add a source to /media with no scraper just to allow access.

I really hope one day someone could fix it Smile
(2014-10-02, 09:27)Tolriq Wrote: [ -> ]You are using an RPI and are facing a "bug" that I reported many times but was never addressed Sad

On rpi the /media is automatically scrapped without being added as a source, so you have the media in your library but no way to access them from outside.

The easy solution is just to add a source to /media with no scraper just to allow access.

I really hope one day someone could fix it Smile

Thank you!! That was exactly it! Smile I had a feeling it would have to be something simple. Thank you very much for you help!
(2014-10-02, 09:27)Tolriq Wrote: [ -> ]You are using an RPI and are facing a "bug" that I reported many times but was never addressed Sad

On rpi the /media is automatically scrapped without being added as a source, so you have the media in your library but no way to access them from outside.

The easy solution is just to add a source to /media with no scraper just to allow access.

I really hope one day someone could fix it Smile

Could you post a link to where you reported it so others can report the same error? It's still there at the time of this posting and it's a real problem for those wanting to further customize their install.
Another option on the Raspberry Pi would be to use a symlink to the USB drive.
I use an external hard drive to store all of my movie files and leave the /home/osmc/Movies directory empty.

So here's my example:
My external hard drive is located at /media/EXTERNAL_BOOK/. So I use the following code to make the symlink:

Code:
ln -s /media/EXTERNAL_BOOK /home/osmc/Movies/EXTERNAL_BOOK

This allows me to continue using a scraper for new content AND allows for downloading the file(s) with a corrected URL. Here's an example of how to correct the URL while using the Files.PrepareDownload() method.

my path to the video file is
Code:
/media/EXTERNAL_BOOK/The_Movie-HD.mp4

The return would convert that to
Code:
"path":"vfs/%2fmedia%2fEXTERNAL_BOOK%2fThe_Movie-HD.mp4"

To correct it, I simply replace the "media" part as follows:
Code:
vfs/%2fhome%2fosmc%2fMovies%2fEXTERNAL_BOOK%2fThe_Movie-HD.mp4

So the request URL would look something like this:
Code:
http://192.168.0.14:8080/vfs/%2fhome%2fosmc%2fMovies%2fEXTERNAL_BOOK%2fThe_Movie-HD.mp4

This works perfect for me and I hope that helps someone else until they actually fix this glitch or someone provides a better solution.