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.

231 lines
7.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. ExtractorError,
  8. parse_iso8601,
  9. qualities,
  10. )
  11. class TVPlayIE(InfoExtractor):
  12. IE_DESC = 'TV3Play and related services'
  13. _VALID_URL = r'''(?x)http://(?:www\.)?
  14. (?:tvplay\.lv/parraides|
  15. tv3play\.lt/programos|
  16. tv3play\.ee/sisu|
  17. tv3play\.se/program|
  18. tv6play\.se/program|
  19. tv8play\.se/program|
  20. tv10play\.se/program|
  21. tv3play\.no/programmer|
  22. viasat4play\.no/programmer|
  23. tv6play\.no/programmer|
  24. tv3play\.dk/programmer|
  25. )/[^/]+/(?P<id>\d+)
  26. '''
  27. _TESTS = [
  28. {
  29. 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true',
  30. 'info_dict': {
  31. 'id': '418113',
  32. 'ext': 'flv',
  33. 'title': 'Kādi ir īri? - Viņas melo labāk',
  34. 'description': 'Baiba apsmej īrus, kādi tie ir un ko viņi dara.',
  35. 'duration': 25,
  36. 'timestamp': 1406097056,
  37. 'upload_date': '20140723',
  38. },
  39. 'params': {
  40. # rtmp download
  41. 'skip_download': True,
  42. },
  43. },
  44. {
  45. 'url': 'http://www.tv3play.lt/programos/moterys-meluoja-geriau/409229?autostart=true',
  46. 'info_dict': {
  47. 'id': '409229',
  48. 'ext': 'flv',
  49. 'title': 'Moterys meluoja geriau',
  50. 'description': 'md5:9aec0fc68e2cbc992d2a140bd41fa89e',
  51. 'duration': 1330,
  52. 'timestamp': 1403769181,
  53. 'upload_date': '20140626',
  54. },
  55. 'params': {
  56. # rtmp download
  57. 'skip_download': True,
  58. },
  59. },
  60. {
  61. 'url': 'http://www.tv3play.ee/sisu/kodu-keset-linna/238551?autostart=true',
  62. 'info_dict': {
  63. 'id': '238551',
  64. 'ext': 'flv',
  65. 'title': 'Kodu keset linna 398537',
  66. 'description': 'md5:7df175e3c94db9e47c0d81ffa5d68701',
  67. 'duration': 1257,
  68. 'timestamp': 1292449761,
  69. 'upload_date': '20101215',
  70. },
  71. 'params': {
  72. # rtmp download
  73. 'skip_download': True,
  74. },
  75. },
  76. {
  77. 'url': 'http://www.tv3play.se/program/husraddarna/395385?autostart=true',
  78. 'info_dict': {
  79. 'id': '395385',
  80. 'ext': 'flv',
  81. 'title': 'Husräddarna S02E07',
  82. 'description': 'md5:f210c6c89f42d4fc39faa551be813777',
  83. 'duration': 2574,
  84. 'timestamp': 1400596321,
  85. 'upload_date': '20140520',
  86. },
  87. 'params': {
  88. # rtmp download
  89. 'skip_download': True,
  90. },
  91. },
  92. {
  93. 'url': 'http://www.tv6play.se/program/den-sista-dokusapan/266636?autostart=true',
  94. 'info_dict': {
  95. 'id': '266636',
  96. 'ext': 'flv',
  97. 'title': 'Den sista dokusåpan S01E08',
  98. 'description': 'md5:295be39c872520221b933830f660b110',
  99. 'duration': 1492,
  100. 'timestamp': 1330522854,
  101. 'upload_date': '20120229',
  102. },
  103. 'params': {
  104. # rtmp download
  105. 'skip_download': True,
  106. },
  107. },
  108. {
  109. 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true',
  110. 'info_dict': {
  111. 'id': '282756',
  112. 'ext': 'flv',
  113. 'title': 'Antikjakten S01E10',
  114. 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8',
  115. 'duration': 2646,
  116. 'timestamp': 1348575868,
  117. 'upload_date': '20120925',
  118. },
  119. 'params': {
  120. # rtmp download
  121. 'skip_download': True,
  122. },
  123. },
  124. {
  125. 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true',
  126. 'info_dict': {
  127. 'id': '230898',
  128. 'ext': 'flv',
  129. 'title': 'Anna Anka søker assistent - Ep. 8',
  130. 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474',
  131. 'duration': 2656,
  132. 'timestamp': 1277720005,
  133. 'upload_date': '20100628',
  134. },
  135. 'params': {
  136. # rtmp download
  137. 'skip_download': True,
  138. },
  139. },
  140. {
  141. 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true',
  142. 'info_dict': {
  143. 'id': '21873',
  144. 'ext': 'flv',
  145. 'title': 'Budbringerne program 10',
  146. 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d',
  147. 'duration': 1297,
  148. 'timestamp': 1254205102,
  149. 'upload_date': '20090929',
  150. },
  151. 'params': {
  152. # rtmp download
  153. 'skip_download': True,
  154. },
  155. },
  156. {
  157. 'url': 'http://www.tv6play.no/programmer/hotelinspektor-alex-polizzi/361883?autostart=true',
  158. 'info_dict': {
  159. 'id': '361883',
  160. 'ext': 'flv',
  161. 'title': 'Hotelinspektør Alex Polizzi - Ep. 10',
  162. 'description': 'md5:3ecf808db9ec96c862c8ecb3a7fdaf81',
  163. 'duration': 2594,
  164. 'timestamp': 1393236292,
  165. 'upload_date': '20140224',
  166. },
  167. 'params': {
  168. # rtmp download
  169. 'skip_download': True,
  170. },
  171. },
  172. ]
  173. def _real_extract(self, url):
  174. video_id = self._match_id(url)
  175. video = self._download_json(
  176. 'http://playapi.mtgx.tv/v1/videos/%s' % video_id, video_id, 'Downloading video JSON')
  177. if video['is_geo_blocked']:
  178. raise ExtractorError(
  179. 'This content is not available in your country due to copyright reasons', expected=True)
  180. streams = self._download_json(
  181. 'http://playapi.mtgx.tv/v1/videos/stream/%s' % video_id, video_id, 'Downloading streams JSON')
  182. quality = qualities(['hls', 'medium', 'high'])
  183. formats = []
  184. for format_id, video_url in streams['streams'].items():
  185. if not video_url or not isinstance(video_url, compat_str):
  186. continue
  187. fmt = {
  188. 'format_id': format_id,
  189. 'preference': quality(format_id),
  190. }
  191. if video_url.startswith('rtmp'):
  192. m = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
  193. if not m:
  194. continue
  195. fmt.update({
  196. 'ext': 'flv',
  197. 'url': m.group('url'),
  198. 'app': m.group('app'),
  199. 'play_path': m.group('playpath'),
  200. })
  201. elif video_url.endswith('.f4m'):
  202. formats.extend(self._extract_f4m_formats(
  203. video_url + '?hdcore=3.5.0&plugin=aasp-3.5.0.151.81', video_id))
  204. continue
  205. else:
  206. fmt.update({
  207. 'url': video_url,
  208. })
  209. formats.append(fmt)
  210. self._sort_formats(formats)
  211. return {
  212. 'id': video_id,
  213. 'title': video['title'],
  214. 'description': video['description'],
  215. 'duration': video['duration'],
  216. 'timestamp': parse_iso8601(video['created_at']),
  217. 'view_count': video['views']['total'],
  218. 'age_limit': video.get('age_limit', 0),
  219. 'formats': formats,
  220. }