View previous topic :: View next topic |
Author |
Message |
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3310 Location: Rasi, Finland
|
Posted: Mon Sep 08, 2008 11:56 pm Post subject: Konqueror service menu: YouTube download |
|
|
To download videos easily from YouTube via Konqueror you need... Well... Konqueror (of course), kdialog and youtube-dl.
I assume you already have Konqueror and kdialog so the next step is to get youtube-dl: Code: | emerge -v youtube-dl | and you should have it.
Now create a file (bash script). I will call it as ka_ytdl.sh. Edit it and paste following text into it: Code: | #!/bin/bash
# for mplayer
CACHESIZE="512"
# start directory
STARTDIR="$HOME/Desktop"
DIALOGCMD="$KDEDIR/bin/kdialog --title \"YouTube download\""
case $1 in
HQ)
if ! VIDEOURL=`youtube-dl -bg $2`
then
$DIALOGCMD --error "Error while getting video URL.\nYou could try low quality instead..."
exit 1
fi
VIDEXT="mp4"
;;
LQ)
if ! VIDEOURL=`youtube-dl -g $2`
then
$DIALOGCMD --error "Error while getting video URL."
exit 1
fi
VIDEXT="flv"
;;
mplayer)
mplayer -cache 512 `youtube-dl -g $2` && exit 0 || $DIALOGCMD --error "Mplayer exited with non-zero status"
exit 1
;;
*)
exit 1
;;
esac
# Next line get's kinda dirty. Fix if you know a better and working way
DEST="$(/bin/bash -c "$DIALOGCMD --getsaveurl \"$STARTDIR\" \"*.$VIDEXT\"")"
$KDEDIR/bin/kfmclient copy "$VIDEOURL" "$DEST" |
Then you need to create a text file to ~/.kde/share/apps/konqueror/servicemenus -directory. Name it what ever you like but have '.desktop' extension for it. I named it ytdl.desktop.
Then paste following code into it... Code: | [Desktop Entry]
ServiceTypes=all/all
Actions=YTDLHQ;YTDLLQ;Live
X-KDE-Submenu=YouTube download...
[Desktop Action YTDLHQ]
Name=high quality
Exec=<path to>/ka_ytdl.sh HQ %u
[Desktop Action YTDLLQ]
Name=low quality
Exec=<path to>/ka_ytdl.sh LQ %u
[Desktop Action Live]
Name=play in Mplayer
Exec=<path to>/ka_ytdl.sh mplayer %u | ... and replace <path to> with the path where you saved ka_ytdl.sh.
Then you should be ready.
Just right-click a video link in youtube page and choose Actions --> Download YouTube-video --> <make your choice>
NOTE following:
- I'm not sure if every video on YouTube is in flv-format of in mp4-format. Flv for low-quality and mp4 for high-quality.
- it can download links of format: http://*.youtube.com/watch?v=* (should produce an error when trying to download invalid URL)
- this is still in very early "version", so it may contain bugs (I have eliminated some bugs now... But post reply if you encounter any. :) )
TODO:
- Check that URL is appropriate (need to read more docs if this menu could only appear on YouTube-video link)
- Start from previous location on save dialog instead from $HOME/Desktop but still reminding user to save it as *.mp4 (filter)
- Add viewing videos *done* _________________ ..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3310 Location: Rasi, Finland
|
Posted: Tue Sep 09, 2008 3:54 pm Post subject: Update |
|
|
An update:
I changed the structure of this whole trick. It now needs a seperate script to work and has ability to download both HQ and LQ videos. Also viewing with mplayer is included.
It is now much more careful with video urls. It checks (with youtube-dl exit status) the validity of video urls. _________________ ..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|