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.

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