xfileshare.py 6.7 KB

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