def get_single_video(client, **kwargs):
    """
  Get video and channel data for a SINGLE video
  """
    kwargs = remove_empty_kwargs(**kwargs)

    response = client.videos().list(**kwargs).execute()

    if not response['items'][0]['snippet']['title'] == 'Private video' \
      and not response['items'][0]['snippet']['title'] == 'Deleted video':
        videoId = response['items'][0]['id']

        channelId = response['items'][0]['snippet']['channelId']
        channelData = get_channel_data(
            client, part='snippet,contentDetails,statistics', id=channelId)

        myTitle = response['items'][0]['snippet']['title']
        myThumbnail = response['items'][0]['snippet']['thumbnails']['default'][
            'url']

        videoDislikes = response['items'][0]['statistics']['dislikeCount']
        videoLikes = response['items'][0]['statistics']['likeCount']
        videoViews = response['items'][0]['statistics']['viewCount']
        videoComments = response['items'][0]['statistics']['commentCount']

        # print(videoId, channelId, channelData, myTitle, myThumbnail, videoComments, videoDislikes, videoLikes, videoViews)
        return (videoId, channelId, channelData, myTitle, myThumbnail,
                videoComments, videoDislikes, videoLikes, videoViews)
示例#2
0
def videosList(client, maxResults, part='snippet,statistics', _chart='mostPopular', _regionCode='US'):
	'''
	Args: 
		client: authorized youtube API client
		channelId: valid youtube channelId that will be searched
		maxResults: max number of results returned
		part: format of each result
	Returns: dict; youtube API response for requested channel
	'''
	return client.videos().list(part=part, maxResults=maxResults, chart=_chart, regionCode=_regionCode).execute()
示例#3
0
def videos_list_most_popular(client, **kwargs):

    kwargs = remove_empty_kwargs(**kwargs)

    response = client.videos().list(**kwargs).execute()

    for res in response.get('items', []):

        my_data = (dateparser.parse(res['snippet']['publishedAt']))
        time_data = my_data.strftime('%H:%M:%S')
        # print(time_data)
        #new_date= (datetime.strptime(time_data, "%H:%M:%S"))
        tup = res['id'], res['snippet']['channelTitle'], res['statistics'][
            'viewCount'], my_data.strftime("%I:%M:%S %p"), calendar.day_name[
                my_data.weekday()]
        cur.execute(
            'INSERT INTO youtube (id, chanTitle, viewCount, time_posted, day) VALUES (?, ?, ?, ?, ?)',
            tup,
        )
示例#4
0
def get_single_video(client, **kwargs):
    """
    Get video and channel data for a SINGLE video
    video dislikes, likes, views, comment count, title, and thumbnail URL
    from a video ID (as well as info from the video's channel as detailed in 
    get_channel_data())
  """
    kwargs = remove_empty_kwargs(**kwargs)

    response = client.videos().list(**kwargs).execute()

    if not response['items'][0]['snippet']['title'] == 'Private video' \
      and not response['items'][0]['snippet']['title'] == 'Deleted video':
        videoId = response['items'][0]['id']

        channelId = response['items'][0]['snippet']['channelId']
        channelData = get_channel_data(
            client, part='snippet,contentDetails,statistics', id=channelId)

        myTitle = response['items'][0]['snippet']['title']
        myThumbnail = response['items'][0]['snippet']['thumbnails']['default'][
            'url']

        videoDislikes = response['items'][0]['statistics']['dislikeCount']
        videoLikes = response['items'][0]['statistics']['likeCount']
        videoViews = response['items'][0]['statistics']['viewCount']
        videoComments = 0
        try:
            videoComments = response['items'][0]['statistics']['commentCount']
        except KeyError:
            print("this video has no comments")
            return videoId, channelId, channelData, myTitle, myThumbnail, videoComments, videoDislikes, videoLikes, videoViews

        return videoId, channelId, channelData, myTitle, myThumbnail, videoComments, videoDislikes, videoLikes, videoViews
    else:
        # status = response['items'][0]['status']['privacyStatus']
        print("This video is a ", response['items'][0]['snippet']['title'])
 def videos_list_most_popular(client, **kwargs):
     # See full sample for function
     kwargs = remove_empty_kwargs(**kwargs)
     response = client.videos().list(**kwargs).execute()
     return response
示例#6
0
def get_duration_from_vid(client, **kwargs):

    kwargs = remove_empty_kwargs(**kwargs)
    response = client.videos().list(**kwargs).execute()
    return response["items"][0]["contentDetails"]["duration"]
def videos_list_by_id(client, **kwargs):
    kwargs = remove_empty_kwargs(**kwargs)

    response = client.videos().list(**kwargs).execute()

    return response