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.

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