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.

114 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. },
  53. ]
  54. def _real_extract(self, url):
  55. mobj = re.match(self._VALID_URL, url)
  56. video_id = mobj.group('id')
  57. webpage = self._download_webpage(
  58. 'http://%s/video/%s' % (mobj.group('host'), video_id),
  59. video_id, 'Downloading webpage')
  60. title = self._og_search_title(webpage)
  61. thumbnail = self._og_search_thumbnail(webpage)
  62. description = self._og_search_description(webpage)
  63. r = [
  64. self._API_KEY,
  65. [
  66. 'preview/flv_link',
  67. {
  68. 'uid': video_id,
  69. },
  70. ],
  71. ]
  72. r_json = json.dumps(r)
  73. post = compat_urllib_parse.urlencode({'r': r_json})
  74. req = compat_urllib_request.Request(self._API_URL, post)
  75. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  76. response = self._download_json(req, video_id)
  77. if response['status'] != 'OK':
  78. raise ExtractorError(
  79. '%s returned error: %s' % (self.IE_NAME, response['data']),
  80. expected=True
  81. )
  82. item = response['data'][0]
  83. video_url = item['link']
  84. duration = int_or_none(item['length'])
  85. width = int_or_none(item['width'])
  86. height = int_or_none(item['height'])
  87. filesize = int_or_none(item['convert_size'])
  88. formats = [{
  89. 'format_id': 'sd',
  90. 'http_headers': {'Range': 'bytes=0-'}, # Required to download
  91. 'url': video_url,
  92. 'width': width,
  93. 'height': height,
  94. 'filesize': filesize,
  95. }]
  96. return {
  97. 'id': video_id,
  98. 'title': title,
  99. 'thumbnail': thumbnail,
  100. 'description': description,
  101. 'duration': duration,
  102. 'formats': formats,
  103. }