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         video_url 
= manifest_url
.replace('manifest.f4m', 'index_2_av.m3u8') 
  23         video_url 
= video_url
.replace('/z/', '/i/') 
  24         thumbnail_path 
= info
.find('image').text
 
  26         return {'id': video_id
, 
  27                 'ext': 'flv' if video_url
.startswith('rtmp') else 'mp4', 
  29                 'title': info
.find('titre').text
, 
  30                 'thumbnail': compat_urlparse
.urljoin('http://pluzz.francetv.fr', thumbnail_path
), 
  31                 'description': info
.find('synopsis').text
, 
  35 class PluzzIE(FranceTVBaseInfoExtractor
): 
  36     IE_NAME 
= 'pluzz.francetv.fr' 
  37     _VALID_URL 
= r
'https?://pluzz\.francetv\.fr/videos/(.*?)\.html' 
  39     # Can't use tests, videos expire in 7 days 
  41     def _real_extract(self
, url
): 
  42         title 
= re
.match(self
._VALID
_URL
, url
).group(1) 
  43         webpage 
= self
._download
_webpage
(url
, title
) 
  44         video_id 
= self
._search
_regex
( 
  45             r
'data-diffusion="(\d+)"', webpage
, 'ID') 
  46         return self
._extract
_video
(video_id
) 
  49 class FranceTvInfoIE(FranceTVBaseInfoExtractor
): 
  50     IE_NAME 
= 'francetvinfo.fr' 
  51     _VALID_URL 
= r
'https?://www\.francetvinfo\.fr/.*/(?P<title>.+)\.html' 
  54         'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html', 
  61             'skip_download': True, 
  64         'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html', 
  68             'title': 'Débat des candidats à la Commission européenne', 
  69             'description': 'Débat des candidats à la Commission européenne', 
  72             'skip_download': 'HLS (reqires ffmpeg)' 
  76     def _real_extract(self
, url
): 
  77         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  78         page_title 
= mobj
.group('title') 
  79         webpage 
= self
._download
_webpage
(url
, page_title
) 
  80         video_id 
= self
._search
_regex
(r
'id-video=((?:[^0-9]*?_)?[0-9]+)[@"]', webpage
, 'video id') 
  81         return self
._extract
_video
(video_id
) 
  84 class FranceTVIE(FranceTVBaseInfoExtractor
): 
  86     IE_DESC 
= 'France 2, 3, 4, 5 and Ô' 
  87     _VALID_URL 
= r
'''(?x)https?://www\.france[2345o]\.fr/ 
  89             emissions/.*?/(videos|emissions)/(?P<id>[^/?]+) 
  90         |   (emissions?|jt)/(?P<key>[^/?]+) 
  96             'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104', 
  97             'file': '75540104.mp4', 
  99                 'title': '13h15, le samedi...', 
 100                 'description': 'md5:2e5b58ba7a2d3692b35c792be081a03d', 
 104                 'skip_download': True, 
 109             'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575', 
 111                 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au', 
 113                 'title': 'Le scandale du prix des médicaments', 
 114                 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce', 
 118                 'skip_download': True, 
 123             'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4', 
 125                 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4', 
 127                 'title': 'Hero Corp Making of - Extrait 1', 
 128                 'description': 'md5:c87d54871b1790679aec1197e73d650a', 
 132                 'skip_download': True, 
 137             'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968', 
 141                 'title': 'C à dire ?!', 
 142                 'description': 'md5:fb1db1cbad784dcce7c7a7bd177c8e2f', 
 146                 'skip_download': True, 
 151             'url': 'http://www.franceo.fr/jt/info-afrique/04-12-2013', 
 155                 'title': 'Infô-Afrique', 
 156                 'description': 'md5:ebf346da789428841bee0fd2a935ea55', 
 160                 'skip_download': True, 
 162             'skip': 'The id changes frequently', 
 166     def _real_extract(self
, url
): 
 167         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 168         if mobj
.group('key'): 
 169             webpage 
= self
._download
_webpage
(url
, mobj
.group('key')) 
 171                 (r
'''(?x)<div\s+class="video-player">\s* 
 172                     <a\s+href="http://videos.francetv.fr/video/([0-9]+)"\s+ 
 173                     class="francetv-video-player">'''), 
 174                 (r
'<a id="player_direct" href="http://info\.francetelevisions' 
 175                  '\.fr/\?id-video=([^"/&]+)'), 
 176                 (r
'<a class="video" id="ftv_player_(.+?)"'), 
 178             video_id 
= self
._html
_search
_regex
(id_res
, webpage
, 'video ID') 
 180             video_id 
= mobj
.group('id') 
 181         return self
._extract
_video
(video_id
) 
 184 class GenerationQuoiIE(InfoExtractor
): 
 185     IE_NAME 
= 'france2.fr:generation-quoi' 
 186     _VALID_URL 
= r
'https?://generation-quoi\.france2\.fr/portrait/(?P<name>.*)(\?|$)' 
 189         'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous', 
 190         'file': 'k7FJX8VBcvvLmX4wA5Q.mp4', 
 192             'title': 'Génération Quoi - Garde à Vous', 
 193             'uploader': 'Génération Quoi', 
 196             # It uses Dailymotion 
 197             'skip_download': True, 
 199         'skip': 'Only available from France', 
 202     def _real_extract(self
, url
): 
 203         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 204         name 
= mobj
.group('name') 
 205         info_url 
= compat_urlparse
.urljoin(url
, '/medias/video/%s.json' % name
) 
 206         info_json 
= self
._download
_webpage
(info_url
, name
) 
 207         info 
= json
.loads(info_json
) 
 208         return self
.url_result('http://www.dailymotion.com/video/%s' % info
['id'], 
 212 class CultureboxIE(FranceTVBaseInfoExtractor
): 
 213     IE_NAME 
= 'culturebox.francetvinfo.fr' 
 214     _VALID_URL 
= r
'https?://culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)' 
 217         'url': 'http://culturebox.francetvinfo.fr/einstein-on-the-beach-au-theatre-du-chatelet-146813', 
 221             'title': 'Einstein on the beach au Théâtre du Châtelet', 
 222             'description': 'md5:9ce2888b1efefc617b5e58b3f6200eeb', 
 226             'skip_download': True, 
 230     def _real_extract(self
, url
): 
 231         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 232         name 
= mobj
.group('name') 
 233         webpage 
= self
._download
_webpage
(url
, name
) 
 234         video_id 
= self
._search
_regex
(r
'"http://videos\.francetv\.fr/video/(.*?)"', webpage
, 'video id') 
 235         return self
._extract
_video
(video_id
)