Skip to content

Instantly share code, notes, and snippets.

@FiXato
Created October 14, 2012 23:12
Show Gist options
  • Save FiXato/3890124 to your computer and use it in GitHub Desktop.
Save FiXato/3890124 to your computer and use it in GitHub Desktop.
Retrieve page title for YouTube video ID.
# If the url is a youtube URL, make sure we query the api instead of the actual page to prevent triggering captcha requests
if 'v=' in url and ('youtube.com' in url or 'youtu.be' in url):
m = re.search('v=([\w\d_-]+)', url)
if m:
youtube_id = m.group(1)
url = "http://gdata.youtube.com/feeds/api/videos?v=2&q=" + youtube_id + "&max-results=1&fields=entry(title)&prettyprint=false"
weechat.prnt("", url)
#!/bin/bash
curl -A "Title Retriever" --silent "http://gdata.youtube.com/feeds/api/videos?v=2&q=$1&max-results=1&fields=entry(title)&prettyprint=false"|awk -vRS="</title>" '/<title>/{gsub(/.*<title>|\n+/,"");print;exit}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment