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.

63 lines
2.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. class TrailerAddictIE(InfoExtractor):
  5. _VALID_URL = r'(?:http://)?(?: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 = re.match(self._VALID_URL, url)
  18. name = mobj.group('movie') + '/' + mobj.group('trailer_name')
  19. webpage = self._download_webpage(url, name)
  20. title = self._search_regex(r'<title>(.+?)</title>',
  21. webpage, 'video title').replace(' - Trailer Addict','')
  22. view_count_str = self._search_regex(
  23. r'<span class="views_n">([0-9,.]+)</span>',
  24. webpage, 'view count', fatal=False)
  25. view_count = (
  26. None if view_count_str is None
  27. else int(view_count_str.replace(',', '')))
  28. video_id = self._search_regex(
  29. r'<param\s+name="movie"\s+value="/emb/([0-9]+)"\s*/>',
  30. webpage, 'video id')
  31. # Presence of (no)watchplus function indicates HD quality is available
  32. if re.search(r'function (no)?watchplus()', webpage):
  33. fvar = "fvarhd"
  34. else:
  35. fvar = "fvar"
  36. info_url = "http://www.traileraddict.com/%s.php?tid=%s" % (fvar, str(video_id))
  37. info_webpage = self._download_webpage(info_url, video_id , "Downloading the info webpage")
  38. final_url = self._search_regex(r'&fileurl=(.+)',
  39. info_webpage, 'Download url').replace('%3F','?')
  40. thumbnail_url = self._search_regex(r'&image=(.+?)&',
  41. info_webpage, 'thumbnail url')
  42. description = self._html_search_regex(
  43. r'(?s)<div class="synopsis">.*?<div class="movie_label_info"[^>]*>(.*?)</div>',
  44. webpage, 'description', fatal=False)
  45. return {
  46. 'id': video_id,
  47. 'url': final_url,
  48. 'title': title,
  49. 'thumbnail': thumbnail_url,
  50. 'description': description,
  51. 'view_count': view_count,
  52. }