Constructor
class YouTube(link, cookies)
class YouTube(link, cookies)
- Initializes the YouTube object with the provided video link.
Parameters:
Properties
videoId
str
videoId
str
- Returns the unique identifier of the video.
title
str
title
str
- Returns the title of the video.
author
str
author
str
- Returns the name of the channel that uploaded the video.
description
str
description
str
- Returns the description of the video.
duration
int
duration
int
- Returns the duration of the video in seconds.
views
int
views
int
- Returns the view count of the video.
likes
int
likes
int
- Returns the like count of the video.
comments
MyTube.CommentsManager
comments
MyTube.CommentsManager
- Returns the comments manager. To get comments count call:
len(yt.comments)
type
str
type
str
- Returns the type of content of the YouTube video. (
"video" or "music"
)
upload_date
datetime
upload_date
datetime
- Returns the upload date of the video.
channel
MyTube.Channel
channel
MyTube.Channel
- Returns the channel information that uploaded the video.
thumbnail
MyTube.Thumbnail
thumbnail
MyTube.Thumbnail
- Returns the thumbnail of the video.
subtitles
MyTube.SubtitlesManager
subtitles
MyTube.SubtitlesManager
- Returns the subtitles manager for the video.
streams
MyTube.StreamsManager
streams
MyTube.StreamsManager
- Returns the available video and audio streams for download.
Methods
download(video, audio) ->
MyTube.Downloader
download(video, audio) ->
MyTube.Downloader
- Initializes the Downloader based on the provided video or audio stream parameters.
Parameters:
video | MyTube.Stream | Optional |
audio | MyTube.Stream | Optional |
Example
import MyTube
yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
print(yt.title) # Title of the video
print(yt.author) # Author (channel name)
print(yt.views) # Number of views
print(yt.duration) # Video duration in seconds
>>> Rick Astley - Never Gonna Give You Up (Official Music Video)
>>> Rick Astley
>>> 1587866581
>>> 212
Cookies example
[{"domain": ".youtube.com", "expiry": 1700000000, "httpOnly": true, "name": "__Secure-1234", "path": "/", "sameSite": "Lax", "secure": true, "value": "ABCdef123456789"}, ...]
To get the cookies, you can use the browser extension to export cookies (Chrome or Firefox).
We are not developing this extensions, so install them at your own risk! Be careful what you install.
import json
import MyTube
with open("my_cookies.json", 'r') as f:
cookies = json.loads(f.read())
link = "https://youtube.com/watch?v=HtVdAasjOgU"
yt = MyTube.YouTube(link, cookies=cookies)
print(yt.title)