Open AliAkhtari78 opened 4 years ago
ok apperantly my initial instructions were wrong; when you change user agent and other request headers the response changes so it corrupts the parsing.
Instead you only need to pass cookies like this:
YouTubeItem('https://www.youtube.com/embed/B48hwisZvEI', request_headers={
'cookie':
I will update the instructions on medium post and here. can you retry like this? I was able to get title correct when i did this.
I can't pass the parameter like that, it says: Value expression expected
sorry i should have written cleaner(actually i did but github removes the things i have written between "less than signs" anyways;). you need to put your cookie to the value section:
YouTubeItem('https://www.youtube.com/embed/B48hwisZvEI', request_headers={ 'cookie': 'here should be your cookie' })
let me know if it works; happy to help if it doesnt.
Okay, but I have multiple value for my cookie , which one should I pass? Can you look at the image below and tell me? List Of YouTube Cookie
i dont know which one works when I get my cookies from chrome I take it like a string and pass all. something like this(below values are just dummy values as a sample);
YouTubeItem('https://www.youtube.com/embed/B48hwisZvEI', request_headers={
'cookie': "HSID=SDFJSDFJSD; SSID=sdf@31j2kjfk; APISID=!@JLFEJF@L!@/EJ@!JE!@;......"
})
Still not working. But views, ratings, and author are shown completely. only title returns "YouTube".
is it possible to share the video url you are trying to download? so i can try to reproduce.
it's happening for all the videos
Can you share how you are creating the YouTubeItem(please delete the values of your cookies etc while sharing; they are sensitive). Because when I call like that there is no problem:
from YouPy import YouTubeItem
item = YouTubeItem('https://www.youtube.com/watch?v=B48hwisZvEI&t=21s', request_headers={
'cookie': 'my cookies'
})
print(item.title)
> RESISTANCE - Official Trailer I HD I IFC Films
maybe you are passing another request header too?
I will add some protective measures to the code today to prevent passing extras just to be sure.
yt = YouTubeItem(url=url, request_headers=header)
temp = {'title': yt.title, 'cover': yt.thumbnail_url, 'author': yt.author, 'views': yt.views, 'rating': yt.rating}
everything works fine except yt.title
which return YouTube
for me.
and here's the header:
header = {'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
'X-Client-Data': '',
'X-Goog-AuthUser': '0',
'X-Goog-Visitor-Id': '',
'x-origin': 'https://www.youtube.com',
'X-YouTube-Client-Name': '1',
'X-YouTube-Client-Version': '2.20200406.06.02',
'X-YouTube-Device': 'cbr=Chrome&cbrver=80.0.3987.163&ceng=WebKit&cengver=537.36&cos=Windows&cosver=10.0',
'X-Youtube-Identity-Token': '',
'cookie': cookies
}
Yes that is what I mean. You are sending too many extras with headers. You need to send only the cookie so your code should be:
header = {
'cookie': cookies
}
yt = YouTubeItem(url=url, request_headers=header)
temp = {'title': yt.title, 'cover': yt.thumbnail_url, 'author': yt.author, 'views': yt.views, 'rating': yt.rating}
otherwise based on the things you are sending on headers the response is changing and how PyTube and YouPy is doing is a simple string partsing. any change on response is affecting the retrieval of the title.
When I try to get the title of the video, it always return
YouTube
. here my code:yt = YouTubeItem(url=url, request_headers=header)
print(yt.title)