Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Opening files with MIME type preferences #314

Closed
msglm opened this issue Aug 6, 2020 · 5 comments
Closed

Opening files with MIME type preferences #314

msglm opened this issue Aug 6, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@msglm
Copy link

msglm commented Aug 6, 2020

What do you want

I request a feature that when the attached image button (Default O) is pressed that the file will be opened based on the mimetype (and mac/windows equivalent) preferences of the user. I.e: .pngs, .jpgs, .bpm, etc with feh and .mp4s, .webms., .oggs, etc with mpv or something of the likes. As another feature, there could be another shortcut that copys the link AND opens the media in the preferred application for those who like to save videos/images.

Why

As it stands, cordless only allows images to be displayed with little ease of customization for the end user, meaning video files are completely unplayable without copy and pasting and choice is limited on what the user can open a file. Using mimetypes would a Linux user to open any file they please in the program, .mp4s to mpv, .pngs to feh, .mid to wildmidi, etc. This would elevate the current issue of no embeds and would allow the user to user his or her preferred program.

Implementation hints

As said throughout this, MIMEtypes, and reading pull request #256 shows that you have obviously thought of this before, but only implemented images due to security concerns. Maybe have it as an optional config would allow the user to be given the choice (probably defaulting off for security).

@Bios-Marcel
Copy link
Owner

Bios-Marcel commented Aug 22, 2020

Yo, I was wondering, whether you'd like to find out the mime-type or just use the extension in the file-name, since both would be possible. Clearly using the extension is easier, but using the mime-type might also be a risk, as something looking like a png could and up being a script or such. So I'd say let's go for extensions. I thought about simply using https://github.com/skratchdot/open-golang with optional caching in a non-temporary directory. I'd make it so that all data gets saved in the same folder and you can manually sort it out later if you will. Optionally there will be a config field where you can overwrite the actions for specific mimetypes:

//Won't open
"png": ""
//Always opens in gimp
"png": "gimp $file"

The ImageViewer configuration field will be removed when this is introduced.

@Bios-Marcel
Copy link
Owner

Bios-Marcel commented Aug 22, 2020

Made a little first version: https://github.com/Bios-Marcel/cordless/tree/file_open

Sadly xdg-open, or furthermore that library that i use, doesn't seem to work and doesn't give any error. Either way, feel free to try: https://github.com/Bios-Marcel/cordless/tree/file_open

You gotta check out that branch and compile it yourself.

Additionally I added a default handler, in order to override the default of using the system-file-opener.

A possible configuration looks like this:

    "FileOpenHandlers": {
        "*": "custom-file-handler {$file}",
        "jpg": "feh {$file}",
        "mp4": "vlc -somearg 202 {$file}",
        "png": "feh {$file}"
    },
    "FileOpenSaveFilesPermanently": false,
    "FileOpenSaveFolder": "~/Downloads"

This would also allow for example custom settings for the launch. For example vlc {$file} -L would loop the videos it opens.

Demo:

record

@Bios-Marcel
Copy link
Owner

I am not sure whether it's smarter to go with mimetype or file extension, because I don't know how accurate mimetype recognition is. But a cool thing might be allowing this

"image/*": "feh {$file}"`

@Bios-Marcel
Copy link
Owner

I've pushed the current state to master for now, as I deem it pretty useful already. If you feel like your issue is solved, close it, otherwise tell me what's lacking.

@Bios-Marcel
Copy link
Owner

Actually, before i forget about it, I just close it. Just reopen it or make a new one if needed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants