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.

112 lines
3.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. ExtractorError,
  8. compat_urllib_parse,
  9. compat_urllib_request,
  10. int_or_none,
  11. )
  12. class MoeVideoIE(InfoExtractor):
  13. IE_DESC = 'LetitBit video services: moevideo.net, playreplay.net and videochart.net'
  14. _VALID_URL = r'''(?x)
  15. https?://(?P<host>(?:www\.)?
  16. (?:(?:moevideo|playreplay|videochart)\.net))/
  17. (?:video|framevideo)/(?P<id>[0-9]+\.[0-9A-Za-z]+)'''
  18. _API_URL = 'http://api.letitbit.net/'
  19. _API_KEY = 'tVL0gjqo5'
  20. _TESTS = [
  21. {
  22. 'url': 'http://moevideo.net/video/00297.0036103fe3d513ef27915216fd29',
  23. 'md5': '129f5ae1f6585d0e9bb4f38e774ffb3a',
  24. 'info_dict': {
  25. 'id': '00297.0036103fe3d513ef27915216fd29',
  26. 'ext': 'flv',
  27. 'title': 'Sink cut out machine',
  28. 'description': 'md5:f29ff97b663aefa760bf7ca63c8ca8a8',
  29. 'thumbnail': 're:^https?://.*\.jpg$',
  30. 'width': 540,
  31. 'height': 360,
  32. 'duration': 179,
  33. 'filesize': 17822500,
  34. }
  35. },
  36. {
  37. 'url': 'http://playreplay.net/video/77107.7f325710a627383d40540d8e991a',
  38. 'md5': '74f0a014d5b661f0f0e2361300d1620e',
  39. 'info_dict': {
  40. 'id': '77107.7f325710a627383d40540d8e991a',
  41. 'ext': 'flv',
  42. 'title': 'Operacion Condor.',
  43. 'description': 'md5:7e68cb2fcda66833d5081c542491a9a3',
  44. 'thumbnail': 're:^https?://.*\.jpg$',
  45. 'width': 480,
  46. 'height': 296,
  47. 'duration': 6027,
  48. 'filesize': 588257923,
  49. }
  50. },
  51. ]
  52. def _real_extract(self, url):
  53. mobj = re.match(self._VALID_URL, url)
  54. video_id = mobj.group('id')
  55. webpage = self._download_webpage(
  56. 'http://%s/video/%s' % (mobj.group('host'), video_id),
  57. video_id, 'Downloading webpage')
  58. title = self._og_search_title(webpage)
  59. thumbnail = self._og_search_thumbnail(webpage)
  60. description = self._og_search_description(webpage)
  61. r = [
  62. self._API_KEY,
  63. [
  64. 'preview/flv_link',
  65. {
  66. 'uid': video_id,
  67. },
  68. ],
  69. ]
  70. r_json = json.dumps(r)
  71. post = compat_urllib_parse.urlencode({'r': r_json})
  72. req = compat_urllib_request.Request(self._API_URL, post)
  73. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  74. response = self._download_json(req, video_id)
  75. if response['status'] != 'OK':
  76. raise ExtractorError(
  77. '%s returned error: %s' % (self.IE_NAME, response['data']),
  78. expected=True
  79. )
  80. item = response['data'][0]
  81. video_url = item['link']
  82. duration = int_or_none(item['length'])
  83. width = int_or_none(item['width'])
  84. height = int_or_none(item['height'])
  85. filesize = int_or_none(item['convert_size'])
  86. formats = [{
  87. 'format_id': 'sd',
  88. 'http_headers': {'Range': 'bytes=0-'}, # Required to download
  89. 'url': video_url,
  90. 'width': width,
  91. 'height': height,
  92. 'filesize': filesize,
  93. }]
  94. return {
  95. 'id': video_id,
  96. 'title': title,
  97. 'thumbnail': thumbnail,
  98. 'description': description,
  99. 'duration': duration,
  100. 'formats': formats,
  101. }