def grab_videos(keyword, token=None): res = youtube_search(keyword) token = res[0] videos = res[1] for vid in videos: video_dict['youID'].append(vid['id']['videoId']) video_dict['title'].append(vid['snippet']['title']) video_dict['pub_date'].append(vid['snippet']['publishedAt']) print("added " + str(len(videos)) + " videos to a total of " + str(len(video_dict['youID']))) return token
def get_video(title): search = youtube_search(title, 1) vid_dic = {} for vid in search[1]: vid_dic = { 'title': vid['snippet']['title'], 'thumbnail': vid['snippet']['thumbnails']['high']['url'], 'channel': vid['snippet']['channelTitle'], 'url': 'https://www.youtube.com/watch?v=' + vid['id']['videoId'], 'id': vid['id']['videoId'] } return vid_dic
def get_top_vids(query): search = youtube_search(query, 50) videos = [] for vid in search[1]: vid_dic = { 'title': vid['snippet']['title'], 'thumbnail': vid['snippet']['thumbnails']['high']['url'], 'channel': vid['snippet']['channelTitle'], 'url': 'https://www.youtube.com/watch?v=' + vid['id']['videoId'], 'id': vid['id']['videoId'] } videos.append(vid_dic) return videos
import sys sys.path.append('/home/spnichol/Dropbox/youtube_tutorial/') from youtube import youtube_videos test = youtube_videos.youtube_search("spinners", location="40.730610, -73.935242", location_radius="50km") geo_test = youtube_videos.geo_query('r2GYzQvfARo') location_dict = {"youID": [], "lat": [], "lon": []} for video in test[1]: location_dict['youID'].append((video['id']['videoId'])) geo = youtube_videos.geo_query(video['id']['videoId']) location_dict['lat'].append( geo['items'][0]['recordingDetails']['location']['latitude']) location_dict['lon'].append( geo['items'][0]['recordingDetails']['location']['longitude']) print(location_dict)
import sys sys.path.append('/') from youtube import youtube_videos test = youtube_videos.youtube_search("spinners") video_dict = {'youID': [], 'title': [], 'pub_date': []} just_json = test[1] len(just_json) for video in just_json: print(video['snippet']['title']) token = test[0] youtube_videos.youtube_search("spinners", token=token) video_dict = {'youID': [], 'title': [], 'pub_date': []} def grab_videos(keyword, token=None): res = youtube_videos.youtube_search(keyword, token=token) token = res[0] videos = res[1] for vid in videos: video_dict['youID'].append(vid['id']['videoId']) video_dict['title'].append(vid['snippet']['title']) video_dict['pub_date'].append(vid['snippet']['publishedAt']) print("added " + str(len(videos)) + " videos to a total of " + str(len(video_dict['youID'])))