Skip to content

Commit 568fd2d

Browse files
committed
support channel_username
1 parent 0e31634 commit 568fd2d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

scrapetube/scrapetube.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
def get_channel(
1515
channel_id: str = None,
1616
channel_url: str = None,
17+
channel_username: str = None,
1718
limit: int = None,
1819
sleep: int = 1,
1920
sort_by: Literal["newest", "oldest", "popular"] = "newest",
@@ -32,6 +33,11 @@ def get_channel(
3233
Since there is a few type's of channel url's, you can use the one you want
3334
by passing it here instead of using ``channel_id``.
3435
36+
channel_username (``str``, *optional*):
37+
The username from the channel you want to get the videos for.
38+
Ex. ``LinusTechTips`` (without the @).
39+
If you prefer to use the channel url instead, see ``channel_url`` above.
40+
3541
limit (``int``, *optional*):
3642
Limit the number of videos you want to get.
3743
@@ -52,9 +58,18 @@ def get_channel(
5258
``"streams"``: Streams
5359
"""
5460

55-
sort_by_map = {"newest": "dd", "oldest": "da", "popular": "p"}
56-
url = "{url}/{content_type}?view=0&sort={sort_by}&flow=grid".format(
57-
url=channel_url or f"https://www.youtube.com/channel/{channel_id}",
61+
sort_by_map = {"newest": "dd", "oldest": "da", "popular": "p"}
62+
63+
base_url = ""
64+
if channel_url:
65+
base_url = channel_url
66+
elif channel_id:
67+
base_url = f"https://www.youtube.com/channel/{channel_id}"
68+
elif channel_username:
69+
base_url = f"https://www.youtube.com/@{channel_username}"
70+
71+
url = "{base_url}/{content_type}?view=0&sort={sort_by}&flow=grid".format(
72+
base_url=base_url,
5873
content_type=content_type,
5974
sort_by=sort_by_map[sort_by],
6075
)

0 commit comments

Comments
 (0)