Comments (17)
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.
@michael-lazar I really like this idea, good resolution for #70
from rtv.
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.
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:
.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.- 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. - I haven't found a good way to open imgur albums which represent a significant number of posts.
Any ideas?
from rtv.
@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.
@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.
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.
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.
@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.
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.
Yeah. It will be great with iterm2 images support https://iterm2.com/images.html
from rtv.
@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.
[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.
There's already a de facto standard tool for this. It's called mailcap. Why not use that?
from rtv.
That's a really interesting idea, it's even in the standard library https://docs.python.org/2/library/mailcap.html
from rtv.
It's in! See the new section in the README for a description https://github.com/michael-lazar/rtv#media
from rtv.
That's all well and good, but there seem to still be a few bugs in the implementation. The ones I see are:
- Hitting O while selecting the OP in a comment thread still just opens the browser
- [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,
- Longer videos seem to get cut off after a certain amount of time. This link kills the player 13 minutes in or so. Lastly,
- 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)
- add Twitch mime parser HOT 5
- Crash when hitting G on empty thread HOT 1
- RTV development is shutting down HOT 30
- Offering to help with the project HOT 1
- ConnectionError upon first launch
- no confirmation on exit HOT 1
- Program exited with status 127 HOT 1
- When you set $RTV_BROWSER variable to a program with options like "mybrowser -u" it basicly doesn't work HOT 1
- [1.2.7] Where is the configuration option to toggle whether to open web browser links in a new tab or a new window?
- Not being able to view remote image url via iTerm2's imgcat HOT 6
- How do I change it that rtv uses leafpad instead of nano as its default text editor?
- Save option for posts.
- Option to edit a posted comment.
- Where does rtv store the credentials or session/cookie file so I could just take a rtv install to another OS/new install and donβt have to reopen Firefox for allowing the app access?
- Version 1.27.0_1 (from brew) crashed when opening url HOT 5
- Fix incase mpv is not opening anymore
- When pressing < o > key on a reddit post rtv crashes, "Can't pickle local object" HOT 1
- Crash while trying to sign in HOT 1
- Crash while trying to open a submission link HOT 2
- Archiving Github Repository
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rtv.