You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
3.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_duration,
  8. parse_iso8601,
  9. )
  10. class AirMozillaIE(InfoExtractor):
  11. _VALID_URL = r'https?://air\.mozilla\.org/(?P<id>[0-9a-z-]+)/?'
  12. _TEST = {
  13. 'url': 'https://air.mozilla.org/privacy-lab-a-meetup-for-privacy-minded-people-in-san-francisco/',
  14. 'md5': '2e3e7486ba5d180e829d453875b9b8bf',
  15. 'info_dict': {
  16. 'id': '6x4q2w',
  17. 'ext': 'mp4',
  18. 'title': 'Privacy Lab - a meetup for privacy minded people in San Francisco',
  19. 'thumbnail': 're:https?://vid\.ly/(?P<id>[0-9a-z-]+)/poster',
  20. '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...',
  21. 'timestamp': 1422487800,
  22. 'upload_date': '20150128',
  23. 'location': 'SFO Commons',
  24. 'duration': 3780,
  25. 'view_count': int,
  26. 'categories': ['Main', 'Privacy'],
  27. }
  28. }
  29. def _real_extract(self, url):
  30. display_id = self._match_id(url)
  31. webpage = self._download_webpage(url, display_id)
  32. video_id = self._html_search_regex(r'//vid.ly/(.*?)/embed', webpage, 'id')
  33. embed_script = self._download_webpage('https://vid.ly/{0}/embed'.format(video_id), video_id)
  34. jwconfig = self._search_regex(r'\svar jwconfig = (\{.*?\});\s', embed_script, 'metadata')
  35. metadata = self._parse_json(jwconfig, video_id)
  36. formats = [{
  37. 'url': source['file'],
  38. 'ext': source['type'],
  39. 'format_id': self._search_regex(r'&format=(.*)$', source['file'], 'video format'),
  40. 'format': source['label'],
  41. 'height': int(source['label'].rstrip('p')),
  42. } for source in metadata['playlist'][0]['sources']]
  43. self._sort_formats(formats)
  44. view_count = int_or_none(self._html_search_regex(
  45. r'Views since archived: ([0-9]+)',
  46. webpage, 'view count', fatal=False))
  47. timestamp = parse_iso8601(self._html_search_regex(
  48. r'<time datetime="(.*?)"', webpage, 'timestamp', fatal=False))
  49. duration = parse_duration(self._search_regex(
  50. r'Duration:\s*(\d+\s*hours?\s*\d+\s*minutes?)',
  51. webpage, 'duration', fatal=False))
  52. return {
  53. 'id': video_id,
  54. 'title': self._og_search_title(webpage),
  55. 'formats': formats,
  56. 'url': self._og_search_url(webpage),
  57. 'display_id': display_id,
  58. 'thumbnail': metadata['playlist'][0].get('image'),
  59. 'description': self._og_search_description(webpage),
  60. 'timestamp': timestamp,
  61. 'location': self._html_search_regex(r'Location: (.*)', webpage, 'location', default=None),
  62. 'duration': duration,
  63. 'view_count': view_count,
  64. 'categories': re.findall(r'<a href=".*?" class="channel">(.*?)</a>', webpage),
  65. }