1 from __future__ 
import unicode_literals
 
   3 from .common 
import InfoExtractor
 
   7     compat_urllib_parse_unquote
, 
  15 class BeegIE(InfoExtractor
): 
  16     _VALID_URL 
= r
'https?://(?:www\.)?beeg\.com/(?P<id>\d+)' 
  18         'url': 'http://beeg.com/5416503', 
  19         'md5': '46c384def73b33dbc581262e5ee67cef', 
  23             'title': 'Sultry Striptease', 
  24             'description': 'md5:d22219c09da287c14bed3d6c37ce4bc2', 
  25             'timestamp': 1391813355, 
  26             'upload_date': '20140207', 
  33     def _real_extract(self
, url
): 
  34         video_id 
= self
._match
_id
(url
) 
  36         video 
= self
._download
_json
( 
  37             'https://api.beeg.com/api/v5/video/%s' % video_id
, video_id
) 
  53             # Reverse engineered from http://static.beeg.com/cpl/1105.js 
  54             a 
= '5ShMcIQlssOd7zChAIOlmeTZDaUxULbJRnywYaiB' 
  55             e 
= compat_urllib_parse_unquote(key
) 
  57                 compat_chr(compat_ord(e
[n
]) - compat_ord(a
[n 
% len(a
)]) % 21) 
  58                 for n 
in range(len(e
))]) 
  59             return ''.join(split(o
, 3)[::-1]) 
  61         def decrypt_url(encrypted_url
): 
  62             encrypted_url 
= self
._proto
_relative
_url
( 
  63                 encrypted_url
.replace('{DATA_MARKERS}', ''), 'https:') 
  64             key 
= self
._search
_regex
( 
  65                 r
'/key=(.*?)%2Cend=', encrypted_url
, 'key', default
=None) 
  68             return encrypted_url
.replace(key
, decrypt_key(key
)) 
  71         for format_id
, video_url 
in video
.items(): 
  74             height 
= self
._search
_regex
( 
  75                 r
'^(\d+)[pP]$', format_id
, 'height', default
=None) 
  79                 'url': decrypt_url(video_url
), 
  80                 'format_id': format_id
, 
  81                 'height': int(height
), 
  83         self
._sort
_formats
(formats
) 
  85         title 
= video
['title'] 
  86         video_id 
= video
.get('id') or video_id
 
  87         display_id 
= video
.get('code') 
  88         description 
= video
.get('desc') 
  90         timestamp 
= parse_iso8601(video
.get('date'), ' ') 
  91         duration 
= int_or_none(video
.get('duration')) 
  93         tags 
= [tag
.strip() for tag 
in video
['tags'].split(',')] if video
.get('tags') else None 
  97             'display_id': display_id
, 
  99             'description': description
, 
 100             'timestamp': timestamp
, 
 101             'duration': duration
,