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.

86 lines
3.0 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. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. lang = mobj.group('lang')
  29. portal = mobj.group('portal')
  30. webpage = self._download_webpage(url, video_id)
  31. iframe_url = self._search_regex(
  32. r'<iframe[^>]*?class="main_tv_player"[^>]*?src="([^"]+)"',
  33. webpage, 'iframe URL')
  34. iframe = self._download_webpage(
  35. iframe_url, video_id, note='Downloading iframe')
  36. flashvars_m = re.findall(
  37. r'flashvars\.([_a-zA-Z0-9]+)\s*=\s*"([^"]*)";', iframe)
  38. flashvars = dict((m[0], m[1]) for m in flashvars_m)
  39. partner_id = self._search_regex(
  40. r'partnerid\s*:\s*"([^"]+)"', iframe, 'partner id')
  41. xml_url = ('http://www.laola1.tv/server/hd_video.php?' +
  42. 'play=%s&partner=%s&portal=%s&v5ident=&lang=%s' % (
  43. video_id, partner_id, portal, lang))
  44. hd_doc = self._download_xml(xml_url, video_id)
  45. title = xpath_text(hd_doc, './/video/title', fatal=True)
  46. flash_url = xpath_text(hd_doc, './/video/url', fatal=True)
  47. uploader = xpath_text(hd_doc, './/video/meta_organistation')
  48. is_live = xpath_text(hd_doc, './/video/islive') == 'true'
  49. categories = xpath_text(hd_doc, './/video/meta_sports')
  50. if categories:
  51. categories = categories.split(',')
  52. ident = random.randint(10000000, 99999999)
  53. token_url = '%s&ident=%s&klub=0&unikey=0&timestamp=%s&auth=%s' % (
  54. flash_url, ident, flashvars['timestamp'], flashvars['auth'])
  55. token_doc = self._download_xml(
  56. token_url, video_id, note='Downloading token')
  57. token_attrib = token_doc.find('.//token').attrib
  58. if token_attrib.get('auth') in ('blocked', 'restricted'):
  59. raise ExtractorError(
  60. 'Token error: %s' % token_attrib.get('comment'), expected=True)
  61. video_url = '%s?hdnea=%s&hdcore=3.2.0' % (
  62. token_attrib['url'], token_attrib['auth'])
  63. return {
  64. 'id': video_id,
  65. 'is_live': is_live,
  66. 'title': title,
  67. 'url': video_url,
  68. 'uploader': uploader,
  69. 'categories': categories,
  70. 'ext': 'mp4',
  71. }