dw.py 4.0 KB

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