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.

64 lines
2.6 KiB

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