aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'youtube_dl/extractor/common.py')
-rw-r--r--youtube_dl/extractor/common.py54
1 files changed, 51 insertions, 3 deletions
diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py
index 9c30a1d33..f43a0a569 100644
--- a/youtube_dl/extractor/common.py
+++ b/youtube_dl/extractor/common.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import base64
+import datetime
import hashlib
import json
import netrc
@@ -15,11 +16,13 @@ from ..utils import (
compat_http_client,
compat_urllib_error,
compat_urllib_parse_urlparse,
+ compat_urlparse,
compat_str,
clean_html,
compiled_regex_type,
ExtractorError,
+ float_or_none,
int_or_none,
RegexNotFoundError,
sanitize_filename,
@@ -164,6 +167,14 @@ class InfoExtractor(object):
return cls._VALID_URL_RE.match(url) is not None
@classmethod
+ def _match_id(cls, url):
+ if '_VALID_URL_RE' not in cls.__dict__:
+ cls._VALID_URL_RE = re.compile(cls._VALID_URL)
+ m = cls._VALID_URL_RE.match(url)
+ assert m
+ return m.group('id')
+
+ @classmethod
def working(cls):
"""Getter method for _WORKING."""
return cls._WORKING
@@ -640,7 +651,9 @@ class InfoExtractor(object):
return formats
- def _extract_m3u8_formats(self, m3u8_url, video_id, ext=None):
+ def _extract_m3u8_formats(self, m3u8_url, video_id, ext=None,
+ entry_protocol='m3u8', preference=None):
+
formats = [{
'format_id': 'm3u8-meta',
'url': m3u8_url,
@@ -651,6 +664,11 @@ class InfoExtractor(object):
'format_note': 'Quality selection URL',
}]
+ format_url = lambda u: (
+ u
+ if re.match(r'^https?://', u)
+ else compat_urlparse.urljoin(m3u8_url, u))
+
m3u8_doc = self._download_webpage(m3u8_url, video_id)
last_info = None
kv_rex = re.compile(
@@ -667,15 +685,17 @@ class InfoExtractor(object):
continue
else:
if last_info is None:
- formats.append({'url': line})
+ formats.append({'url': format_url(line)})
continue
tbr = int_or_none(last_info.get('BANDWIDTH'), scale=1000)
f = {
'format_id': 'm3u8-%d' % (tbr if tbr else len(formats)),
- 'url': line.strip(),
+ 'url': format_url(line.strip()),
'tbr': tbr,
'ext': ext,
+ 'protocol': entry_protocol,
+ 'preference': preference,
}
codecs = last_info.get('CODECS')
if codecs:
@@ -695,6 +715,34 @@ class InfoExtractor(object):
self._sort_formats(formats)
return formats
+ def _live_title(self, name):
+ """ Generate the title for a live video """
+ now = datetime.datetime.now()
+ now_str = now.strftime("%Y-%m-%d %H:%M")
+ return name + ' ' + now_str
+
+ def _int(self, v, name, fatal=False, **kwargs):
+ res = int_or_none(v, **kwargs)
+ if 'get_attr' in kwargs:
+ print(getattr(v, kwargs['get_attr']))
+ if res is None:
+ msg = 'Failed to extract %s: Could not parse value %r' % (name, v)
+ if fatal:
+ raise ExtractorError(msg)
+ else:
+ self._downloader.report_warning(msg)
+ return res
+
+ def _float(self, v, name, fatal=False, **kwargs):
+ res = float_or_none(v, **kwargs)
+ if res is None:
+ msg = 'Failed to extract %s: Could not parse value %r' % (name, v)
+ if fatal:
+ raise ExtractorError(msg)
+ else:
+ self._downloader.report_warning(msg)
+ return res
+
class SearchInfoExtractor(InfoExtractor):
"""