bigflix.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import re
  2. from .common import InfoExtractor
  3. from ..compat import (
  4. compat_b64decode,
  5. compat_urllib_parse_unquote,
  6. )
  7. class BigflixIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?bigflix\.com/.+/(?P<id>[0-9]+)'
  9. _TESTS = [{
  10. # 2 formats
  11. 'url': 'http://www.bigflix.com/Tamil-movies/Drama-movies/Madarasapatinam/16070',
  12. 'info_dict': {
  13. 'id': '16070',
  14. 'ext': 'mp4',
  15. 'title': 'Madarasapatinam',
  16. 'description': 'md5:9f0470b26a4ba8e824c823b5d95c2f6b',
  17. 'formats': 'mincount:2',
  18. },
  19. 'params': {
  20. 'skip_download': True,
  21. }
  22. }, {
  23. # multiple formats
  24. 'url': 'http://www.bigflix.com/Malayalam-movies/Drama-movies/Indian-Rupee/15967',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. webpage = self._download_webpage(url, video_id)
  30. title = self._html_search_regex(
  31. r'<div[^>]+class=["\']pagetitle["\'][^>]*>(.+?)</div>',
  32. webpage, 'title')
  33. def decode_url(quoted_b64_url):
  34. return compat_b64decode(compat_urllib_parse_unquote(
  35. quoted_b64_url)).decode('utf-8')
  36. formats = []
  37. for height, encoded_url in re.findall(
  38. r'ContentURL_(\d{3,4})[pP][^=]+=([^&]+)', webpage):
  39. video_url = decode_url(encoded_url)
  40. f = {
  41. 'url': video_url,
  42. 'format_id': '%sp' % height,
  43. 'height': int(height),
  44. }
  45. if video_url.startswith('rtmp'):
  46. f['ext'] = 'flv'
  47. formats.append(f)
  48. file_url = self._search_regex(
  49. r'file=([^&]+)', webpage, 'video url', default=None)
  50. if file_url:
  51. video_url = decode_url(file_url)
  52. if all(f['url'] != video_url for f in formats):
  53. formats.append({
  54. 'url': decode_url(file_url),
  55. })
  56. description = self._html_search_meta('description', webpage)
  57. return {
  58. 'id': video_id,
  59. 'title': title,
  60. 'description': description,
  61. 'formats': formats
  62. }