<s> from __future__ import unicode_literals <EOL> import json <EOL> import re <EOL> from . common import InfoExtractor <EOL> from . . utils import ( <EOL> js_to_json , <EOL> ) <EOL> class PatreonIE ( InfoExtractor ) : <EOL> _VALID_URL = r'<STR_LIT>' <EOL> _TESTS = [ <EOL> { <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } , <EOL> { <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } , <EOL> ] <EOL> '''<STR_LIT>''' <EOL> def _real_extract ( self , url ) : <EOL> mobj = re . match ( self . _VALID_URL , url ) <EOL> video_id = mobj . group ( <NUM_LIT:1> ) <EOL> webpage = self . _download_webpage ( url , video_id ) <EOL> title = self . _og_search_title ( webpage ) . strip ( ) <EOL> attach_fn = self . _html_search_regex ( <EOL> r'<STR_LIT>' , <EOL> webpage , '<STR_LIT>' , default = None ) <EOL> if attach_fn is not None : <EOL> video_url = '<STR_LIT>' + attach_fn <EOL> thumbnail = self . _og_search_thumbnail ( webpage ) <EOL> uploader = self . _html_search_regex ( <EOL> r'<STR_LIT>' , webpage , '<STR_LIT>' ) <EOL> else : <EOL> playlist_js = self . _search_regex ( <EOL> r'<STR_LIT>' , <EOL> webpage , '<STR_LIT>' ) <EOL> playlist_json = js_to_json ( playlist_js ) <EOL> playlist = json . loads ( playlist_json ) <EOL> data = playlist [ <NUM_LIT:0> ] <EOL> video_url = self . _proto_relative_url ( data [ '<STR_LIT>' ] ) <EOL> thumbnail = self . _proto_relative_url ( data . get ( '<STR_LIT>' ) ) <EOL> uploader = data . get ( '<STR_LIT>' ) <EOL> return { <EOL> '<STR_LIT:id>' : video_id , <EOL> '<STR_LIT:url>' : video_url , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : title , <EOL> '<STR_LIT>' : uploader , <EOL> '<STR_LIT>' : thumbnail , <EOL> } </s>
