Skip to content

Commit

Permalink
support channel_username
Browse files Browse the repository at this point in the history
  • Loading branch information
dermasmid committed Jun 12, 2023
1 parent 0e31634 commit 568fd2d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions scrapetube/scrapetube.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
def get_channel(
channel_id: str = None,
channel_url: str = None,
channel_username: str = None,
limit: int = None,
sleep: int = 1,
sort_by: Literal["newest", "oldest", "popular"] = "newest",
Expand All @@ -32,6 +33,11 @@ def get_channel(
Since there is a few type's of channel url's, you can use the one you want
by passing it here instead of using ``channel_id``.
channel_username (``str``, *optional*):
The username from the channel you want to get the videos for.
Ex. ``LinusTechTips`` (without the @).
If you prefer to use the channel url instead, see ``channel_url`` above.
limit (``int``, *optional*):
Limit the number of videos you want to get.
Expand All @@ -52,9 +58,18 @@ def get_channel(
``"streams"``: Streams
"""

sort_by_map = {"newest": "dd", "oldest": "da", "popular": "p"}
url = "{url}/{content_type}?view=0&sort={sort_by}&flow=grid".format(
url=channel_url or f"https://www.youtube.com/channel/{channel_id}",
sort_by_map = {"newest": "dd", "oldest": "da", "popular": "p"}

base_url = ""
if channel_url:
base_url = channel_url
elif channel_id:
base_url = f"https://www.youtube.com/channel/{channel_id}"
elif channel_username:
base_url = f"https://www.youtube.com/@{channel_username}"

url = "{base_url}/{content_type}?view=0&sort={sort_by}&flow=grid".format(
base_url=base_url,
content_type=content_type,
sort_by=sort_by_map[sort_by],
)
Expand Down

0 comments on commit 568fd2d

Please sign in to comment.