logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

faz.py (3586B)


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