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.

249 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. 'age_limit': 18,
  104. },
  105. 'params': {
  106. # rtmp download
  107. 'skip_download': True,
  108. },
  109. },
  110. {
  111. 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true',
  112. 'info_dict': {
  113. 'id': '282756',
  114. 'ext': 'flv',
  115. 'title': 'Antikjakten S01E10',
  116. 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8',
  117. 'duration': 2646,
  118. 'timestamp': 1348575868,
  119. 'upload_date': '20120925',
  120. },
  121. 'params': {
  122. # rtmp download
  123. 'skip_download': True,
  124. },
  125. },
  126. {
  127. 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true',
  128. 'info_dict': {
  129. 'id': '230898',
  130. 'ext': 'flv',
  131. 'title': 'Anna Anka søker assistent - Ep. 8',
  132. 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474',
  133. 'duration': 2656,
  134. 'timestamp': 1277720005,
  135. 'upload_date': '20100628',
  136. },
  137. 'params': {
  138. # rtmp download
  139. 'skip_download': True,
  140. },
  141. },
  142. {
  143. 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true',
  144. 'info_dict': {
  145. 'id': '21873',
  146. 'ext': 'flv',
  147. 'title': 'Budbringerne program 10',
  148. 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d',
  149. 'duration': 1297,
  150. 'timestamp': 1254205102,
  151. 'upload_date': '20090929',
  152. },
  153. 'params': {
  154. # rtmp download
  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': 'flv',
  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. # rtmp download
  171. 'skip_download': True,
  172. },
  173. },
  174. {
  175. 'url': 'http://play.novatv.bg/programi/zdravei-bulgariya/624952?autostart=true',
  176. 'info_dict': {
  177. 'id': '624952',
  178. 'ext': 'flv',
  179. 'title': 'Здравей, България (12.06.2015 г.) ',
  180. 'description': 'md5:99f3700451ac5bb71a260268b8daefd7',
  181. 'duration': 8838,
  182. 'timestamp': 1434100372,
  183. 'upload_date': '20150612',
  184. },
  185. 'params': {
  186. # rtmp download
  187. 'skip_download': True,
  188. },
  189. },
  190. ]
  191. def _real_extract(self, url):
  192. video_id = self._match_id(url)
  193. video = self._download_json(
  194. 'http://playapi.mtgx.tv/v1/videos/%s' % video_id, video_id, 'Downloading video JSON')
  195. if video['is_geo_blocked']:
  196. self.report_warning(
  197. 'This content might not be available in your country due to copyright reasons')
  198. streams = self._download_json(
  199. 'http://playapi.mtgx.tv/v1/videos/stream/%s' % video_id, video_id, 'Downloading streams JSON')
  200. quality = qualities(['hls', 'medium', 'high'])
  201. formats = []
  202. for format_id, video_url in streams['streams'].items():
  203. if not video_url or not isinstance(video_url, compat_str):
  204. continue
  205. fmt = {
  206. 'format_id': format_id,
  207. 'preference': quality(format_id),
  208. }
  209. if video_url.startswith('rtmp'):
  210. m = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
  211. if not m:
  212. continue
  213. fmt.update({
  214. 'ext': 'flv',
  215. 'url': m.group('url'),
  216. 'app': m.group('app'),
  217. 'play_path': m.group('playpath'),
  218. })
  219. elif video_url.endswith('.f4m'):
  220. formats.extend(self._extract_f4m_formats(
  221. video_url + '?hdcore=3.5.0&plugin=aasp-3.5.0.151.81', video_id))
  222. continue
  223. else:
  224. fmt.update({
  225. 'url': video_url,
  226. })
  227. formats.append(fmt)
  228. self._sort_formats(formats)
  229. return {
  230. 'id': video_id,
  231. 'title': video['title'],
  232. 'description': video['description'],
  233. 'duration': video['duration'],
  234. 'timestamp': parse_iso8601(video['created_at']),
  235. 'view_count': video['views']['total'],
  236. 'age_limit': video.get('age_limit', 0),
  237. 'formats': formats,
  238. }