]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/appletrailers.py
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
12 class AppleTrailersIE(InfoExtractor
):
13 _VALID_URL
= r
'https?://(?:www\.)?trailers\.apple\.com/trailers/(?P<company>[^/]+)/(?P<movie>[^/]+)'
15 "url": "http://trailers.apple.com/trailers/wb/manofsteel/",
18 "md5": "d97a8e575432dbcb81b7c3acb741f8a8",
20 "id": "manofsteel-trailer4",
24 "upload_date": "20130523",
29 "md5": "b8017b7131b721fb4e8d6f49e1df908c",
31 "id": "manofsteel-trailer3",
35 "upload_date": "20130417",
40 "md5": "d0f1e1150989b9924679b441f3404d48",
42 "id": "manofsteel-trailer",
46 "upload_date": "20121212",
51 "md5": "5fe08795b943eb2e757fa95cb6def1cb",
53 "id": "manofsteel-teaser",
57 "upload_date": "20120721",
64 _JSON_RE
= r
'iTunes.playURL\((.*?)\);'
66 def _real_extract(self
, url
):
67 mobj
= re
.match(self
._VALID
_URL
, url
)
68 movie
= mobj
.group('movie')
69 uploader_id
= mobj
.group('company')
71 playlist_url
= compat_urlparse
.urljoin(url
, 'includes/playlists/itunes.inc')
73 s
= re
.sub(r
'(?s)<script[^<]*?>.*?</script>', '', s
)
74 s
= re
.sub(r
'<img ([^<]*?)>', r
'<img \1/>', s
)
75 # The ' in the onClick attributes are not escaped, it couldn't be parsed
76 # like: http://trailers.apple.com/trailers/wb/gravity/
78 return 'iTunes.playURL(%s);' % m
.group(1).replace('\'', ''')
79 s
= re
.sub(self
._JSON
_RE
, _clean_json
, s
)
80 s
= '<html>' + s
+ u
'</html>'
82 doc
= self
._download
_xml
(playlist_url
, movie
, transform_source
=fix_html
)
85 for li
in doc
.findall('./div/ul/li'):
86 on_click
= li
.find('.//a').attrib
['onClick']
87 trailer_info_json
= self
._search
_regex
(self
._JSON
_RE
,
88 on_click
, 'trailer info')
89 trailer_info
= json
.loads(trailer_info_json
)
90 title
= trailer_info
['title']
91 video_id
= movie
+ '-' + re
.sub(r
'[^a-zA-Z0-9]', '', title
).lower()
92 thumbnail
= li
.find('.//img').attrib
['src']
93 upload_date
= trailer_info
['posted'].replace('-', '')
95 runtime
= trailer_info
['runtime']
96 m
= re
.search(r
'(?P<minutes>[0-9]+):(?P<seconds>[0-9]{1,2})', runtime
)
99 duration
= 60 * int(m
.group('minutes')) + int(m
.group('seconds'))
101 first_url
= trailer_info
['url']
102 trailer_id
= first_url
.split('/')[-1].rpartition('_')[0].lower()
103 settings_json_url
= compat_urlparse
.urljoin(url
, 'includes/settings/%s.json' % trailer_id
)
104 settings
= self
._download
_json
(settings_json_url
, trailer_id
, 'Downloading settings json')
107 for format
in settings
['metadata']['sizes']:
108 # The src is a file pointing to the real video file
109 format_url
= re
.sub(r
'_(\d*p.mov)', r
'_h\1', format
['src'])
112 'format': format
['type'],
113 'width': format
['width'],
114 'height': int(format
['height']),
117 self
._sort
_formats
(formats
)
125 'duration': duration
,
126 'thumbnail': thumbnail
,
127 'upload_date': upload_date
,
128 'uploader_id': uploader_id
,
129 'user_agent': 'QuickTime compatible (youtube-dl)',