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.

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