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.

85 lines
2.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. parse_iso8601,
  8. qualities,
  9. )
  10. class TVPlayIE(InfoExtractor):
  11. _VALID_URL = r'http://(?:www\.)?tvplay\.lv/parraides/[^/]+/(?P<id>\d+)'
  12. _TESTS = [
  13. {
  14. 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true',
  15. 'info_dict': {
  16. 'id': '418113',
  17. 'ext': 'flv',
  18. 'title': 'Kādi ir īri? - Viņas melo labāk',
  19. 'description': 'Baiba apsmej īrus, kādi tie ir un ko viņi dara.',
  20. 'duration': 25,
  21. 'timestamp': 1406097056,
  22. 'upload_date': '20140723',
  23. },
  24. 'params': {
  25. # rtmp download
  26. 'skip_download': True,
  27. },
  28. },
  29. ]
  30. def _real_extract(self, url):
  31. mobj = re.match(self._VALID_URL, url)
  32. video_id = mobj.group('id')
  33. video = self._download_json(
  34. 'http://playapi.mtgx.tv/v1/videos/%s' % video_id, video_id, 'Downloading video JSON')
  35. if video['is_geo_blocked']:
  36. raise ExtractorError(
  37. 'This content is not available in your country due to copyright reasons', expected=True)
  38. streams = self._download_json(
  39. 'http://playapi.mtgx.tv/v1/videos/stream/%s' % video_id, video_id, 'Downloading streams JSON')
  40. quality = qualities(['hls', 'medium', 'high'])
  41. formats = []
  42. for format_id, video_url in streams['streams'].items():
  43. if not video_url:
  44. continue
  45. fmt = {
  46. 'format_id': format_id,
  47. 'preference': quality(format_id),
  48. }
  49. if video_url.startswith('rtmp'):
  50. m = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
  51. if not m:
  52. continue
  53. fmt.update({
  54. 'ext': 'flv',
  55. 'url': m.group('url'),
  56. 'app': m.group('app'),
  57. 'play_path': m.group('playpath'),
  58. })
  59. else:
  60. fmt.update({
  61. 'url': video_url,
  62. })
  63. formats.append(fmt)
  64. self._sort_formats(formats)
  65. return {
  66. 'id': video_id,
  67. 'title': video['title'],
  68. 'description': video['description'],
  69. 'duration': video['duration'],
  70. 'timestamp': parse_iso8601(video['created_at']),
  71. 'view_count': video['views']['total'],
  72. 'age_limit': video.get('age_limit', 0),
  73. 'formats': formats,
  74. }