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.

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