3 from __future__ 
import unicode_literals
 
   8 from .common 
import InfoExtractor
 
  14 class FranceTVBaseInfoExtractor(InfoExtractor
): 
  15     def _extract_video(self
, video_id
): 
  16         info 
= self
._download
_xml
( 
  17             'http://www.francetvinfo.fr/appftv/webservices/video/' 
  18             'getInfosOeuvre.php?id-diffusion=' 
  19             + video_id
, video_id
, 'Downloading XML config') 
  21         manifest_url 
= info
.find('videos/video/url').text
 
  22         manifest_url 
= manifest_url
.replace('/z/', '/i/') 
  24         if manifest_url
.startswith('rtmp'): 
  25             formats 
= [{'url': manifest_url
, 'ext': 'flv'}] 
  28             available_formats 
= self
._search
_regex
(r
'/[^,]*,(.*?),k\.mp4', manifest_url
, 'available formats') 
  29             for index
, format_descr 
in enumerate(available_formats
.split(',')): 
  31                     'url': manifest_url
.replace('manifest.f4m', 'index_%d_av.m3u8' % index
), 
  34                 m_resolution 
= re
.search(r
'(?P<width>\d+)x(?P<height>\d+)', format_descr
) 
  35                 if m_resolution 
is not None: 
  37                         'width': int(m_resolution
.group('width')), 
  38                         'height': int(m_resolution
.group('height')), 
  40                 formats
.append(format_info
) 
  42         thumbnail_path 
= info
.find('image').text
 
  46             'title': info
.find('titre').text
, 
  48             'thumbnail': compat_urlparse
.urljoin('http://pluzz.francetv.fr', thumbnail_path
), 
  49             'description': info
.find('synopsis').text
, 
  53 class PluzzIE(FranceTVBaseInfoExtractor
): 
  54     IE_NAME 
= 'pluzz.francetv.fr' 
  55     _VALID_URL 
= r
'https?://pluzz\.francetv\.fr/videos/(.*?)\.html' 
  57     # Can't use tests, videos expire in 7 days 
  59     def _real_extract(self
, url
): 
  60         title 
= re
.match(self
._VALID
_URL
, url
).group(1) 
  61         webpage 
= self
._download
_webpage
(url
, title
) 
  62         video_id 
= self
._search
_regex
( 
  63             r
'data-diffusion="(\d+)"', webpage
, 'ID') 
  64         return self
._extract
_video
(video_id
) 
  67 class FranceTvInfoIE(FranceTVBaseInfoExtractor
): 
  68     IE_NAME 
= 'francetvinfo.fr' 
  69     _VALID_URL 
= r
'https?://(?:www|mobile)\.francetvinfo\.fr/.*/(?P<title>.+)\.html' 
  72         'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html', 
  79             'skip_download': True, 
  82         'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html', 
  86             'title': 'Débat des candidats à la Commission européenne', 
  87             'description': 'Débat des candidats à la Commission européenne', 
  90             'skip_download': 'HLS (reqires ffmpeg)' 
  94     def _real_extract(self
, url
): 
  95         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  96         page_title 
= mobj
.group('title') 
  97         webpage 
= self
._download
_webpage
(url
, page_title
) 
  98         video_id 
= self
._search
_regex
(r
'id-video=((?:[^0-9]*?_)?[0-9]+)[@"]', webpage
, 'video id') 
  99         return self
._extract
_video
(video_id
) 
 102 class FranceTVIE(FranceTVBaseInfoExtractor
): 
 104     IE_DESC 
= 'France 2, 3, 4, 5 and Ô' 
 105     _VALID_URL 
= r
'''(?x)https?://www\.france[2345o]\.fr/ 
 107             emissions/.*?/(videos|emissions)/(?P<id>[^/?]+) 
 108         |   (emissions?|jt)/(?P<key>[^/?]+) 
 114             'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104', 
 115             'file': '75540104.mp4', 
 117                 'title': '13h15, le samedi...', 
 118                 'description': 'md5:2e5b58ba7a2d3692b35c792be081a03d', 
 122                 'skip_download': True, 
 127             'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575', 
 129                 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au', 
 131                 'title': 'Le scandale du prix des médicaments', 
 132                 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce', 
 136                 'skip_download': True, 
 141             'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4', 
 143                 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4', 
 145                 'title': 'Hero Corp Making of - Extrait 1', 
 146                 'description': 'md5:c87d54871b1790679aec1197e73d650a', 
 150                 'skip_download': True, 
 155             'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968', 
 159                 'title': 'C à dire ?!', 
 160                 'description': 'md5:fb1db1cbad784dcce7c7a7bd177c8e2f', 
 164                 'skip_download': True, 
 169             'url': 'http://www.franceo.fr/jt/info-afrique/04-12-2013', 
 173                 'title': 'Infô-Afrique', 
 174                 'description': 'md5:ebf346da789428841bee0fd2a935ea55', 
 178                 'skip_download': True, 
 180             'skip': 'The id changes frequently', 
 184     def _real_extract(self
, url
): 
 185         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 186         if mobj
.group('key'): 
 187             webpage 
= self
._download
_webpage
(url
, mobj
.group('key')) 
 189                 (r
'''(?x)<div\s+class="video-player">\s* 
 190                     <a\s+href="http://videos.francetv.fr/video/([0-9]+)"\s+ 
 191                     class="francetv-video-player">'''), 
 192                 (r
'<a id="player_direct" href="http://info\.francetelevisions' 
 193                  '\.fr/\?id-video=([^"/&]+)'), 
 194                 (r
'<a class="video" id="ftv_player_(.+?)"'), 
 196             video_id 
= self
._html
_search
_regex
(id_res
, webpage
, 'video ID') 
 198             video_id 
= mobj
.group('id') 
 199         return self
._extract
_video
(video_id
) 
 202 class GenerationQuoiIE(InfoExtractor
): 
 203     IE_NAME 
= 'france2.fr:generation-quoi' 
 204     _VALID_URL 
= r
'https?://generation-quoi\.france2\.fr/portrait/(?P<name>.*)(\?|$)' 
 207         'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous', 
 208         'file': 'k7FJX8VBcvvLmX4wA5Q.mp4', 
 210             'title': 'Génération Quoi - Garde à Vous', 
 211             'uploader': 'Génération Quoi', 
 214             # It uses Dailymotion 
 215             'skip_download': True, 
 217         'skip': 'Only available from France', 
 220     def _real_extract(self
, url
): 
 221         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 222         name 
= mobj
.group('name') 
 223         info_url 
= compat_urlparse
.urljoin(url
, '/medias/video/%s.json' % name
) 
 224         info_json 
= self
._download
_webpage
(info_url
, name
) 
 225         info 
= json
.loads(info_json
) 
 226         return self
.url_result('http://www.dailymotion.com/video/%s' % info
['id'], 
 230 class CultureboxIE(FranceTVBaseInfoExtractor
): 
 231     IE_NAME 
= 'culturebox.francetvinfo.fr' 
 232     _VALID_URL 
= r
'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)' 
 235         'url': 'http://culturebox.francetvinfo.fr/einstein-on-the-beach-au-theatre-du-chatelet-146813', 
 239             'title': 'Einstein on the beach au Théâtre du Châtelet', 
 240             'description': 'md5:9ce2888b1efefc617b5e58b3f6200eeb', 
 244             'skip_download': True, 
 248     def _real_extract(self
, url
): 
 249         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 250         name 
= mobj
.group('name') 
 251         webpage 
= self
._download
_webpage
(url
, name
) 
 252         video_id 
= self
._search
_regex
(r
'"http://videos\.francetv\.fr/video/(.*?)"', webpage
, 'video id') 
 253         return self
._extract
_video
(video_id
)