diff --git a/youtube_api/parsers.py b/youtube_api/parsers.py index 44f2ca1..b974cf1 100644 --- a/youtube_api/parsers.py +++ b/youtube_api/parsers.py @@ -70,6 +70,7 @@ def parse_video_metadata(item): "video_comment_count" : item["statistics"].get("commentCount"), "video_like_count" : item["statistics"].get("likeCount"), "video_dislike_count" : item["statistics"].get("dislikeCount"), + "duration" : item["contentDetails"]["duration"], "video_thumbnail" : item["snippet"]["thumbnails"]["high"]["url"], "video_tags" : video_tags, "collection_date" : datetime.datetime.now() diff --git a/youtube_api/youtube_api.py b/youtube_api/youtube_api.py index d661c74..8f1eb25 100644 --- a/youtube_api/youtube_api.py +++ b/youtube_api/youtube_api.py @@ -204,9 +204,9 @@ def get_channel_metadata(self, channel_id, parser=P.parse_channel_metadata, def get_video_metadata_gen(self, video_id, parser=P.parse_video_metadata, - part=['statistics','snippet'], **kwargs): + part=['statistics','snippet','contentDetails'], **kwargs): ''' - Given a `video_id` returns metrics (views, likes, comments) and metadata (description, category) as a dictionary. + Given a `video_id` returns metrics (views, likes, comments, duration) and metadata (description, category) as a dictionary. Read the docs: https://developers.google.com/youtube/v3/docs/videos/list @@ -238,12 +238,12 @@ def get_video_metadata_gen(self, video_id, parser=P.parse_video_metadata, else: yield parser(None) else: - raise Expection('This function only takes iterables!') + raise Exception('This function only takes iterables!') - def get_video_metadata(self, video_id, parser=P.parse_video_metadata, part=['statistics','snippet'], **kwargs): + def get_video_metadata(self, video_id, parser=P.parse_video_metadata, part=['statistics','snippet','contentDetails'], **kwargs): ''' - Given a single or list of `video_id` returns metrics (views, likes, comments) and metadata (description, category) as a dictionary. + Given a single or list of `video_id` returns metrics (views, likes, comments, duration) and metadata (description, category) as a dictionary. Read the docs: https://developers.google.com/youtube/v3/docs/videos/list