JuanBindez / pytubefix

Python3 library for downloading YouTube Videos.
http://pytubefix.rtfd.io/
MIT License
654 stars 91 forks source link

Not retrieving time for publish_date #29

Closed NannoSilver closed 7 months ago

NannoSilver commented 10 months ago

The publish_date is returning day, month and year only. Not returning time.

Code to test:

from pytubefix import YouTube

video_url = 'https://www.youtube.com/watch?v=AW2LELZZNgA'

yt = YouTube (video_url)

publish_date = yt.publish_date
print(publish_date)

Expected result: 2023-12-26T13:30:09-08:00

Actual result: 2023-12-26 00:00:00

Published date seems to be available at the video's HTML page under a meta tag, as in this example: Video: https://www.youtube.com/watch?v=AW2LELZZNgA <meta itemprop="datePublished" content="2023-12-26T13:30:09-08:00">

It also will be useful to have the option to have the output date in ISO format, that includes time-zone. The date in the meta tag already is in ISO format.

NannoSilver commented 10 months ago

This issue is also present at pytube 15

NannoSilver commented 10 months ago

I worked-out a solution with beautifulsoup to retrieve publish_date that can be used while there is no permanent fix:

import requests
from bs4 import BeautifulSoup

video_url = 'https://www.youtube.com/watch?v=4CPR6UK5svs'
response = requests.get(video_url)
soup = BeautifulSoup(response.text, 'html.parser')
publish_date = soup.find('meta', itemprop='datePublished')['content']

print(publish_date)