Client class
YoutubeToBibtexClient
- class youtubetobibtex.client.YoutubetobibtexClient(apikey)
Main class for interacting with YouTube’s api.
- _get_video_info(video_id)
Get information form the id.
- Args:
video_id (string): id of the video
- Raises:
VideoNotFound: if the video wit the given id does not exist ChannelNotFound: if no channel is associated with the id with got from the API
- Returns:
(string, string, datetime): title, author and date of the video.
- check()
Check if the client is valid.
- Returns:
bool: True if the client is valid, False otherwise.
- get_bibtex(video_id)
Get the bibtex entry form the video_id
- Args:
video_id (string): id of the video
- Returns:
string: bibtex entry
- get_video_id(url)
Return the video id from url.
Several URL schemes are supported.
- Args:
url (string): url of the video
- Raises:
UrlNotSupported: if the id cannot be extracted from the url
- Returns:
string: id of the video
Exceptions
- exception youtubetobibtex.errors.VideoNotFound
Exception raised when not video is found with id
- exception youtubetobibtex.errors.ChannelNotFound
Exception raised when not channel is found with id
- exception youtubetobibtex.errors.UrlNotSupported
Exception raised when the id cannot be extracted from the url.
Usage example
In [1]: from youtubetobibtex import YoutubetobibtexClient
In [2]: client = YoutubetobibtexClient("secret")
In [3]: client.check() # check if the client is correctly connected to google api
Out[3]: True
In [4]: video_id = client.get_video_id("https://www.youtube.com/watch\?v=v=LkH2r-sNjQs") # get id from url. several schemes of url are supported
In [5]: video_id
Out[5]: 'LkH2r-sNjQs'
In [6]: client.get_bibtex(video_id) # get bibtex
Out[6]: '\n@online{video:tomscott2019,\n title = {Why Electronic Voting Is Still A Bad Idea},\n date = {2019},\n organization = {YouTube},\n author = {Tom Scott},\n url = {https://youtube.com/watch?v=LkH2r-sNjQs},\n}\n