Skip to content

Commit

Permalink
Merge pull request #39 from BismeetSingh/feature/async-videoinfo-call
Browse files Browse the repository at this point in the history
Change video info to be generator
  • Loading branch information
Agent-Hellboy authored Oct 15, 2022
2 parents a7500b7 + 8582634 commit 3ce31fc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ Using
>>> obj=PyYtData('flask',1)
>>> vid=obj.get_videoinfo()
>>> vid
[<util.vidinfo.VidInfo object at 0x7ff971539e10>]
<generator object PyYtData.get_videoinfo at 0x7fb0f69f8040>
#Since get_videoinfo returns a generator, you can either iterate or get the next() item.
#You can fire dir on this object to get the attribute and method of the object.
>>> dir(vid[0])
>>> dir(next(vid))
['_Info__API_KEY', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_id', 'channel_info', 'get_description', 'get_image_url', 'get_link', 'get_publishedtime', 'get_title', 'keyword', 'maxlen', 'open_id', 'order', 'result', 'type', 'youtube']
For more examples refer to the `\docs` folder
Expand Down
46 changes: 23 additions & 23 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,34 @@ An API which will take the URL of youtube video and provide metadata of the vide
>>> obj=PyYtData('flask',1)
>>> vid=obj.get_videoinfo()
>>> vid
[<util.vidinfo.VidInfo object at 0x7ff971539e10>]
<generator object PyYtData.get_videoinfo at 0x7fb0f69f8040>
#Since get_videoinfo returns a generator, you can either iterate or get the next() item.
#You can fire dir on this object to get the attribute and method of the object.
>>> dir(vid[0])
>>> dir(next(vid))
['_Info__API_KEY', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_id', 'channel_info', 'get_description', 'get_image_url', 'get_link', 'get_publishedtime', 'get_title', 'keyword', 'maxlen', 'open_id', 'order', 'result', 'type', 'youtube']
# To get the description of the video
>>> vid[0].get_description()
>>> next(vid).get_description()
'Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. Learn how to use it ...'
# To get the title of the video.
>>> vid[0].get_title()
>>> next(vid).get_title()
'Learn Flask for Python - Full Tutorial'
# To get the link for the video which can we used in web app to open the link for the video.
>>> vid[0].get_link()
>>> next(vid).get_link()
'https://www.youtube.com/watch?v=Z1RJmh_OqeA'
# To get the title img of the video which can be rendered through HTML tag.
>>> vid[0].get_image_url()
>>> next(vid).get_image_url()
'https://i.ytimg.com/vi/Z1RJmh_OqeA/mqdefault.jpg'
# To get the date at which the video is published
>>> vid[0].get_publisheddate()
>>> next(vid).get_publisheddate()
# To get the chnlInfo object having methods which describes a channel.
>>> chnl=vid[0].channel_info()
>>> chnl=next(vid).channel_info()
>>> dir(chnl)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'id', 'result', 'total_subscriber', 'total_video', 'total_viewcnt', 'youtube']
Expand All @@ -78,7 +78,7 @@ An API which will take the URL of youtube video and provide metadata of the vide
'1133'
# To get the obejct having stat of the video
>>> vidinf=vid[0].video_stat()
>>> vidinf=next(vid).video_stat()
# To get total number of like to the video
>>> vidinf.total_like()
Expand All @@ -97,7 +97,7 @@ An API which will take the URL of youtube video and provide metadata of the vide
'621'
# To get the object having info about comment on the video
>>> cmntinfo=vid[0].comment_info()
>>> cmntinfo=next(vid).comment_info()
>>> cmntinfo.comment_author(2)
'Fourierwave'
Expand All @@ -112,18 +112,18 @@ An API which will take the URL of youtube video and provide metadata of the vide
# working on it @ToDo
# To get the link for the video which can we used in web app to open the link for the video.
>>> vid[0].get_link()
>>> next(vid).get_link()
'https://www.youtube.com/watch?v=Z1RJmh_OqeA'
# To get the title img of the video which can be rendered through HTML tag.
>>> vid[0].get_image_url()
>>> next(vid).get_image_url()
'https://i.ytimg.com/vi/Z1RJmh_OqeA/mqdefault.jpg'
# To get the date at which the video is published
>>> vid[0].get_publisheddate()
>>> next(vid).get_publisheddate()
# To get the chnlInfo object having methods which describes a channel.
>>> chnl=vid[0].channel_info()
>>> chnl=next(vid).channel_info()
>>> dir(chnl)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'id', 'result', 'total_subscriber', 'total_video', 'total_viewcnt', 'youtube']
Expand All @@ -141,7 +141,7 @@ An API which will take the URL of youtube video and provide metadata of the vide
'1133'
# To get the obejct having stat of the video
>>> vidinf=vid[0].video_stat()
>>> vidinf=next(vid).video_stat()
# To get total number of like to the video
>>> vidinf.total_like()
Expand All @@ -160,7 +160,7 @@ An API which will take the URL of youtube video and provide metadata of the vide
'621'
# To get the object having info about comment on the video
>>> cmntinfo=vid[0].comment_info()
>>> cmntinfo=next(vid).comment_info()
>>> cmntinfo.comment_author(2)
'Fourierwave'
Expand All @@ -175,18 +175,18 @@ An API which will take the URL of youtube video and provide metadata of the vide
# working on it @ToDo
# To get the link for the video which can we used in web app to open the link for the video.
>>> vid[0].get_link()
>>> next(vid).get_link()
'https://www.youtube.com/watch?v=Z1RJmh_OqeA'
# To get the title img of the video which can be rendered through HTML tag.
>>> vid[0].get_image_url()
>>> next(vid).get_image_url()
'https://i.ytimg.com/vi/Z1RJmh_OqeA/mqdefault.jpg'
# To get the date at which the video is published
>>> vid[0].get_publisheddate()
>>> next(vid).get_publisheddate()
# To get the chnlInfo object having methods which describes a channel.
>>> chnl=vid[0].channel_info()
>>> chnl=next(vid).channel_info()
>>> dir(chnl)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'id', 'result', 'total_subscriber', 'total_video', 'total_viewcnt', 'youtube']
Expand All @@ -204,7 +204,7 @@ An API which will take the URL of youtube video and provide metadata of the vide
'1133'
# To get the obejct having stat of the video
>>> vidinf=vid[0].video_stat()
>>> vidinf=next(vid).video_stat()
# To get total number of like to the video
>>> vidinf.total_like()
Expand All @@ -223,7 +223,7 @@ An API which will take the URL of youtube video and provide metadata of the vide
'621'
# To get the object having info about comment on the video
>>> cmntinfo=vid[0].comment_info()
>>> cmntinfo=next(vid).comment_info()
>>> cmntinfo.comment_author(2)
'Fourierwave'
Expand Down
6 changes: 1 addition & 5 deletions pyytdata/pyytdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ def __init__(self, keyword: str, maxlen: int, type: str = "video") -> None:

def get_videoinfo(self) -> List:
"""Returns a list with has objects of VidInfo class"""
rslt = []

for i in range(self.maxlen):
vid = VidInfo(self.type, self.keyword, self.maxlen, i)
rslt.append(vid)
return rslt
yield VidInfo(self.type, self.keyword, self.maxlen, i)
6 changes: 3 additions & 3 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime
import os
import types
import unittest

from pyytdata import PyYtData


Expand All @@ -14,7 +13,8 @@ def setUp(self):
self.rslt = self.data.get_videoinfo()

def test_get_videoinfo(self):
self.assertTrue(len(self.rslt) == 1)
self.assertIsInstance(self.rslt, types.GeneratorType)
self.assertTrue(len(list(self.rslt)) == 1)


if __name__ == "__main__":
Expand Down

0 comments on commit 3ce31fc

Please sign in to comment.