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.

296 lines
10 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_HTTPError,
  7. compat_str,
  8. compat_urlparse,
  9. )
  10. from ..utils import (
  11. determine_ext,
  12. ExtractorError,
  13. int_or_none,
  14. parse_iso8601,
  15. qualities,
  16. update_url_query,
  17. )
  18. class TVPlayIE(InfoExtractor):
  19. IE_DESC = 'TV3Play and related services'
  20. _VALID_URL = r'''(?x)https?://(?:www\.)?
  21. (?:tvplay(?:\.skaties)?\.lv/parraides|
  22. (?:tv3play|play\.tv3)\.lt/programos|
  23. tv3play(?:\.tv3)?\.ee/sisu|
  24. tv(?:3|6|8|10)play\.se/program|
  25. (?:(?:tv3play|viasat4play|tv6play)\.no|tv3play\.dk)/programmer|
  26. play\.novatv\.bg/programi
  27. )/[^/]+/(?P<id>\d+)
  28. '''
  29. _TESTS = [
  30. {
  31. 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true',
  32. 'md5': 'a1612fe0849455423ad8718fe049be21',
  33. 'info_dict': {
  34. 'id': '418113',
  35. 'ext': 'mp4',
  36. 'title': 'Kādi ir īri? - Viņas melo labāk',
  37. 'description': 'Baiba apsmej īrus, kādi tie ir un ko viņi dara.',
  38. 'series': 'Viņas melo labāk',
  39. 'season': '2.sezona',
  40. 'season_number': 2,
  41. 'duration': 25,
  42. 'timestamp': 1406097056,
  43. 'upload_date': '20140723',
  44. },
  45. },
  46. {
  47. 'url': 'http://play.tv3.lt/programos/moterys-meluoja-geriau/409229?autostart=true',
  48. 'info_dict': {
  49. 'id': '409229',
  50. 'ext': 'flv',
  51. 'title': 'Moterys meluoja geriau',
  52. 'description': 'md5:9aec0fc68e2cbc992d2a140bd41fa89e',
  53. 'series': 'Moterys meluoja geriau',
  54. 'episode_number': 47,
  55. 'season': '1 sezonas',
  56. 'season_number': 1,
  57. 'duration': 1330,
  58. 'timestamp': 1403769181,
  59. 'upload_date': '20140626',
  60. },
  61. 'params': {
  62. # rtmp download
  63. 'skip_download': True,
  64. },
  65. },
  66. {
  67. 'url': 'http://www.tv3play.ee/sisu/kodu-keset-linna/238551?autostart=true',
  68. 'info_dict': {
  69. 'id': '238551',
  70. 'ext': 'flv',
  71. 'title': 'Kodu keset linna 398537',
  72. 'description': 'md5:7df175e3c94db9e47c0d81ffa5d68701',
  73. 'duration': 1257,
  74. 'timestamp': 1292449761,
  75. 'upload_date': '20101215',
  76. },
  77. 'params': {
  78. # rtmp download
  79. 'skip_download': True,
  80. },
  81. },
  82. {
  83. 'url': 'http://www.tv3play.se/program/husraddarna/395385?autostart=true',
  84. 'info_dict': {
  85. 'id': '395385',
  86. 'ext': 'mp4',
  87. 'title': 'Husräddarna S02E07',
  88. 'description': 'md5:f210c6c89f42d4fc39faa551be813777',
  89. 'duration': 2574,
  90. 'timestamp': 1400596321,
  91. 'upload_date': '20140520',
  92. },
  93. 'params': {
  94. 'skip_download': True,
  95. },
  96. },
  97. {
  98. 'url': 'http://www.tv6play.se/program/den-sista-dokusapan/266636?autostart=true',
  99. 'info_dict': {
  100. 'id': '266636',
  101. 'ext': 'mp4',
  102. 'title': 'Den sista dokusåpan S01E08',
  103. 'description': 'md5:295be39c872520221b933830f660b110',
  104. 'duration': 1492,
  105. 'timestamp': 1330522854,
  106. 'upload_date': '20120229',
  107. 'age_limit': 18,
  108. },
  109. 'params': {
  110. 'skip_download': True,
  111. },
  112. },
  113. {
  114. 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true',
  115. 'info_dict': {
  116. 'id': '282756',
  117. 'ext': 'mp4',
  118. 'title': 'Antikjakten S01E10',
  119. 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8',
  120. 'duration': 2646,
  121. 'timestamp': 1348575868,
  122. 'upload_date': '20120925',
  123. },
  124. 'params': {
  125. 'skip_download': True,
  126. },
  127. },
  128. {
  129. 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true',
  130. 'info_dict': {
  131. 'id': '230898',
  132. 'ext': 'mp4',
  133. 'title': 'Anna Anka søker assistent - Ep. 8',
  134. 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474',
  135. 'duration': 2656,
  136. 'timestamp': 1277720005,
  137. 'upload_date': '20100628',
  138. },
  139. 'params': {
  140. 'skip_download': True,
  141. },
  142. },
  143. {
  144. 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true',
  145. 'info_dict': {
  146. 'id': '21873',
  147. 'ext': 'mp4',
  148. 'title': 'Budbringerne program 10',
  149. 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d',
  150. 'duration': 1297,
  151. 'timestamp': 1254205102,
  152. 'upload_date': '20090929',
  153. },
  154. 'params': {
  155. 'skip_download': True,
  156. },
  157. },
  158. {
  159. 'url': 'http://www.tv6play.no/programmer/hotelinspektor-alex-polizzi/361883?autostart=true',
  160. 'info_dict': {
  161. 'id': '361883',
  162. 'ext': 'mp4',
  163. 'title': 'Hotelinspektør Alex Polizzi - Ep. 10',
  164. 'description': 'md5:3ecf808db9ec96c862c8ecb3a7fdaf81',
  165. 'duration': 2594,
  166. 'timestamp': 1393236292,
  167. 'upload_date': '20140224',
  168. },
  169. 'params': {
  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. 'url': 'http://tvplay.skaties.lv/parraides/vinas-melo-labak/418113?autostart=true',
  191. 'only_matching': True,
  192. },
  193. {
  194. 'url': 'http://tv3play.tv3.ee/sisu/kodu-keset-linna/238551?autostart=true',
  195. 'only_matching': True,
  196. }
  197. ]
  198. def _real_extract(self, url):
  199. video_id = self._match_id(url)
  200. video = self._download_json(
  201. 'http://playapi.mtgx.tv/v1/videos/%s' % video_id, video_id, 'Downloading video JSON')
  202. title = video['title']
  203. try:
  204. streams = self._download_json(
  205. 'http://playapi.mtgx.tv/v1/videos/stream/%s' % video_id,
  206. video_id, 'Downloading streams JSON')
  207. except ExtractorError as e:
  208. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
  209. msg = self._parse_json(e.cause.read().decode('utf-8'), video_id)
  210. raise ExtractorError(msg['msg'], expected=True)
  211. raise
  212. quality = qualities(['hls', 'medium', 'high'])
  213. formats = []
  214. for format_id, video_url in streams.get('streams', {}).items():
  215. if not video_url or not isinstance(video_url, compat_str):
  216. continue
  217. ext = determine_ext(video_url)
  218. if ext == 'f4m':
  219. formats.extend(self._extract_f4m_formats(
  220. update_url_query(video_url, {
  221. 'hdcore': '3.5.0',
  222. 'plugin': 'aasp-3.5.0.151.81'
  223. }), video_id, f4m_id='hds', fatal=False))
  224. elif ext == 'm3u8':
  225. formats.extend(self._extract_m3u8_formats(
  226. video_url, video_id, 'mp4', 'm3u8_native',
  227. m3u8_id='hls', fatal=False))
  228. else:
  229. fmt = {
  230. 'format_id': format_id,
  231. 'quality': quality(format_id),
  232. 'ext': ext,
  233. }
  234. if video_url.startswith('rtmp'):
  235. m = re.search(
  236. r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
  237. if not m:
  238. continue
  239. fmt.update({
  240. 'ext': 'flv',
  241. 'url': m.group('url'),
  242. 'app': m.group('app'),
  243. 'play_path': m.group('playpath'),
  244. })
  245. else:
  246. fmt.update({
  247. 'url': video_url,
  248. })
  249. formats.append(fmt)
  250. if not formats and video.get('is_geo_blocked'):
  251. self.raise_geo_restricted(
  252. 'This content might not be available in your country due to copyright reasons')
  253. self._sort_formats(formats)
  254. # TODO: webvtt in m3u8
  255. subtitles = {}
  256. sami_path = video.get('sami_path')
  257. if sami_path:
  258. lang = self._search_regex(
  259. r'_([a-z]{2})\.xml', sami_path, 'lang',
  260. default=compat_urlparse.urlparse(url).netloc.rsplit('.', 1)[-1])
  261. subtitles[lang] = [{
  262. 'url': sami_path,
  263. }]
  264. series = video.get('format_title')
  265. episode_number = int_or_none(video.get('format_position', {}).get('episode'))
  266. season = video.get('_embedded', {}).get('season', {}).get('title')
  267. season_number = int_or_none(video.get('format_position', {}).get('season'))
  268. return {
  269. 'id': video_id,
  270. 'title': title,
  271. 'description': video.get('description'),
  272. 'series': series,
  273. 'episode_number': episode_number,
  274. 'season': season,
  275. 'season_number': season_number,
  276. 'duration': int_or_none(video.get('duration')),
  277. 'timestamp': parse_iso8601(video.get('created_at')),
  278. 'view_count': int_or_none(video.get('views', {}).get('total')),
  279. 'age_limit': int_or_none(video.get('age_limit', 0)),
  280. 'formats': formats,
  281. 'subtitles': subtitles,
  282. }