Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update youtube channel URL #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Update youtube channel URL now identified by username
  • Loading branch information
miguelgr committed Mar 29, 2023
commit eafadcdf8fb13600f93603970a692616579c2cee
13 changes: 8 additions & 5 deletions scrapetube/scrapetube.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def get_channel(
``"streams"``: Streams
"""

sort_by_map = {"newest": "dd", "oldest": "da", "popular": "p"}
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}",
url=channel_url or f"https://www.youtube.com/{channel_id}",
content_type=content_type,
sort_by=sort_by_map[sort_by],
)
Expand Down Expand Up @@ -160,6 +160,8 @@ def get_videos(
while True:
if is_first:
html = get_initial_data(session, url)
if not html:
break
client = json.loads(
get_json_from_html(html, "INNERTUBE_CONTEXT", 2, '"}},') + '"}}'
)["client"]
Expand Down Expand Up @@ -196,9 +198,10 @@ def get_videos(
def get_initial_data(session: requests.Session, url: str) -> str:
session.cookies.set("CONSENT", "YES+cb", domain=".youtube.com")
response = session.get(url)

html = response.text
return html
if response.ok:
html = response.text
return html
return ""


def get_ajax_data(
Expand Down