| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  | # encoding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							|  |  |  | from ..compat import ( | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |     compat_str, | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  |     compat_urlparse, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							|  |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |     float_or_none, | 
					
						
							|  |  |  |     parse_duration, | 
					
						
							|  |  |  |     str_to_int, | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PandoraTVIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2016-01-01 00:42:42 +06:00
										 |  |  |     IE_NAME = 'pandora.tv' | 
					
						
							|  |  |  |     IE_DESC = '판도라TV' | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |     _VALID_URL = r'https?://(?:.+?\.)?channel\.pandora\.tv/channel/video\.ptv\?' | 
					
						
							|  |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  |         'url': 'http://jp.channel.pandora.tv/channel/video.ptv?c1=&prgid=53294230&ch_userid=mikakim&ref=main&lot=cate_01_2', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '53294230', | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |             'ext': 'flv', | 
					
						
							|  |  |  |             'title': '頭を撫でてくれる?', | 
					
						
							|  |  |  |             'description': '頭を撫でてくれる?', | 
					
						
							|  |  |  |             'thumbnail': 're:^https?://.*\.jpg$', | 
					
						
							|  |  |  |             'duration': 39, | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  |             'upload_date': '20151218', | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |             'uploader': 'カワイイ動物まとめ', | 
					
						
							|  |  |  |             'uploader_id': 'mikakim', | 
					
						
							|  |  |  |             'view_count': int, | 
					
						
							|  |  |  |             'like_count': int, | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query) | 
					
						
							|  |  |  |         video_id = qs.get('prgid', [None])[0] | 
					
						
							|  |  |  |         user_id = qs.get('ch_userid', [None])[0] | 
					
						
							|  |  |  |         if any(not f for f in (video_id, user_id,)): | 
					
						
							|  |  |  |             raise ExtractorError('Invalid URL', expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |         data = self._download_json( | 
					
						
							|  |  |  |             'http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid=%s&prgid=%s' | 
					
						
							|  |  |  |             % (user_id, video_id), video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  |         info = data['data']['rows']['vod_play_info']['result'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |         for format_id, format_url in info.items(): | 
					
						
							|  |  |  |             if not format_url: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             height = self._search_regex( | 
					
						
							|  |  |  |                 r'^v(\d+)[Uu]rl$', format_id, 'height', default=None) | 
					
						
							|  |  |  |             if not height: | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  |             formats.append({ | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |                 'format_id': '%sp' % height, | 
					
						
							|  |  |  |                 'url': format_url, | 
					
						
							|  |  |  |                 'height': int(height), | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |         self._sort_formats(formats) | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': info['subject'], | 
					
						
							| 
									
										
										
										
											2016-01-01 00:40:27 +06:00
										 |  |  |             'description': info.get('body'), | 
					
						
							|  |  |  |             'thumbnail': info.get('thumbnail') or info.get('poster'), | 
					
						
							|  |  |  |             'duration': float_or_none(info.get('runtime'), 1000) or parse_duration(info.get('time')), | 
					
						
							|  |  |  |             'upload_date': info['fid'][:8] if isinstance(info.get('fid'), compat_str) else None, | 
					
						
							|  |  |  |             'uploader': info.get('nickname'), | 
					
						
							|  |  |  |             'uploader_id': info.get('upload_userid'), | 
					
						
							|  |  |  |             'view_count': str_to_int(info.get('hit')), | 
					
						
							|  |  |  |             'like_count': str_to_int(info.get('likecnt')), | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2015-12-20 15:37:57 +01:00
										 |  |  |         } |