dw.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. unified_strdate,
  5. url_or_none,
  6. )
  7. from ..compat import compat_urlparse
  8. class DWIE(InfoExtractor):
  9. IE_NAME = 'dw'
  10. _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+(?:av|e)-(?P<id>\d+)'
  11. _TESTS = [{
  12. # video
  13. 'url': 'http://www.dw.com/en/intelligent-light/av-19112290',
  14. 'md5': 'fb9dfd9520811d3ece80f04befd73428',
  15. 'info_dict': {
  16. 'id': '19112290',
  17. 'ext': 'mp4',
  18. 'title': 'Intelligent light',
  19. 'description': 'md5:90e00d5881719f2a6a5827cb74985af1',
  20. 'upload_date': '20160605',
  21. }
  22. }, {
  23. # audio
  24. 'url': 'http://www.dw.com/en/worldlink-my-business/av-19111941',
  25. 'md5': '2814c9a1321c3a51f8a7aeb067a360dd',
  26. 'info_dict': {
  27. 'id': '19111941',
  28. 'ext': 'mp3',
  29. 'title': 'WorldLink: My business',
  30. 'description': 'md5:bc9ca6e4e063361e21c920c53af12405',
  31. 'upload_date': '20160311',
  32. }
  33. }, {
  34. # DW documentaries, only last for one or two weeks
  35. 'url': 'http://www.dw.com/en/documentaries-welcome-to-the-90s-2016-05-21/e-19220158-9798',
  36. 'md5': '56b6214ef463bfb9a3b71aeb886f3cf1',
  37. 'info_dict': {
  38. 'id': '19274438',
  39. 'ext': 'mp4',
  40. 'title': 'Welcome to the 90s – Hip Hop',
  41. 'description': 'Welcome to the 90s - The Golden Decade of Hip Hop',
  42. 'upload_date': '20160521',
  43. },
  44. 'skip': 'Video removed',
  45. }]
  46. def _real_extract(self, url):
  47. media_id = self._match_id(url)
  48. webpage = self._download_webpage(url, media_id)
  49. hidden_inputs = self._hidden_inputs(webpage)
  50. title = hidden_inputs['media_title']
  51. media_id = hidden_inputs.get('media_id') or media_id
  52. direct_url = url_or_none(hidden_inputs.get('file_name'))
  53. if direct_url:
  54. formats = [{'url': hidden_inputs['file_name']}]
  55. else:
  56. formats = self._extract_smil_formats(
  57. 'http://www.dw.com/smil/v-%s' % media_id, media_id,
  58. transform_source=lambda s: s.replace(
  59. 'rtmp://tv-od.dw.de/flash/',
  60. 'http://tv-download.dw.de/dwtv_video/flv/'))
  61. upload_date = hidden_inputs.get('display_date')
  62. if not upload_date:
  63. upload_date = self._html_search_regex(
  64. r'<span[^>]+class="date">([0-9.]+)\s*\|', webpage,
  65. 'upload date', default=None)
  66. upload_date = unified_strdate(upload_date)
  67. return {
  68. 'id': media_id,
  69. 'title': title,
  70. 'description': self._og_search_description(webpage),
  71. 'thumbnail': hidden_inputs.get('preview_image'),
  72. 'duration': int_or_none(hidden_inputs.get('file_duration')),
  73. 'upload_date': upload_date,
  74. 'formats': formats,
  75. }
  76. class DWArticleIE(InfoExtractor):
  77. IE_NAME = 'dw:article'
  78. _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+a-(?P<id>\d+)'
  79. _TEST = {
  80. 'url': 'http://www.dw.com/en/no-hope-limited-options-for-refugees-in-idomeni/a-19111009',
  81. 'md5': '8ca657f9d068bbef74d6fc38b97fc869',
  82. 'info_dict': {
  83. 'id': '19105868',
  84. 'ext': 'mp4',
  85. 'title': 'The harsh life of refugees in Idomeni',
  86. 'description': 'md5:196015cc7e48ebf474db9399420043c7',
  87. 'upload_date': '20160310',
  88. }
  89. }
  90. def _real_extract(self, url):
  91. article_id = self._match_id(url)
  92. webpage = self._download_webpage(url, article_id)
  93. hidden_inputs = self._hidden_inputs(webpage)
  94. media_id = hidden_inputs['media_id']
  95. media_path = self._search_regex(r'href="([^"]+av-%s)"\s+class="overlayLink"' % media_id, webpage, 'media url')
  96. media_url = compat_urlparse.urljoin(url, media_path)
  97. return self.url_result(media_url, 'DW', media_id)