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
2.6 KiB

9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urlparse
  6. from ..utils import (
  7. int_or_none,
  8. parse_filesize,
  9. unified_strdate,
  10. )
  11. class EsriVideoIE(InfoExtractor):
  12. _VALID_URL = r'https?://video\.esri\.com/watch/(?P<id>[0-9]+)'
  13. _TEST = {
  14. 'url': 'https://video.esri.com/watch/1124/arcgis-online-_dash_-developing-applications',
  15. 'md5': 'd4aaf1408b221f1b38227a9bbaeb95bc',
  16. 'info_dict': {
  17. 'id': '1124',
  18. 'ext': 'mp4',
  19. 'title': 'ArcGIS Online - Developing Applications',
  20. 'description': 'Jeremy Bartley demonstrates how to develop applications with ArcGIS Online.',
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. 'duration': 185,
  23. 'upload_date': '20120419',
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. formats = []
  30. for width, height, content in re.findall(
  31. r'(?s)<li><strong>(\d+)x(\d+):</strong>(.+?)</li>', webpage):
  32. for video_url, ext, filesize in re.findall(
  33. r'<a[^>]+href="([^"]+)">([^<]+)&nbsp;\(([^<]+)\)</a>', content):
  34. formats.append({
  35. 'url': compat_urlparse.urljoin(url, video_url),
  36. 'ext': ext.lower(),
  37. 'format_id': '%s-%s' % (ext.lower(), height),
  38. 'width': int(width),
  39. 'height': int(height),
  40. 'filesize_approx': parse_filesize(filesize),
  41. })
  42. self._sort_formats(formats)
  43. title = self._html_search_meta('title', webpage, 'title')
  44. description = self._html_search_meta(
  45. 'description', webpage, 'description', fatal=False)
  46. thumbnail = self._html_search_meta('thumbnail', webpage, 'thumbnail', fatal=False)
  47. if thumbnail:
  48. thumbnail = re.sub(r'_[st]\.jpg$', '_x.jpg', thumbnail)
  49. duration = int_or_none(self._search_regex(
  50. [r'var\s+videoSeconds\s*=\s*(\d+)', r"'duration'\s*:\s*(\d+)"],
  51. webpage, 'duration', fatal=False))
  52. upload_date = unified_strdate(self._html_search_meta(
  53. 'last-modified', webpage, 'upload date', fatal=False))
  54. return {
  55. 'id': video_id,
  56. 'title': title,
  57. 'description': description,
  58. 'thumbnail': thumbnail,
  59. 'duration': duration,
  60. 'upload_date': upload_date,
  61. 'formats': formats
  62. }