airmozilla.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import parse_iso8601
  6. class AirMozillaIE(InfoExtractor):
  7. _VALID_URL = r'https?://air\.mozilla\.org/(?P<id>[0-9a-z-]+)/?'
  8. _TEST = {
  9. 'url': 'https://air.mozilla.org/privacy-lab-a-meetup-for-privacy-minded-people-in-san-francisco/',
  10. 'md5': '2e3e7486ba5d180e829d453875b9b8bf',
  11. 'info_dict': {
  12. 'id': '6x4q2w',
  13. 'ext': 'mp4',
  14. 'title': 'Privacy Lab - a meetup for privacy minded people in San Francisco',
  15. 'thumbnail': 're:https://\w+\.cloudfront\.net/6x4q2w/poster\.jpg\?t=\d+',
  16. 'description': 'Brings together privacy professionals and others interested in privacy at for-profits, non-profits, and NGOs in an effort to contribute to the state of the ecosystem...',
  17. 'timestamp': 1422487800,
  18. 'upload_date': '20150128',
  19. 'location': 'SFO Commons',
  20. 'duration': 3780,
  21. 'view_count': int,
  22. 'categories': ['Main'],
  23. }
  24. }
  25. _QUALITY_MAP = {
  26. '360p': 0,
  27. '576p': 1,
  28. '640p': 2,
  29. '720p': 3,
  30. }
  31. def _real_extract(self, url):
  32. display_id = self._match_id(url)
  33. webpage = self._download_webpage(url, display_id)
  34. video_id = self._html_search_regex(r'//vid.ly/(.*?)/embed', webpage, 'id')
  35. embed_script = self._download_webpage('https://vid.ly/{0}/embed'.format(video_id), video_id)
  36. jwconfig = self._search_regex(r'\svar jwconfig = (\{.*?\});\s', embed_script, 'metadata')
  37. metadata = self._parse_json(jwconfig, video_id)
  38. formats = []
  39. for source in metadata['playlist'][0]['sources']:
  40. fmt = {
  41. 'url': source['file'],
  42. 'ext': source['type'],
  43. 'format_id': self._search_regex(r'&format=(.*)$', source['file'], 'video format'),
  44. 'resolution': source['label'],
  45. 'quality': self._QUALITY_MAP.get(source['label'], -1),
  46. }
  47. formats.append(fmt)
  48. self._sort_formats(formats)
  49. duration_match = re.search(r'Duration:(?: (?P<H>\d+) hours?)?(?: (?P<M>\d+) minutes?)?', webpage)
  50. return {
  51. 'id': video_id,
  52. 'title': self._og_search_title(webpage),
  53. 'formats': formats,
  54. 'url': self._og_search_url(webpage),
  55. 'display_id': display_id,
  56. 'thumbnail': metadata['playlist'][0]['image'],
  57. 'description': self._og_search_description(webpage),
  58. 'timestamp': parse_iso8601(self._html_search_regex(r'<time datetime="(.*?)"', webpage, 'timestamp')),
  59. 'location': self._html_search_regex(r'Location: (.*)', webpage, 'location', default=None),
  60. 'duration': int(duration_match.groupdict()['H'] or 0) * 3600 + int(duration_match.groupdict()['M'] or 0) * 60,
  61. 'view_count': int(self._html_search_regex(r'Views since archived: ([0-9]+)', webpage, 'view count')),
  62. 'categories': re.findall(r'<a href=".*?" class="channel">(.*?)</a>', webpage),
  63. }