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

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_request,
  6. compat_urllib_parse,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. )
  11. class MooshareIE(InfoExtractor):
  12. IE_NAME = 'mooshare'
  13. IE_DESC = 'Mooshare.biz'
  14. _VALID_URL = r'http://(?:www\.)?mooshare\.biz/(?P<id>[\da-z]{12})'
  15. _TESTS = [
  16. {
  17. 'url': 'http://mooshare.biz/8dqtk4bjbp8g',
  18. 'md5': '4e14f9562928aecd2e42c6f341c8feba',
  19. 'info_dict': {
  20. 'id': '8dqtk4bjbp8g',
  21. 'ext': 'mp4',
  22. 'title': 'Comedy Football 2011 - (part 1-2)',
  23. 'duration': 893,
  24. },
  25. },
  26. {
  27. 'url': 'http://mooshare.biz/aipjtoc4g95j',
  28. 'info_dict': {
  29. 'id': 'aipjtoc4g95j',
  30. 'ext': 'mp4',
  31. 'title': 'Orange Caramel Dashing Through the Snow',
  32. 'duration': 212,
  33. },
  34. 'params': {
  35. # rtmp download
  36. 'skip_download': True,
  37. }
  38. }
  39. ]
  40. def _real_extract(self, url):
  41. video_id = self._match_id(url)
  42. page = self._download_webpage(url, video_id, 'Downloading page')
  43. if re.search(r'>Video Not Found or Deleted<', page) is not None:
  44. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  45. hash_key = self._html_search_regex(r'<input type="hidden" name="hash" value="([^"]+)">', page, 'hash')
  46. title = self._html_search_regex(r'(?m)<div class="blockTitle">\s*<h2>Watch ([^<]+)</h2>', page, 'title')
  47. download_form = {
  48. 'op': 'download1',
  49. 'id': video_id,
  50. 'hash': hash_key,
  51. }
  52. request = compat_urllib_request.Request(
  53. 'http://mooshare.biz/%s' % video_id, compat_urllib_parse.urlencode(download_form))
  54. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  55. self._sleep(5, video_id)
  56. video_page = self._download_webpage(request, video_id, 'Downloading video page')
  57. thumbnail = self._html_search_regex(r'image:\s*"([^"]+)",', video_page, 'thumbnail', fatal=False)
  58. duration_str = self._html_search_regex(r'duration:\s*"(\d+)",', video_page, 'duration', fatal=False)
  59. duration = int(duration_str) if duration_str is not None else None
  60. formats = []
  61. # SD video
  62. mobj = re.search(r'(?m)file:\s*"(?P<url>[^"]+)",\s*provider:', video_page)
  63. if mobj is not None:
  64. formats.append({
  65. 'url': mobj.group('url'),
  66. 'format_id': 'sd',
  67. 'format': 'SD',
  68. })
  69. # HD video
  70. mobj = re.search(r'\'hd-2\': { file: \'(?P<url>[^\']+)\' },', video_page)
  71. if mobj is not None:
  72. formats.append({
  73. 'url': mobj.group('url'),
  74. 'format_id': 'hd',
  75. 'format': 'HD',
  76. })
  77. # rtmp video
  78. mobj = re.search(r'(?m)file: "(?P<playpath>[^"]+)",\s*streamer: "(?P<rtmpurl>rtmp://[^"]+)",', video_page)
  79. if mobj is not None:
  80. formats.append({
  81. 'url': mobj.group('rtmpurl'),
  82. 'play_path': mobj.group('playpath'),
  83. 'rtmp_live': False,
  84. 'ext': 'mp4',
  85. 'format_id': 'rtmp',
  86. 'format': 'HD',
  87. })
  88. return {
  89. 'id': video_id,
  90. 'title': title,
  91. 'thumbnail': thumbnail,
  92. 'duration': duration,
  93. 'formats': formats,
  94. }