airmozilla.py 2.6 KB

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