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.

213 lines
7.5 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. decode_packed_codes,
  7. determine_ext,
  8. ExtractorError,
  9. int_or_none,
  10. NO_DEFAULT,
  11. urlencode_postdata,
  12. )
  13. class XFileShareIE(InfoExtractor):
  14. _SITES = (
  15. (r'daclips\.(?:in|com)', 'DaClips'),
  16. (r'filehoot\.com', 'FileHoot'),
  17. (r'gorillavid\.(?:in|com)', 'GorillaVid'),
  18. (r'movpod\.in', 'MovPod'),
  19. (r'powerwatch\.pw', 'PowerWatch'),
  20. (r'rapidvideo\.ws', 'Rapidvideo.ws'),
  21. (r'thevideobee\.to', 'TheVideoBee'),
  22. (r'vidto\.(?:me|se)', 'Vidto'),
  23. (r'streamin\.to', 'Streamin.To'),
  24. (r'xvidstage\.com', 'XVIDSTAGE'),
  25. (r'vidabc\.com', 'Vid ABC'),
  26. (r'vidbom\.com', 'VidBom'),
  27. (r'vidlo\.us', 'vidlo'),
  28. (r'rapidvideo\.(?:cool|org)', 'RapidVideo.TV'),
  29. (r'fastvideo\.me', 'FastVideo.me'),
  30. )
  31. IE_DESC = 'XFileShare based sites: %s' % ', '.join(list(zip(*_SITES))[1])
  32. _VALID_URL = (r'https?://(?P<host>(?:www\.)?(?:%s))/(?:embed-)?(?P<id>[0-9a-zA-Z]+)'
  33. % '|'.join(site for site in list(zip(*_SITES))[0]))
  34. _FILE_NOT_FOUND_REGEXES = (
  35. r'>(?:404 - )?File Not Found<',
  36. r'>The file was removed by administrator<',
  37. )
  38. _TESTS = [{
  39. 'url': 'http://gorillavid.in/06y9juieqpmi',
  40. 'md5': '5ae4a3580620380619678ee4875893ba',
  41. 'info_dict': {
  42. 'id': '06y9juieqpmi',
  43. 'ext': 'mp4',
  44. 'title': 'Rebecca Black My Moment Official Music Video Reaction-6GK87Rc8bzQ',
  45. 'thumbnail': r're:http://.*\.jpg',
  46. },
  47. }, {
  48. 'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
  49. 'only_matching': True,
  50. }, {
  51. 'url': 'http://daclips.in/3rso4kdn6f9m',
  52. 'md5': '1ad8fd39bb976eeb66004d3a4895f106',
  53. 'info_dict': {
  54. 'id': '3rso4kdn6f9m',
  55. 'ext': 'mp4',
  56. 'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
  57. 'thumbnail': r're:http://.*\.jpg',
  58. }
  59. }, {
  60. 'url': 'http://movpod.in/0wguyyxi1yca',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'http://filehoot.com/3ivfabn7573c.html',
  64. 'info_dict': {
  65. 'id': '3ivfabn7573c',
  66. 'ext': 'mp4',
  67. 'title': 'youtube-dl test video \'äBaW_jenozKc.mp4.mp4',
  68. 'thumbnail': r're:http://.*\.jpg',
  69. },
  70. 'skip': 'Video removed',
  71. }, {
  72. 'url': 'http://vidto.me/ku5glz52nqe1.html',
  73. 'info_dict': {
  74. 'id': 'ku5glz52nqe1',
  75. 'ext': 'mp4',
  76. 'title': 'test'
  77. }
  78. }, {
  79. 'url': 'http://powerwatch.pw/duecjibvicbu',
  80. 'info_dict': {
  81. 'id': 'duecjibvicbu',
  82. 'ext': 'mp4',
  83. 'title': 'Big Buck Bunny trailer',
  84. },
  85. }, {
  86. 'url': 'http://xvidstage.com/e0qcnl03co6z',
  87. 'info_dict': {
  88. 'id': 'e0qcnl03co6z',
  89. 'ext': 'mp4',
  90. 'title': 'Chucky Prank 2015.mp4',
  91. },
  92. }, {
  93. # removed by administrator
  94. 'url': 'http://xvidstage.com/amfy7atlkx25',
  95. 'only_matching': True,
  96. }, {
  97. 'url': 'http://vidabc.com/i8ybqscrphfv',
  98. 'info_dict': {
  99. 'id': 'i8ybqscrphfv',
  100. 'ext': 'mp4',
  101. 'title': 're:Beauty and the Beast 2017',
  102. },
  103. 'params': {
  104. 'skip_download': True,
  105. },
  106. }, {
  107. 'url': 'http://www.rapidvideo.cool/b667kprndr8w',
  108. 'only_matching': True,
  109. }, {
  110. 'url': 'http://www.fastvideo.me/k8604r8nk8sn/FAST_FURIOUS_8_-_Trailer_italiano_ufficiale.mp4.html',
  111. 'only_matching': True,
  112. }, {
  113. 'url': 'http://vidto.se/1tx1pf6t12cg.html',
  114. 'only_matching': True,
  115. }]
  116. @staticmethod
  117. def _extract_urls(webpage):
  118. return [
  119. mobj.group('url')
  120. for mobj in re.finditer(
  121. r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:%s)/embed-[0-9a-zA-Z]+.*?)\1'
  122. % '|'.join(site for site in list(zip(*XFileShareIE._SITES))[0]),
  123. webpage)]
  124. def _real_extract(self, url):
  125. mobj = re.match(self._VALID_URL, url)
  126. video_id = mobj.group('id')
  127. url = 'http://%s/%s' % (mobj.group('host'), video_id)
  128. webpage = self._download_webpage(url, video_id)
  129. if any(re.search(p, webpage) for p in self._FILE_NOT_FOUND_REGEXES):
  130. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  131. fields = self._hidden_inputs(webpage)
  132. if fields['op'] == 'download1':
  133. countdown = int_or_none(self._search_regex(
  134. r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
  135. webpage, 'countdown', default=None))
  136. if countdown:
  137. self._sleep(countdown, video_id)
  138. webpage = self._download_webpage(
  139. url, video_id, 'Downloading video page',
  140. data=urlencode_postdata(fields), headers={
  141. 'Referer': url,
  142. 'Content-type': 'application/x-www-form-urlencoded',
  143. })
  144. title = (self._search_regex(
  145. (r'style="z-index: [0-9]+;">([^<]+)</span>',
  146. r'<td nowrap>([^<]+)</td>',
  147. r'h4-fine[^>]*>([^<]+)<',
  148. r'>Watch (.+) ',
  149. r'<h2 class="video-page-head">([^<]+)</h2>',
  150. r'<h2 style="[^"]*color:#403f3d[^"]*"[^>]*>([^<]+)<'), # streamin.to
  151. webpage, 'title', default=None) or self._og_search_title(
  152. webpage, default=None) or video_id).strip()
  153. def extract_formats(default=NO_DEFAULT):
  154. urls = []
  155. for regex in (
  156. r'(?:file|src)\s*:\s*(["\'])(?P<url>http(?:(?!\1).)+\.(?:m3u8|mp4|flv)(?:(?!\1).)*)\1',
  157. r'file_link\s*=\s*(["\'])(?P<url>http(?:(?!\1).)+)\1',
  158. r'addVariable\((\\?["\'])file\1\s*,\s*(\\?["\'])(?P<url>http(?:(?!\2).)+)\2\)',
  159. r'<embed[^>]+src=(["\'])(?P<url>http(?:(?!\1).)+\.(?:m3u8|mp4|flv)(?:(?!\1).)*)\1'):
  160. for mobj in re.finditer(regex, webpage):
  161. video_url = mobj.group('url')
  162. if video_url not in urls:
  163. urls.append(video_url)
  164. formats = []
  165. for video_url in urls:
  166. if determine_ext(video_url) == 'm3u8':
  167. formats.extend(self._extract_m3u8_formats(
  168. video_url, video_id, 'mp4',
  169. entry_protocol='m3u8_native', m3u8_id='hls',
  170. fatal=False))
  171. else:
  172. formats.append({
  173. 'url': video_url,
  174. 'format_id': 'sd',
  175. })
  176. if not formats and default is not NO_DEFAULT:
  177. return default
  178. self._sort_formats(formats)
  179. return formats
  180. formats = extract_formats(default=None)
  181. if not formats:
  182. webpage = decode_packed_codes(self._search_regex(
  183. r"(}\('(.+)',(\d+),(\d+),'[^']*\b(?:file|embed)\b[^']*'\.split\('\|'\))",
  184. webpage, 'packed code'))
  185. formats = extract_formats()
  186. thumbnail = self._search_regex(
  187. r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', default=None)
  188. return {
  189. 'id': video_id,
  190. 'title': title,
  191. 'thumbnail': thumbnail,
  192. 'formats': formats,
  193. }