Home

About

This is a KDE service menu with which you can download YouTube videos. It is based on the service menus made by arctor and Hirs but is more like a rewrite nowadays.

With this konqueror service menu it is possible to download a youtube video by right clicking a link to the video (or the background of the video page itself) and choosing "get youtube video" from the actions menu. You can also use the backend Python script directly, if you like.

Screenshots

actions menu demo session

Usage

In Konqueror, right-click onto a link to a YouTube video or at the background of the YouTube site showing the video and choose action -> Download YouTube Video -> ...

Automatic Installation (may not work because of distribution specific paths)

tar xvjf youtube-servicemenu*.tar.bz2
sudo ./youtube-servicemenu*/install-kde3.sh

Or if you use KDE 4 on Fedora

sudo ./youtube-servicemenu*/install-kde4.sh

RPMs

For Fedora RPMs see the project page at kde-apps.org.

Technical Details

This is how I search for video information in the given url or in the page the url points to:

import re

# searching for video id in url:
m = re.search('youtube\.com/v/(?P<video_id>[-A-Za-z0-9_]+)', url)

if m is None:
	m = re.search('video_id=(?P<video_id>[-A-Za-z0-9_]+)', url)

if m is None:
	m = re.search('v=(?P<video_id>[-A-Za-z0-9_]+)', url)

if m is not None:
	# video id found
	result = [m.group('video_id')]

else:
	# searching for video ids in content:
	stream = urlopener.open(url)
	
	try:
		data = stream.read()
	finally:
		stream.close()
	
	result = set(re.findall('youtube\.com/v/([-A-Za-z0-9_]+)', data))
	
	if not result:
		result = set(re.findall('video_id=([-A-Za-z0-9_]+)', data))
	
	if not result:
		result = set(re.findall('v=([-A-Za-z0-9_]+)', data))
	
	if not result:
		showError(
			_("Save YouTube Video"),
			_("Can\'t get the youtube-videos ID out of the url or the referred site content.\n"
			"Maybe you have to be logged in to view this video?"))

Now result is a list of video ids. I get the download informations by searching the video's page like this:

import urllib
from lxml import html

try:
	from urlparse import parse_qs
except ImportError:
	from cgi import parse_qs

try:
	import json
except ImportError:
	import simplejson as json

doc = html.document_fromstring(unicode(urllib.urlopen("http://www.youtube.com/watch?v=45gsH7JleKg").read(),'utf-8'))

video_id = None
fmt_stream_map = None
	
for script in doc.xpath("//script"):
	m = re.search(r"^\s*yt\.playerConfig\s*=\s*(.*);\s*$",script.text,re.M)
	if m:
		try:
			config = json.loads(m.group(1))
			args = config.get('args',None)
			if args:
				video_id = args.get('video_id',None)
				fmt_stream_map = args.get('url_encoded_fmt_stream_map',None)
				fmt_stream_map = [dict((item[0], ''.join(item[1])) for item in parse_qs(info).items()) for info in fmt_stream_map.split(",")]
		except ValueError:
			pass

Now fmt_stream_map is a list of dicts that contain these keys:

KeyValue
urlstream/download URL
typemime type
qualitysmall, medium, large, hd720, hd1080
itagnumber indicating the video type and quality
fallback_hostalternative host name

itag values:

Video Formatresolutionitag
FLV360p5
FLV480p?6
3GP240?13
3GP144p17
MP4480p18
MP4720p22
MP4360p34
MP4480p35
MP41080p37
MP43072p38
WEBM360p43
WEBM720p45

Some other information can be obtained like this:

video_title = None
user_name = None
video_object = doc.xpath('//*[@itemscope][@itemtype="http://schema.org/VideoObject"]')
if video_object:
	video_object = video_object[0]
	video_title = video_object.xpath('//meta[@itemprop="name"]/@content')
	user_name = video_object.xpath('//a[@rel="author"]/@title')

Note that not all videos support all video formats.

See also: Quality and codecs

Enjoy! :)

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.