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.

92 lines
3.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import random
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. ExtractorError,
  8. xpath_text,
  9. )
  10. class Laola1TvIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?laola1\.tv/(?P<lang>[a-z]+)-(?P<portal>[a-z]+)/.*?/(?P<id>[0-9]+)\.html'
  12. _TEST = {
  13. 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie/227883.html',
  14. 'info_dict': {
  15. 'id': '227883',
  16. 'ext': 'mp4',
  17. 'title': 'Straubing Tigers - Kölner Haie',
  18. 'categories': ['Eishockey'],
  19. 'is_live': False,
  20. },
  21. 'params': {
  22. 'skip_download': True,
  23. }
  24. }
  25. _BROKEN = True # Not really - extractor works fine, but f4m downloader does not support live streams yet.
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. video_id = mobj.group('id')
  29. lang = mobj.group('lang')
  30. portal = mobj.group('portal')
  31. webpage = self._download_webpage(url, video_id)
  32. iframe_url = self._search_regex(
  33. r'<iframe[^>]*?class="main_tv_player"[^>]*?src="([^"]+)"',
  34. webpage, 'iframe URL')
  35. iframe = self._download_webpage(
  36. iframe_url, video_id, note='Downloading iframe')
  37. flashvars_m = re.findall(
  38. r'flashvars\.([_a-zA-Z0-9]+)\s*=\s*"([^"]*)";', iframe)
  39. flashvars = dict((m[0], m[1]) for m in flashvars_m)
  40. partner_id = self._search_regex(
  41. r'partnerid\s*:\s*"([^"]+)"', iframe, 'partner id')
  42. xml_url = ('http://www.laola1.tv/server/hd_video.php?' +
  43. 'play=%s&partner=%s&portal=%s&v5ident=&lang=%s' % (
  44. video_id, partner_id, portal, lang))
  45. hd_doc = self._download_xml(xml_url, video_id)
  46. title = xpath_text(hd_doc, './/video/title', fatal=True)
  47. flash_url = xpath_text(hd_doc, './/video/url', fatal=True)
  48. uploader = xpath_text(hd_doc, './/video/meta_organistation')
  49. is_live = xpath_text(hd_doc, './/video/islive') == 'true'
  50. if is_live:
  51. raise ExtractorError(
  52. 'Live streams are not supported by the f4m downloader.')
  53. categories = xpath_text(hd_doc, './/video/meta_sports')
  54. if categories:
  55. categories = categories.split(',')
  56. ident = random.randint(10000000, 99999999)
  57. token_url = '%s&ident=%s&klub=0&unikey=0&timestamp=%s&auth=%s' % (
  58. flash_url, ident, flashvars['timestamp'], flashvars['auth'])
  59. token_doc = self._download_xml(
  60. token_url, video_id, note='Downloading token')
  61. token_attrib = token_doc.find('.//token').attrib
  62. if token_attrib.get('auth') in ('blocked', 'restricted'):
  63. raise ExtractorError(
  64. 'Token error: %s' % token_attrib.get('comment'), expected=True)
  65. video_url = '%s?hdnea=%s&hdcore=3.2.0' % (
  66. token_attrib['url'], token_attrib['auth'])
  67. return {
  68. 'id': video_id,
  69. 'is_live': is_live,
  70. 'title': title,
  71. 'url': video_url,
  72. 'uploader': uploader,
  73. 'categories': categories,
  74. 'ext': 'mp4',
  75. }