traileraddict.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import re
  2. from .common import InfoExtractor
  3. class TrailerAddictIE(InfoExtractor):
  4. _WORKING = False
  5. _VALID_URL = r'(?:https?://)?(?:www\.)?traileraddict\.com/(?:trailer|clip)/(?P<movie>.+?)/(?P<trailer_name>.+)'
  6. _TEST = {
  7. 'url': 'http://www.traileraddict.com/trailer/prince-avalanche/trailer',
  8. 'md5': '41365557f3c8c397d091da510e73ceb4',
  9. 'info_dict': {
  10. 'id': '76184',
  11. 'ext': 'mp4',
  12. 'title': 'Prince Avalanche Trailer',
  13. 'description': 'Trailer for Prince Avalanche.\n\nTwo highway road workers spend the summer of 1988 away from their city lives. The isolated landscape becomes a place of misadventure as the men find themselves at odds with each other and the women they left behind.',
  14. },
  15. }
  16. def _real_extract(self, url):
  17. mobj = self._match_valid_url(url)
  18. name = mobj.group('movie') + '/' + mobj.group('trailer_name')
  19. webpage = self._download_webpage(url, name)
  20. title = self._html_extract_title(webpage, 'video title').replace(' - Trailer Addict', '')
  21. view_count_str = self._search_regex(
  22. r'<span class="views_n">([0-9,.]+)</span>',
  23. webpage, 'view count', fatal=False)
  24. view_count = (
  25. None if view_count_str is None
  26. else int(view_count_str.replace(',', '')))
  27. video_id = self._search_regex(
  28. r'<param\s+name="movie"\s+value="/emb/([0-9]+)"\s*/>',
  29. webpage, 'video id')
  30. # Presence of (no)watchplus function indicates HD quality is available
  31. if re.search(r'function (no)?watchplus()', webpage):
  32. fvar = 'fvarhd'
  33. else:
  34. fvar = 'fvar'
  35. info_url = f'http://www.traileraddict.com/{fvar}.php?tid={video_id!s}'
  36. info_webpage = self._download_webpage(info_url, video_id, 'Downloading the info webpage')
  37. final_url = self._search_regex(r'&fileurl=(.+)',
  38. info_webpage, 'Download url').replace('%3F', '?')
  39. thumbnail_url = self._search_regex(r'&image=(.+?)&',
  40. info_webpage, 'thumbnail url')
  41. description = self._html_search_regex(
  42. r'(?s)<div class="synopsis">.*?<div class="movie_label_info"[^>]*>(.*?)</div>',
  43. webpage, 'description', fatal=False)
  44. return {
  45. 'id': video_id,
  46. 'url': final_url,
  47. 'title': title,
  48. 'thumbnail': thumbnail_url,
  49. 'description': description,
  50. 'view_count': view_count,
  51. }