i have problems with pytube and telegram bot

155 Views Asked by At

I have a telegram bot that downloads videos from youtube. i have 2 problems.

  1. I used the pytube library to create the bot. shows age limit error while downloading some videos. How to avoid this. I tried this answers but it didn't work.
  2. Normal telegram bots cannot send videos larger than 50 mb. For this, you need to create a telegram bot local server and run the bot on this local server. Is there an easier way?
# simple code 
# exeption: age restricted
from pytube import YouTube

url='https://www.youtube.com/watch?v=m9ezpAUvMC8&pp=ygUPbG92ZSB5b3VyIHZvaWNl'

yt=YouTube(url,use_oauth=True,allow_oauth_cache=True)
print(yt.age_restricted)

print(yt.streams)
1

There are 1 best solutions below

0
naser On

Go to your site-packages: C:\Users\myname\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytube\innertube.py line 223 change client='ANDROID_MUSIC' to client='ANDROID'

def __init__(self, client='ANDROID', use_oauth=False, allow_cache=True):

from pytube import YouTube
url='https://www.youtube.com/watch?v=m9ezpAUvMC8&pp=ygUPbG92ZSB5b3VyIHZvaWNl'

yt=YouTube(url,use_oauth=True,allow_oauth_cache=True)
print(yt.age_restricted)
stream = yt.streams.get_highest_resolution()
stream.download()