def you(request): from apiclient.discovery import build from apiclient.errors import HttpError import pprint DEVELOPER_KEY = "AIzaSyD3TnRkfHqDBcAjD0vGfpCE473hwje12tg" YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_VERSION = "v3" youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) # Call the search.list method to retrieve results matching the specified # query term. search_response = youtube.search().list( q="google", part="snippet", type="video", maxResults=1, ).execute() videos = [] for search_result in search_response.get("items", []): videos.append("%s" % (search_result["id"]["videoId"])) print "Videos:\n", "\n".join(videos), "\n" print search_response.get("items", []) pprint.pprint(search_response,indent=4) return HttpResponse('hello')
def search(youtube, keyword): # Call the search.list method to retrieve results matching the specified # query term. search_response = youtube.search().list(q=keyword,part="id,snippet",maxResults=10,type="video").execute() videos = [] # Add each result to the appropriate list, and then display the lists of # matching videos, channels, and playlists. for search_result in search_response.get("items", []): videos.append(search_result["id"]["videoId"]) return videos[0]
def search_by_keyword(qTerm): youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey='AIzaSyA8XJm8lda2bCjACudSN0VffMhUdF3f-7Q') search_response = youtube.search().list(q=qTerm, part="id,snippet", maxResults=25).execute() videos = [] for search_result in search_response.get("items", []): if search_result["id"]["kind"] == "youtube#video": videos.append("%s (%s)" % (search_result["snippet"]["title"], search_result["id"]["videoId"])) return videos
def search_by_keyword(): search_response = youtube.search().list( part="snippet", channelId = BOILER_ROOM_CHANNELID, order = "viewCount", maxResults=50 ).execute() videos = [] v = dict() titles = [] for search_result in search_response.get("items", []): if search_result["id"]["kind"] == "youtube#video": videos.append("%s" % str(search_result["id"]["videoId"])) v[search_result["id"]["videoId"]] = search_result["snippet"]["title"] titles.append("%s" % search_result["snippet"]["title"]) return videos
def getYouTubeVideoIds(keyword, maxresults): youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,developerKey=DEVELOPER_KEY) search_response = youtube.search().list(q=keyword,part="id,snippet",maxResults=maxresults).execute() videos_id = [] try: for search_result in search_response.get("items", []): if search_result["id"]["kind"] == "youtube#video": videos_id.append(search_result["id"]["videoId"]) #print "Title : " + search_result["snippet"]["title"] #print "Id : " + search_result["id"]["videoId"] except Exception as e: print "Error in retrieving comments from youtube.. \n" print e return videos_id
def youtube_search(options, TEXT): youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) search_response = youtube.search().list( q=TEXT, type="video", location=options.location, locationRadius=options.location_radius, part="id,snippet", maxResults=options.max_results).execute() search_videos = [] # Merge video ids for search_result in search_response.get("items", []): search_videos.append(search_result["id"]["videoId"]) video_ids = ",".join(search_videos) video_response = youtube.videos().list( id=video_ids, part='snippet, recordingDetails, statistics, contentDetails,id' ).execute() videos = [] # Add each result to the list, and then display the list of matching videos. for video_result in video_response.get("items", []): #videos.append("title: %s\n likes: %s\n location: (%s,%s)" % (video_result["snippet"]["title"],video_result["statistics"]["likeCount"],video_result["recordingDetails"]["location"]["latitude"],video_result["recordingDetails"]["location"]["longitude"])) print "title:" + video_result["snippet"]["title"] print "URL: " + "https://www.youtube.com/watch?v=" + video_result["id"] print "likes:" + video_result["statistics"]["likeCount"] print "dislikes:" + video_result["statistics"]["dislikeCount"] print "viewCount:" + video_result["statistics"]["viewCount"] print "favoriteCount: " + video_result["statistics"]["favoriteCount"] print "commentCount: " + video_result["statistics"]["commentCount"] print "location: ", video_result["recordingDetails"]["location"][ "latitude"], video_result["recordingDetails"]["location"][ "longitude"] print "duration: ", video_result["contentDetails"]["duration"] print
def getYouTubeVideoIds(keyword, maxresults): youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) search_response = youtube.search().list(q=keyword, part="id,snippet", maxResults=maxresults).execute() videos_id = [] try: for search_result in search_response.get("items", []): if search_result["id"]["kind"] == "youtube#video": videos_id.append(search_result["id"]["videoId"]) #print "Title : " + search_result["snippet"]["title"] #print "Id : " + search_result["id"]["videoId"] except Exception as e: print "Error in retrieving comments from youtube.. \n" print e return videos_id
import urllib import csv import gdata.youtube import gdata.youtube.service # Set DEVELOPER_KEY to the "API key" value from the "Access" tab of the # Google APIs Console http://code.google.com/apis/console#access # Please ensure that you have enabled the YouTube Data API for your project. DEVELOPER_KEY = "AIzaSyCpl5TM4HFVXIfAdy1PeLByqAWrlaHEqdk" YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_VERSION = "v3" FREEBASE_SEARCH_URL = "https://www.googleapis.com/freebase/v1/search?%s" youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) ysearch = youtube.search() ''' yt_service = gdata.youtube.service.YouTubeService() entry = yt_service.GetYouTubeVideoEntry(video_id='the0KZLEacs') search_terms='mathematics and education' def SearchAndPrint(search_terms): yt_service = gdata.youtube.service.YouTubeService() query = gdata.youtube.service.YouTubeVideoQuery() query.vq = search_terms query.orderby = 'viewCount' query.racy = 'include' feed = yt_service.YouTubeQuery(query) print feed