2

I'm trying to make an html page where user can see a list of movies and start watching them. The page is supposed to work locally on one particular machine (file protocol, or http://localhost if needed).

The thing is with "start watching them" part. If I do it straightforward way (<a href="path/to/movie.mkv">watch it</a>) it asks where to save the file.

I'd like it to start vlc or file manager with corresponding directory open.

I was thinking about creating dummy files with some non-standard extensions, associating them with custom MIME type and .desktop file. The .desktop file was supposed to start corresponding movie. But I've got little or no experience with it, and it still have to download it first, doesn't it?

Preferable browsers are chrome or firefox. Target OS is linux.

UPD Judging from this answer what I want seems to be impossible. There's probably a workaround I mentioned above, to make browser download a "shortcut" (containing path to a movie), rather then the whole movie, and associate this custom file type with a .desktop file, which would start corresponding movie. Additionally, make the browser auto-save downloads and auto-open files of this type. But not sure if I'm going this way.

Community
  • 1
  • 1
x-yuri
  • 16,722
  • 15
  • 114
  • 161
  • On Windows there is a VLC integration plugin with some codec packs, so the video starts streaming immediately. You should take a look if there is something like that for Linux. – mrmut Mar 05 '16 at 16:34
  • @mrmut Can you tell me which exactly plugin you're talking about? – x-yuri Mar 05 '16 at 16:40
  • Possible duplicate of [How to launch browser to open local file](http://stackoverflow.com/questions/22535148/how-to-open-local-file-in-browser) and a host of other similar answers found on SO. – Rob Mar 05 '16 at 16:41
  • @Rob Are you sure your link has anything to do with my question? I'm not going to write an android application. – x-yuri Mar 05 '16 at 16:50
  • @x-yuri I clicked on the wrong link but changed it. Even still, you should search SO for your answer first. – Rob Mar 05 '16 at 16:52
  • @x-yuri You can check it here: https://wiki.videolan.org/Documentation:WebPlugin/ – mrmut Mar 05 '16 at 16:57
  • @Rob Please change both links, one in the comment and one in the question. Additionally, [this](http://stackoverflow.com/questions/18246053/how-can-i-create-a-link-to-a-local-file-on-a-locally-run-web-page) seems like a better suggestion. – x-yuri Mar 05 '16 at 17:24

2 Answers2

2

After all, I ended up doing it "custom mime type" way. First, I failed to make chromium play mkv files. Second, I believe that browser is not for watching movies (although you can).

So, I'm gonna use chromium here. Go to Settings. Scroll to the bottom of the page. Click Show advanced settings...:

chromium/Settings/Show advanced settings... link

Scroll until Downloads section:

chromium/Settings/Downloads section

(optional) Uncheck Ask where to save each file before downloading. Create file my-movie.movie-shortcut, containing:

path/to/my/movie.mkv

Create and open a page containing link to this file. (You most likely have to serve the page using a web server, or else chromium will just open the file itself after figuring out it's of text/plain mime type.) Click the link, download the file, and (optional) check Always open files of this type menu item:

chromium/Always open files of this type menu item

Now then, chromium most likely runs xdg-open path/to/file to open files. At least, if you make xdg-open work, it will work in chromium as well.

First, you need to install mimetype. If not installed, xdg-open uses file to determine mime type. And I doubt file can be configured to return custom mime type.

Then add a line to /usr/share/mime/globs:

text/x-movie-shortcut:*.movie-shortcut

Do note, /usr/share/mime/globs is autogenerated, so make sure to do it the proper way if need be.

Then add a line to ~/.config/mimeapps.list to [Default Applications] section:

text/x-movie-shortcut=run-movie.desktop

And create ~/.local/share/applications/run-movie.desktop:

[Desktop Entry]
Version=1.0
Name=Run Movie
GenericName=Run Movie
Comment=Run Movie
Exec=/home/yuri/bin/run-movie.sh
Icon=vlc
Terminal=false
Type=Application
MimeType=text/x-movie-shortcut

And create ~/bin/run-movie.sh (you can probably try to put the command into the .desktop file):

#!/usr/bin/env bash
set -eu
/usr/bin/vlc --started-from-file "$(cat "$1")"

I'm running Arch Linux, so your mileage may vary. Here's supposedly useful link for at least xfce.

x-yuri
  • 16,722
  • 15
  • 114
  • 161
0

You have to embed the video in the web page:

<video width="x" height="y" controls>
  <source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.<!--error message for outdated browsers-->
</video>
  • I used "movie.mp4" because most browsers support mp4. You can use "movie.mkv" as well but some browsers may not support it. Chrome does - I'm unsure about other browsers. –  Mar 05 '16 at 16:48
  • I'd like to avoid that if possible. Having it run in a standalone application makes for a better user experience, I think. – x-yuri Mar 05 '16 at 16:49
  • Then you might have to use the tag instead. . But the user will need to have a player that is able to play the particular video format installed. –  Mar 05 '16 at 16:58