Advertisement
Guest User

Untitled

a guest
May 30th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. def youtube(searchterm):
  2.     searchterm = quote(get_nowplaying())
  3.     url = "https://gdata.youtube.com/feeds/api/videos?q={}&orderBy=relevance&alt=json"
  4.     url = url.format(searchterm)
  5.  
  6.     j = requests.get(url).json()
  7.  
  8.     results = j["feed"]
  9.     if "entry" not in results:
  10.         return "sorry, no videos found"
  11.  
  12.     video = results["entry"][0]["link"][0]["href"]
  13.     video = re.sub("&feature=youtube_gdata", "", video)
  14.  
  15.     return video
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement