|
@@ -46,6 +46,10 @@ def get_channel(
|
|
|
Seconds to sleep between API calls to youtube, in order to prevent getting blocked.
|
|
|
Defaults to 1.
|
|
|
|
|
|
+ proxies (``dict``, *optional*):
|
|
|
+ A dictionary with the proxies you want to use. Ex:
|
|
|
+ ``{'https': 'http://username:password@101.102.103.104:3128'}``
|
|
|
+
|
|
|
sort_by (``str``, *optional*):
|
|
|
In what order to retrieve to videos. Pass one of the following values.
|
|
|
``"newest"``: Get the new videos first.
|
|
@@ -78,7 +82,7 @@ def get_channel(
|
|
|
|
|
|
|
|
|
def get_playlist(
|
|
|
- playlist_id: str, limit: int = None, sleep: int = 1
|
|
|
+ playlist_id: str, limit: int = None, sleep: int = 1, proxies: dict = None
|
|
|
) -> Generator[dict, None, None]:
|
|
|
|
|
|
"""Get videos for a playlist.
|
|
@@ -93,6 +97,10 @@ def get_playlist(
|
|
|
sleep (``int``, *optional*):
|
|
|
Seconds to sleep between API calls to youtube, in order to prevent getting blocked.
|
|
|
Defaults to 1.
|
|
|
+
|
|
|
+ proxies (``dict``, *optional*):
|
|
|
+ A dictionary with the proxies you want to use. Ex:
|
|
|
+ ``{'https': 'http://username:password@101.102.103.104:3128'}``
|
|
|
"""
|
|
|
|
|
|
url = f"https://www.youtube.com/playlist?list={playlist_id}"
|
|
@@ -108,6 +116,7 @@ def get_search(
|
|
|
sleep: int = 1,
|
|
|
sort_by: Literal["relevance", "upload_date", "view_count", "rating"] = "relevance",
|
|
|
results_type: Literal["video", "channel", "playlist", "movie"] = "video",
|
|
|
+ proxies: dict = None,
|
|
|
) -> Generator[dict, None, None]:
|
|
|
|
|
|
"""Search youtube and get videos.
|
|
@@ -134,6 +143,11 @@ def get_search(
|
|
|
results_type (``str``, *optional*):
|
|
|
What type you want to search for. Pass one of the following values:
|
|
|
``"video"|"channel"|"playlist"|"movie"``. Defaults to "video".
|
|
|
+
|
|
|
+ proxies (``dict``, *optional*):
|
|
|
+ A dictionary with the proxies you want to use. Ex:
|
|
|
+ ``{'https': 'http://username:password@101.102.103.104:3128'}``
|
|
|
+
|
|
|
"""
|
|
|
|
|
|
sort_by_map = {
|
|
@@ -188,7 +202,7 @@ def get_video(
|
|
|
|
|
|
|
|
|
def get_videos(
|
|
|
- url: str, api_endpoint: str, selector: str, limit: int, sleep: float, proxies, sort_by: str = None
|
|
|
+ url: str, api_endpoint: str, selector: str, limit: int, sleep: float, proxies: dict = None, sort_by: str = None
|
|
|
) -> Generator[dict, None, None]:
|
|
|
session = get_session(proxies)
|
|
|
is_first = True
|
|
@@ -232,9 +246,9 @@ def get_videos(
|
|
|
session.close()
|
|
|
|
|
|
|
|
|
-def get_session(proxies) -> requests.Session:
|
|
|
+def get_session(proxies: dict = None) -> requests.Session:
|
|
|
session = requests.Session()
|
|
|
- if proxies != None:
|
|
|
+ if proxies:
|
|
|
session.proxies.update(proxies)
|
|
|
session.headers[
|
|
|
"User-Agent"
|