Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############################################################################
- ############################################################################
- ## ##
- ## Youtube search from Youtube Data API V3 . Use this as you please. ##
- ## Also, You can fetch the API URL and use my API key as you please. ##
- ## But when you do, please use it wisely since it's a free to use, ##
- ## meaning, there are some ppl who may use it. The request quota ##
- ## for my API key is limited, so please don't waste them on useless ##
- ## requests. ##
- ## ##
- ## Thelorgorenk ##
- ## ##
- ############################################################################
- ############################################################################
- import sys
- import json
- import random
- if sys.version_info[0] > 2:
- import urllib.request as urlreq
- else:
- import urllib2 as urlreq
- def tube(args):
- """
- #In case you don't know how to use this function
- #type this in the python console:
- >>> tube("pokemon dash")
- #and this function would return this thing:
- {'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'}
- """
- search = args.split()
- url = urlreq.urlopen("https://www.googleapis.com/youtube/v3/search?q=%s&part=snippet&key=AIzaSyBSnh-sIjd97_FmQVzlyGbcaYXuSt_oh84" % "+".join(search))
- udict = url.read().decode('utf-8')
- data = json.loads(udict)
- rest = []
- for f in data["items"]:
- rest.append(f)
- d = random.choice(rest)
- link = "http://www.youtube.com/watch?v=" + d["id"]["videoId"]
- videoid = d["id"]["videoId"]
- title = d["snippet"]["title"]
- uploader = d["snippet"]["channelTitle"]
- descript = d["snippet"]['description']
- count = d["snippet"]["publishedAt"]
- 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