Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Subtitles for YouTube videos #304

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pafy/backend_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _get_lst(key, default="unknown", dic=allinfo):
self._keywords = _get_lst('keywords', "").split(',')
self._bigthumb = _get_lst('iurlsd', "")
self._bigthumbhd = _get_lst('iurlsdmaxres', "")
self._subtitles = {} # no subtitles with the internal backend
self.ciphertag = _get_lst("use_cipher_signature") == "True"
self.sm = _extract_smap(g.UEFSM, allinfo, True)
self.asm = _extract_smap(g.AF, allinfo, True)
Expand Down
8 changes: 8 additions & 0 deletions pafy/backend_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ def dislikes(self):

return self._dislikes

@property
def subtitles(self):
""" The subtitles of the video. Returns dict. """
if not self._subtitles:
self._fetch_basic()

return self._subtitles

@property
def mix(self):
""" The playlist for the related YouTube mix. Returns a Playlist object. """
Expand Down
1 change: 1 addition & 0 deletions pafy/backend_youtube_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def _fetch_basic(self):
self._username = self._ydl_info['uploader_id']
self._category = self._ydl_info['categories'][0] if self._ydl_info['categories'] else ''
self._bestthumb = self._ydl_info['thumbnails'][0]['url']
self._subtitles = self._ydl_info.get('subtitles', {})
self._bigthumb = g.urls['bigthumb'] % self.videoid
self._bigthumbhd = g.urls['bigthumbhd'] % self.videoid
self.expiry = time.time() + g.lifespan
Expand Down
3 changes: 2 additions & 1 deletion pafy/g.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
opener = build_opener()
opener.addheaders = [('User-Agent', user_agent)]
cache = {}
def_ydl_opts = {'quiet': True, 'prefer_insecure': False, 'no_warnings': True}
def_ydl_opts = {'quiet': True, 'prefer_insecure': False,
'no_warnings': True, "writesubtitles": True}

# The following are specific to the internal backend
UEFSM = 'url_encoded_fmt_stream_map'
Expand Down