minhateca.py 2.4 KB

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