GithubHelp home page GithubHelp logo

Comments (17)

michael-lazar avatar michael-lazar commented on May 28, 2024

This is a cool idea, I could see defining a new section in the config file. Something like...

[browsers]
*.gif="mpv %u"
youtube="mpv ytdl://%u"
imgur="curl %u | feh -"

This would also be a good way to tie in @McHearty's idea #70 of using w3m.

from rtv.

McHearty avatar McHearty commented on May 28, 2024

@michael-lazar I really like this idea, good resolution for #70

from rtv.

obosob avatar obosob commented on May 28, 2024

There is a pretty simple workaround for this.

BROWSER=urlscript rtv

and in urlscript:

#!/bin/bash
case $1 in
    http*://*youtube.com/watch?*|http*://youtu.be/watch?*)
         mpv "ytdl://$1"
    ;;
    *.gif|*.gifv)
         mpv "$1"
    ;;
    *.jpg*|*.png*)
        feh -. "$1"
    ;;
esac

from rtv.

michael-lazar avatar michael-lazar commented on May 28, 2024

This is very nice! I've been slowly working on building this into the python source using a config file. It's mostly finished, but I have a few roadblocks with imgur:

  1. .gifv is a custom imgur extension that's not recognized by any command-line applications. This one's not so bad because you can replace the .gifv with .webm and the link will still open.
  2. Half of the imgur links look like this http://imgur.com/pCmsLnV and don't link directly to the image. I've been trying to guess at file extensions but I need a way to get the actual file type.
  3. I haven't found a good way to open imgur albums which represent a significant number of posts.

Any ideas?

from rtv.

professorjamesmoriarty avatar professorjamesmoriarty commented on May 28, 2024

@michael-lazar Not sure how it would work with links, but there is https://github.com/ahupp/python-magic which can find out the file type. MIGHT be of some use to reference at least. There is also https://docs.python.org/2/library/imghdr.html which does images. But not sure how this would relate to links... unless it's cached somehow.

Just tossing ideas, punch me later lol.

from rtv.

obosob avatar obosob commented on May 28, 2024

@michael-lazar just had a quick poke around the source, and there is an element in the as follows:

<link rel="image_src" href="http://i.imgur.com/pCmsLnV.jpg"/>

Which is a link to the image itself, albums aside for now.

so you could do a quick hack in the script:

http://imgur.com/*)
    # call this script recursively with whatever the image itself is
    $0  $(curl -s http://imgur.com/pCmsLnV | sed -n 's/^.*<link rel="image_src"\s\+href="\([^"]\+\)".*$/\1/p')
;;

from rtv.

obosob avatar obosob commented on May 28, 2024

personally, i think I'd leave galleries alone and just have a case before that that matches "imgur.com/gallery/" and opens it in a browser.

from rtv.

obosob avatar obosob commented on May 28, 2024

Here's the script i am using, it's got other stuff in it (like mailto) because I use it as a handler for other stuff too. works nicely set as $BROWSER with rtv.

#!/bin/bash

ARGS=$(getopt -o n -- "$@")
PRE=""
q=""
url=""
eval set -- "$ARGS"

while true; do
    case $1 in
        -n)
            # print command that would be run
            PRE="echo "
            # keep this behaviour if we call ourselves recursively (print the final command that will be run)
            q=" -n"
            shift
        ;;
        --)
            shift
            break
        ;;
    esac
done
# let xdg do url scheme handling where appropriate, this script handles special cases (youtube, imgur, etc.)

DEFAULT="${PRE}xdg-open"
VIDEO="mpv"
IMAGE="feh -."
GIF="mpv --loop=inf"

url=$1
case $url in
    http*://*youtube.com/watch?*|http*://youtu.be/watch?*)
        ${PRE}${VIDEO} "$url"
        ;;
    *.jpg*|*.png*)
        ${PRE}${IMAGE} "$url"
        ;;
    *.gif*)
        ${PRE}${GIF} "${url/.gifv/.webm}"
        ;;
    *imgur.com/a/*|*imgur.com/gallery/*)
        ${DEFAULT} "$url"
        ;;
    *imgur.com/*)
        $0$q $(curl -s "$url" | sed -n 's/^.*<link rel="image_src"\s\+href="\([^"]\+\)".*$/\1/p')
        ;;
    mailto:*)
        ${PRE}urxvt -e mutt -- "${url}"
        ;;
    *)
        ${DEFAULT} "$url"
        ;;
esac

from rtv.

michael-lazar avatar michael-lazar commented on May 28, 2024

@obosob that's awesome and way above my head haha. I'll post the config that I've been working on tonight, maybe you can take a look at it.

@shaggytwodope I had no idea about imghdr (I swear the python std library has the most random things in it). Will keep it in my back pocket, although I agree an immediate use doesn't pop out to me either.

from rtv.

kazuoteramoto avatar kazuoteramoto commented on May 28, 2024

I'm using something like @obosob but using the mimeo replacement for xdg-open as $BROWSER, you can associate a regexp match to a program. You still need helpers for thinks like imgur.

from rtv.

onemanstartup avatar onemanstartup commented on May 28, 2024

Yeah. It will be great with iterm2 images support https://iterm2.com/images.html

from rtv.

Brobin avatar Brobin commented on May 28, 2024

@michael-lazar I might be a little late to the party, but imgur ignores all file extensions. For example, your link http://imgur.com/pCmsLnV doesn't have a file extension. With any links like this you prepend i and add any file extension. http://i.imgur.com/pCmsLnV.png, http://i.imgur.com/pCmsLnV.jpg, and http://i.imgur.com/pCmsLnV.gif all work for the same image.

from rtv.

gislifreyr avatar gislifreyr commented on May 28, 2024

[EDITED]For OS X users wanting very similar (nearly identical) behaviour to @obosob's script can use the following script. feh is not available on OS X but the quicklook acts as a substitute.
Got rid of the recursive call and had to change the sed-command so it works on the sed that comes with OS X.

#!/usr/bin/env bash

url=$1

default="open"
videos="mpv --autofit="100%""
gifs="mpv --loop=inf"

function img_handle {
    cd ~/tmp
    name=${url##*/}
    curl -s -O "$url"
    qlmanage -p ~/tmp/$name &>/dev/null
    rm ~/tmp/$name
}

case $url in
    http*://*youtube.com/watch?*|http*://youtu.be/*)
        ${videos} "$url"
        ;;
    *.gif*|http*://streamable.com/*)
        ${gifs} "${url/.gifv/.webm}"
        ;;
    *.jpg*|*.png*)
        img_handle
        ;;
    *imgur.com/a/*|*imgur.com/gallery/*)
        ${default} "$url"
        ;;
    *imgur.com/*)
        url=$(curl -s "$url" | sed -nE 's/^.*<link rel="image_src"[[:space:]]+href="([^"]+)".*$/\1/p')
        img_handle
        ;;
    *)
        ${default} "$url"
        ;;
esac

from rtv.

 avatar commented on May 28, 2024

There's already a de facto standard tool for this. It's called mailcap. Why not use that?

from rtv.

michael-lazar avatar michael-lazar commented on May 28, 2024

That's a really interesting idea, it's even in the standard library https://docs.python.org/2/library/mailcap.html

from rtv.

michael-lazar avatar michael-lazar commented on May 28, 2024

It's in! See the new section in the README for a description https://github.com/michael-lazar/rtv#media

from rtv.

Jaegrqualm avatar Jaegrqualm commented on May 28, 2024

That's all well and good, but there seem to still be a few bugs in the implementation. The ones I see are:

  1. Hitting O while selecting the OP in a comment thread still just opens the browser
  2. [This may be upstream] Opening videos from imgur (with mpv at least) seem to load strangely. Firstly the video loads multiple times, first without a title in the player, then with. Also,
  3. Longer videos seem to get cut off after a certain amount of time. This link kills the player 13 minutes in or so. Lastly,
  4. Again with mpv, and again I don't know whose fault it is, but you can't skip around in videos, either by clicking on the scrubber or using skip keys.

I realize that this may well qualify for a separate issue, but it seemed relevant enough to this topic to at least post it here first.

from rtv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.