71 lines
2.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. int_or_none,
  10. parse_filesize,
  11. )
  12. class MinhatecaIE(InfoExtractor):
  13. _VALID_URL = r'https?://minhateca\.com\.br/[^?#]+,(?P<id>[0-9]+)\.'
  14. _TEST = {
  15. 'url': 'http://minhateca.com.br/pereba/misc/youtube-dl+test+video,125848331.mp4(video)',
  16. 'info_dict': {
  17. 'id': '125848331',
  18. 'ext': 'mp4',
  19. 'title': 'youtube-dl test video',
  20. 'thumbnail': 're:^https?://.*\.jpg$',
  21. 'filesize_approx': 1530000,
  22. 'duration': 9,
  23. 'view_count': int,
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. token = self._html_search_regex(
  30. r'<input name="__RequestVerificationToken".*?value="([^"]+)"',
  31. webpage, 'request token')
  32. token_data = [
  33. ('fileId', video_id),
  34. ('__RequestVerificationToken', token),
  35. ]
  36. req = compat_urllib_request.Request(
  37. 'http://minhateca.com.br/action/License/Download',
  38. data=compat_urllib_parse.urlencode(token_data))
  39. req.add_header('Content-Type', 'application/x-www-form-urlencoded')
  40. data = self._download_json(
  41. req, video_id, note='Downloading metadata')
  42. video_url = data['redirectUrl']
  43. title_str = self._html_search_regex(
  44. r'<h1.*?>(.*?)</h1>', webpage, 'title')
  45. title, _, ext = title_str.rpartition('.')
  46. filesize_approx = parse_filesize(self._html_search_regex(
  47. r'<p class="fileSize">(.*?)</p>',
  48. webpage, 'file size approximation', fatal=False))
  49. duration = int_or_none(self._html_search_regex(
  50. r'(?s)<p class="fileLeng[ht][th]">.*?([0-9]+)\s*s',
  51. webpage, 'duration', fatal=False))
  52. view_count = int_or_none(self._html_search_regex(
  53. r'<p class="downloadsCounter">([0-9]+)</p>',
  54. webpage, 'view count', fatal=False))
  55. return {
  56. 'id': video_id,
  57. 'url': video_url,
  58. 'title': title,
  59. 'ext': ext,
  60. 'filesize_approx': filesize_approx,
  61. 'duration': duration,
  62. 'view_count': view_count,
  63. 'thumbnail': self._og_search_thumbnail(webpage),
  64. }