Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion scrapetube/scrapetube.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def get_channel(
limit: int = None,
sleep: int = 1,
sort_by: Literal["newest", "oldest", "popular"] = "newest",
content_type: Literal["videos", "streams"] = "videos"
) -> Generator[dict, None, None]:

"""Get videos for a channel.
Expand All @@ -38,12 +39,19 @@ def get_channel(
``"newest"``: Get the new videos first.
``"oldest"``: Get the old videos first.
``"popular"``: Get the popular videos first. Defaults to "newest".

content_type (``str``, *optional*):
What type of videos to retrieve. Pass one of these allowed values:
``"videos"``: Get all public videos uploads from the channel.
``"streams"``: Get all public livestreams from the channel.
Defaults to "videos".
"""

sort_by_map = {"newest": "dd", "oldest": "da", "popular": "p"}
url = "{url}/videos?view=0&sort={sort_by}&flow=grid".format(
url = "{url}/{type}&sort={sort_by}&flow=grid".format(
url=channel_url or f"https://www.youtube.com/channel/{channel_id}",
sort_by=sort_by_map[sort_by],
type=content_type
)
api_endpoint = "https://www.youtube.com/youtubei/v1/browse"
videos = get_videos(url, api_endpoint, "gridVideoRenderer", limit, sleep)
Expand Down