faz.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import re
  2. from .common import InfoExtractor
  3. from ..compat import compat_etree_fromstring
  4. from ..utils import (
  5. int_or_none,
  6. xpath_element,
  7. xpath_text,
  8. )
  9. class FazIE(InfoExtractor):
  10. IE_NAME = 'faz.net'
  11. _VALID_URL = r'https?://(?:www\.)?faz\.net/(?:[^/]+/)*.*?-(?P<id>\d+)\.html'
  12. _TESTS = [{
  13. 'url': 'http://www.faz.net/multimedia/videos/stockholm-chemie-nobelpreis-fuer-drei-amerikanische-forscher-12610585.html',
  14. 'info_dict': {
  15. 'id': '12610585',
  16. 'ext': 'mp4',
  17. 'title': 'Stockholm: Chemie-Nobelpreis für drei amerikanische Forscher',
  18. 'description': 'md5:1453fbf9a0d041d985a47306192ea253',
  19. },
  20. }, {
  21. 'url': 'http://www.faz.net/aktuell/politik/berlin-gabriel-besteht-zerreissprobe-ueber-datenspeicherung-13659345.html',
  22. 'only_matching': True,
  23. }, {
  24. 'url': 'http://www.faz.net/berlin-gabriel-besteht-zerreissprobe-ueber-datenspeicherung-13659345.html',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'http://www.faz.net/-13659345.html',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'http://www.faz.net/aktuell/politik/-13659345.html',
  31. 'only_matching': True,
  32. }, {
  33. 'url': 'http://www.faz.net/foobarblafasel-13659345.html',
  34. 'only_matching': True,
  35. }]
  36. def _real_extract(self, url):
  37. video_id = self._match_id(url)
  38. webpage = self._download_webpage(url, video_id)
  39. description = self._og_search_description(webpage)
  40. media = self._html_search_regex(
  41. r"data-videojs-media='([^']+)",
  42. webpage, 'media')
  43. if media == 'extern':
  44. perform_url = self._search_regex(
  45. r"<iframe[^>]+?src='((?:http:)?//player\.performgroup\.com/eplayer/eplayer\.html#/?[0-9a-f]{26}\.[0-9a-z]{26})",
  46. webpage, 'perform url')
  47. return self.url_result(perform_url)
  48. config = compat_etree_fromstring(media)
  49. encodings = xpath_element(config, 'ENCODINGS', 'encodings', True)
  50. formats = []
  51. for pref, code in enumerate(['LOW', 'HIGH', 'HQ']):
  52. encoding = xpath_element(encodings, code)
  53. if encoding is not None:
  54. encoding_url = xpath_text(encoding, 'FILENAME')
  55. if encoding_url:
  56. tbr = xpath_text(encoding, 'AVERAGEBITRATE', 1000)
  57. if tbr:
  58. tbr = int_or_none(tbr.replace(',', '.'))
  59. f = {
  60. 'url': encoding_url,
  61. 'format_id': code.lower(),
  62. 'quality': pref,
  63. 'tbr': tbr,
  64. 'vcodec': xpath_text(encoding, 'CODEC'),
  65. }
  66. mobj = re.search(r'(\d+)x(\d+)_(\d+)\.mp4', encoding_url)
  67. if mobj:
  68. f.update({
  69. 'width': int(mobj.group(1)),
  70. 'height': int(mobj.group(2)),
  71. 'tbr': tbr or int(mobj.group(3)),
  72. })
  73. formats.append(f)
  74. return {
  75. 'id': video_id,
  76. 'title': self._og_search_title(webpage),
  77. 'formats': formats,
  78. 'description': description.strip() if description else None,
  79. 'thumbnail': xpath_text(config, 'STILL/STILL_BIG'),
  80. 'duration': int_or_none(xpath_text(config, 'DURATION')),
  81. }