Advertisement
Thelorgoreng

Youtube search

Aug 3rd, 2015
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. ############################################################################
  2. ############################################################################
  3. ##                                                                        ##
  4. ## Youtube search from Youtube Data API V3 . Use this as you please.      ##
  5. ## Also, You can fetch the API URL and use my API key as you please.      ##
  6. ## But when you do, please use it wisely since it's a free to use,        ##
  7. ## meaning, there are some ppl who may use it. The request quota          ##
  8. ## for my API key is limited, so please don't waste them on useless       ##
  9. ## requests.                                                              ##
  10. ##                                                                        ##
  11. ## Thelorgorenk                                                           ##
  12. ##                                                                        ##
  13. ############################################################################
  14. ############################################################################
  15.  
  16.  
  17. import sys
  18. import json
  19. import random
  20.  
  21. if sys.version_info[0] > 2:
  22.   import urllib.request as urlreq
  23. else:
  24.   import urllib2 as urlreq
  25.  
  26. def tube(args):
  27.   """
  28. #In case you don't know how to use this function
  29. #type this in the python console:
  30. >>> tube("pokemon dash")
  31. #and this function would return this thing:
  32. {'title': 'TAS (DS) Pokémon Dash - Regular Grand Prix', 'descriptions': '1st round Grand Prix but few mistake a first time. Next Hard Grand Prix will know way and few change different Pokémon are more faster and same course Cup.', 'uploader': 'EddieERL', 'link': 'http://www.youtube.com/watch?v=QdvnBmBQiGQ', 'videoid': 'QdvnBmBQiGQ', 'viewcount': '2014-11-04T15:43:15.000Z'}
  33. """
  34.   search = args.split()
  35.   url = urlreq.urlopen("https://www.googleapis.com/youtube/v3/search?q=%s&part=snippet&key=AIzaSyBSnh-sIjd97_FmQVzlyGbcaYXuSt_oh84" % "+".join(search))
  36.   udict = url.read().decode('utf-8')
  37.   data = json.loads(udict)
  38.   rest = []
  39.   for f in data["items"]:
  40.     rest.append(f)
  41.  
  42.   d = random.choice(rest)
  43.   link = "http://www.youtube.com/watch?v=" + d["id"]["videoId"]
  44.   videoid = d["id"]["videoId"]
  45.   title = d["snippet"]["title"]
  46.   uploader = d["snippet"]["channelTitle"]
  47.   descript = d["snippet"]['description']
  48.   count    = d["snippet"]["publishedAt"]
  49.   return "Result: %s <br/><br/><br/><br/><br/><br/><br/><br/><font color='#ffcc00'><b>%s</b></font><br/><font color='#ff0000'><b>Uploader</b></font>:<b> %s</b><br/><font color='#ff0000'><b>Uploaded on</b></font>: %s<br/><font color='#ff0000'><b>Descriptions</b></font>:<i> %s ...</i><br/> " % (link, title, uploader, count, descript[:200])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement