Skip to content

Commit

Permalink
changed all video_id to videoId
Browse files Browse the repository at this point in the history
  • Loading branch information
melvinchia3636 committed Mar 6, 2022
1 parent 9ccef74 commit 0d349fd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ Here come the most important part of this API - The Ultimate Video Object. With

.. code-block:: python
>>> video_id = 'WzxSiEWK3cg'
>>> api.video(video_id)
>>> videoId = 'WzxSiEWK3cg'
>>> api.video(videoId)
<Video id="WzxSiEWK3cg" title="PARIS | A380 LANDING 4K EXTENDED" author="High Pressure Aviation Films">
There you go! You've just created a video Object with contains everything about the video. Suppose you have a video object with the name ``video`` on hand right now, let's see some examples of how we can use it:
Expand Down
6 changes: 5 additions & 1 deletion src/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
print(filters.type)
print(filters.upload_date)

print(api.search("space", filter=SearchFilter(features=["360°"]))[0])
print(api.search("space", filter=SearchFilter(features=["360°"]))[0])
print(api.search("hermitcraft", filter=SearchFilter(upload_date="Today"))[0])

#playlist test
print(api.playlist("PLU2851hDb3SE6S9YJFY6n1B4t_Qv26f1m"))
8 changes: 4 additions & 4 deletions src/youtube_scraping_api/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ def channel(self, channel_id=None, username=None):
result = Channel(channel_id=channel_id, username=username)
return result

def video(self, video_id: str) -> Video:
def video(self, videoId: str) -> Video:
"""Parse video metadata, captions, download link, etc.
:param video_id:
:param videoId:
ID of Youtube video
:type video_id: str
:type videoId: str
:return: Video object
:rtype: Video
"""
return Video(video_id)
return Video(videoId)

def query_suggestions(self, query=None, language='en', country='gb'):
"""Return a list of query suggestions for given query string
Expand Down
12 changes: 6 additions & 6 deletions src/youtube_scraping_api/parser/search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def raw(self):

class LiveStream:
def __init__(self, data):
self.id = data["video_id"]
self.id = data["videoId"]
self.title = "".join(i["text"] for i in data["title"]["runs"])
self.description = "".join(i["text"] for i in data["descriptionSnippet"]["runs"]) if "descriptionSnippet" in data else None
self.watching_count = int(data["viewCountText"]["runs"][0]["text"].replace(",", "")) if "viewCountText" in data else None
Expand All @@ -97,7 +97,7 @@ def __init__(self, data):
channel_id = data["ownerText"]["runs"][0]["navigationEndpoint"]["browseEndpoint"]["browseId"],
builtin_called = True
)
self.thumbnail = get_thumbnail(data["video_id"])
self.thumbnail = get_thumbnail(data["videoId"])

def __repr__(self):
return f'<LiveStream id="{self.id}" title="{self.title}">'
Expand All @@ -106,7 +106,7 @@ def __repr__(self):
def raw(self):
return {
"type": "live_stream",
"video_id": self.id,
"videoId": self.id,
"title": self.title,
"description": self.description,
"watching_count": self.watching_count,
Expand Down Expand Up @@ -249,7 +249,7 @@ def __repr__(self):
def raw(self):
return {
"type": "playlist_video",
"video_id": self.id,
"videoId": self.id,
"title": self.title,
"length": self.length
}
Expand Down Expand Up @@ -304,7 +304,7 @@ def raw(self):
"radioRenderer": Mix,
"shelfRenderer": Shelf,
"liveStreamRenderer": lambda x: Video(
x["video_id"],
x["videoId"],
title="".join(i["text"] for i in x["title"]["runs"]),
author=Channel(
name = x["ownerText"]["runs"][0]["text"],
Expand Down Expand Up @@ -337,7 +337,7 @@ def raw(self):
"previewCardRenderer": None,
"searchPyvRenderer": lambda x: cleanupData(x['ads'])[0],
"promotedVideoRenderer": lambda x: Video(
x["video_id"],
x["videoId"],
title = x["title"]["simpleText"],
author = Channel(
name = x["longBylineText"]["runs"][0]["text"],
Expand Down
6 changes: 3 additions & 3 deletions src/youtube_scraping_api/parser/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class Video():
"""Container for video data"""
def __init__(self, video_id: str, builtin_called: bool = False, **kwargs):
def __init__(self, videoId: str, builtin_called: bool = False, **kwargs):
self._session = requests.Session()
self._session.headers = HEADERS
self._has_generated = False
Expand All @@ -28,7 +28,7 @@ def __init__(self, video_id: str, builtin_called: bool = False, **kwargs):
self._player_info = None
self._is_builtin_called = builtin_called

self.id = video_id
self.id = videoId
self.thumbnails = get_thumbnail(self.id)

self._static_properties = kwargs
Expand Down Expand Up @@ -189,7 +189,7 @@ def raw(self) -> Dict[str, Any]:
primary_info = self._primary_info
player_info = self._player_info
cleaned_data = {
"video_id": self.id,
"videoId": self.id,
"type": self.type,
"title": self.title,
"supertitle": self.supertitle,
Expand Down
8 changes: 4 additions & 4 deletions src/youtube_scraping_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ def reveal_redirect_url(url):
"""
return bs(requests.get(url, headers=HEADERS).content, "lxml").find("div", {"id": "redirect-action-container"}).find("a")["href"]

def get_thumbnail(video_id):
def get_thumbnail(videoId):
"""Get url for thumbnails of video
:param video_id: Youtube ID of the video
:type video_id: str
:param videoId: Youtube ID of the video
:type videoId: str
:return: A dictionary of thumbnail urls
:rtype: dict
:todo: Check thumbnail urls availability
"""
return dict(map(lambda i: (i[0], i[1].format(video_id)), THUMBNAIL_TEMPLATE.items()))
return dict(map(lambda i: (i[0], i[1].format(videoId)), THUMBNAIL_TEMPLATE.items()))

def get_proxy():
proxies = requests.get('https://api.proxyscrape.com/v2/?request=getproxies&protocol=http&timeout=4550&country=all&ssl=all&anonymity=all&simplified=true').text.split('\r\n')
Expand Down

0 comments on commit 0d349fd

Please sign in to comment.