Skip to content

Commit

Permalink
Merge branch 'handle_reject_consent_cookie'
Browse files Browse the repository at this point in the history
  • Loading branch information
NotJoeMartinez committed May 21, 2023
2 parents 859bfee + 013292c commit 050981c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions yt_fts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def list():
@click.option('--channel-id', default=None, help='Optional channel id to override the one from the url')
@click.option('--language', default="en", help='Language of the subtitles to download')
def download(channel_url, channel_id, language):
handle_reject_consent_cookie(channel_url)
if channel_id is None:
channel_id = get_channel_id(channel_url)
if channel_id:
Expand Down Expand Up @@ -75,6 +76,22 @@ def delete(channel_id):



def handle_reject_consent_cookie(channel_url):
r = s.get(channel_url)
if "https://consent.youtube.com" in r.url:
m = re.search(r"<input type=\"hidden\" name=\"bl\" value=\"([^\"]*)\"", r.text)
if m:
data = {
"gl":"DE",
"pc":"yt",
"continue":channel_url,
"x":"6",
"bl":m.group(1),
"hl":"de",
"set_eom":"true"
}
s.post("https://consent.youtube.com/save", data=data)

def download_channel(channel_id, language):
print("Downloading channel")
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down Expand Up @@ -160,7 +177,7 @@ def parse_vtt(file_path):


def get_vid_title(vid_url):
res = requests.get(vid_url)
res = s.get(vid_url)
if res.status_code == 200:
html = res.text
soup = BeautifulSoup(html, 'html.parser')
Expand All @@ -172,7 +189,7 @@ def get_vid_title(vid_url):


def get_channel_id(url):
res = requests.get(url)
res = s.get(url)
if res.status_code == 200:
html = res.text
channel_id = re.search('channelId":"(.{24})"', html).group(1)
Expand All @@ -183,7 +200,7 @@ def get_channel_id(url):

def get_channel_name(channel_id):

res = requests.get(f"https://www.youtube.com/channel/{channel_id}/videos")
res = s.get(f"https://www.youtube.com/channel/{channel_id}/videos")

if res.status_code == 200:

Expand Down Expand Up @@ -272,4 +289,5 @@ def time_to_secs(time_str):


if __name__ == '__main__':
s = requests.session()
cli()

0 comments on commit 050981c

Please sign in to comment.