<s> from wpc import db , app , login_manager <EOL> from wpc . utils import requests_get_with_retries <EOL> from wpc . flask_utils import get_or_create <EOL> from flask . ext . login import UserMixin , AnonymousUserMixin , current_user <EOL> from sqlalchemy . orm . properties import ColumnProperty <EOL> from flask import url_for , request , render_template <EOL> import humanize <EOL> from datetime import datetime , timedelta <EOL> from bs4 import BeautifulSoup <EOL> import uuid <EOL> @ login_manager . user_loader <EOL> def load_user ( reddit_username ) : <EOL> return Streamer . query . filter_by ( reddit_username = reddit_username ) . first ( ) <EOL> class Anon ( AnonymousUserMixin ) : <EOL> def already_subscribed ( self , streamer ) : <EOL> email = request . cookies . get ( "<STR_LIT:email>" ) <EOL> return email and streamer and get_or_create ( Subscriber , email = email ) in streamer . subscribers <EOL> class CaseInsensitiveComparator ( ColumnProperty . Comparator ) : <EOL> def __eq__ ( self , other ) : <EOL> return db . func . lower ( self . __clause_element__ ( ) ) == db . func . lower ( other ) <EOL> login_manager . anonymous_user = Anon <EOL> stream_submission = db . Table ( '<STR_LIT>' , <EOL> db . Column ( '<STR_LIT>' , db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' ) ) , <EOL> db . Column ( '<STR_LIT>' , db . String ( <NUM_LIT:6> ) , db . ForeignKey ( '<STR_LIT>' ) ) ) <EOL> streamer_subscriptions = db . Table ( '<STR_LIT>' , <EOL> db . Column ( '<STR_LIT>' , db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' ) ) , <EOL> db . Column ( '<STR_LIT>' , db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' ) ) ) <EOL> class Submission ( db . Model ) : <EOL> submission_id = db . Column ( db . String ( <NUM_LIT:6> ) , primary_key = True ) <EOL> recording_available = db . Column ( db . Boolean ( ) ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . submission_id ) <EOL> class Stream ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> type = db . Column ( db . String ( <NUM_LIT:50> ) ) <EOL> scheduled_start_time = db . Column ( db . DateTime ( ) ) <EOL> actual_start_time = db . Column ( db . DateTime ( ) ) <EOL> status = db . Column ( db . Enum ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , name = '<STR_LIT>' ) ) <EOL> title = db . Column ( db . String ( <NUM_LIT:200> ) ) <EOL> submissions = db . relationship ( '<STR_LIT>' , secondary = stream_submission , backref = db . backref ( '<STR_LIT>' , lazy = '<STR_LIT>' ) ) <EOL> streamer_id = db . Column ( '<STR_LIT>' , db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> streamer = db . relationship ( '<STR_LIT>' , backref = db . backref ( '<STR_LIT>' , lazy = '<STR_LIT>' ) ) <EOL> current_viewers = db . Column ( db . Integer ) <EOL> confstream = db . Column ( db . Boolean ( ) , default = False ) <EOL> __mapper_args__ = { <EOL> '<STR_LIT>' : type , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def format_start_time ( self , countdown = True , start_time = True ) : <EOL> if not self . scheduled_start_time or ( not countdown and not start_time ) : <EOL> return None <EOL> if countdown : <EOL> return humanize . naturaltime ( datetime . utcnow ( ) - self . scheduled_start_time ) + ( ( "<STR_LIT:U+002CU+0020>" + datetime . strftime ( self . scheduled_start_time , "<STR_LIT>" ) ) if start_time else "<STR_LIT>" ) <EOL> else : <EOL> return datetime . strftime ( self . scheduled_start_time , "<STR_LIT>" ) <EOL> def add_submission ( self , submission ) : <EOL> if submission not in self . submissions : <EOL> self . submissions . append ( submission ) <EOL> def _go_live ( self ) : <EOL> if self . status != '<STR_LIT>' and self . streamer and self . streamer . checked and ( self . streamer . last_time_notified is None or <EOL> ( datetime . utcnow ( ) - self . streamer . last_time_notified ) > timedelta ( hours = <NUM_LIT:1> ) ) : <EOL> self . streamer . need_to_notify_subscribers = True <EOL> self . status = '<STR_LIT>' <EOL> class WPCStream ( Stream ) : <EOL> channel_name = db . Column ( db . String ( <NUM_LIT:30> ) , unique = True ) <EOL> chat_anon_forbidden = db . Column ( db . Boolean , default = False ) <EOL> def __init__ ( self , channel_name ) : <EOL> self . status = '<STR_LIT>' <EOL> self . channel_name = channel_name <EOL> self . submissions = [ ] <EOL> def __eq__ ( self , other ) : <EOL> return type ( self ) == type ( other ) and self . channel_name == other . channel_name <EOL> def __hash__ ( self ) : <EOL> return hash ( self . channel_name ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . id , self . channel_name ) <EOL> def _update_status ( self ) : <EOL> app . logger . info ( "<STR_LIT>" . format ( self ) ) <EOL> r = requests_get_with_retries ( <EOL> "<STR_LIT>" . format ( <EOL> app . config [ '<STR_LIT>' ] , app . config [ '<STR_LIT>' ] , app . config [ '<STR_LIT>' ] ) ) <EOL> r . raise_for_status ( ) <EOL> soup = BeautifulSoup ( r . content , '<STR_LIT>' ) <EOL> for stream in soup . find_all ( '<STR_LIT>' ) : <EOL> if stream . find ( '<STR_LIT:name>' ) . string == self . channel_name : <EOL> client_num = int ( stream . find ( '<STR_LIT>' ) . string ) <EOL> is_live = stream . find ( '<STR_LIT>' ) <EOL> if is_live : <EOL> self . status = '<STR_LIT>' <EOL> self . current_viewers = client_num - <NUM_LIT:1> <EOL> if self . actual_start_time is None : <EOL> self . actual_start_time = datetime . utcnow ( ) <EOL> elif self . status == '<STR_LIT>' and ( self . actual_start_time is None or datetime . utcnow ( ) - self . actual_start_time > timedelta ( seconds = <NUM_LIT:30> ) ) : <EOL> self . status = '<STR_LIT>' <EOL> self . actual_start_time = None <EOL> self . current_viewers = None <EOL> break <EOL> else : <EOL> if self . status == '<STR_LIT>' and ( self . actual_start_time is None or datetime . utcnow ( ) - self . actual_start_time > timedelta ( seconds = <NUM_LIT:30> ) ) : <EOL> self . status = '<STR_LIT>' <EOL> self . actual_start_time = None <EOL> self . current_viewers = None <EOL> def normal_url ( self ) : <EOL> return url_for ( '<STR_LIT>' , streamer_name = self . streamer . reddit_username , _external = True ) <EOL> def html_code ( self , autoplay = False ) : <EOL> return render_template ( "<STR_LIT>" , <EOL> channel_name = self . channel_name , <EOL> autostart = ( "<STR_LIT:true>" if autoplay else "<STR_LIT:false>" ) , <EOL> offline_image_url = url_for ( "<STR_LIT>" , filename = "<STR_LIT>" ) , <EOL> rtmp_server = app . config [ '<STR_LIT>' ] ) <EOL> def _get_flair ( self ) : <EOL> fst = self . format_start_time ( start_time = False ) <EOL> status_to_flair = { "<STR_LIT>" : ( u"<STR_LIT>" , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( u"<STR_LIT>" , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( fst if fst else u"<STR_LIT>" , u"<STR_LIT>" ) , <EOL> None : ( None , None ) } <EOL> return status_to_flair [ self . status ] <EOL> def add_submission ( self , submission ) : <EOL> if submission not in self . submissions : <EOL> self . status = '<STR_LIT>' <EOL> self . scheduled_start_time = None <EOL> self . actual_start_time = None <EOL> Stream . add_submission ( self , submission ) <EOL> __mapper_args__ = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> class YoutubeChannel ( db . Model ) : <EOL> channel_id = db . Column ( db . String ( <NUM_LIT> ) , primary_key = True ) <EOL> title = db . Column ( db . String ( <NUM_LIT:30> ) ) <EOL> streams = db . relationship ( "<STR_LIT>" , backref = "<STR_LIT>" ) <EOL> streamer_id = db . Column ( '<STR_LIT>' , db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> streamer = db . relationship ( '<STR_LIT>' , uselist = False , backref = db . backref ( '<STR_LIT>' , uselist = False ) ) <EOL> def __init__ ( self , channel_id , title = None ) : <EOL> self . channel_id = channel_id <EOL> if title : <EOL> self . title = title <EOL> else : <EOL> r = requests_get_with_retries ( <EOL> "<STR_LIT>" . format ( <EOL> channel_id , app . config [ '<STR_LIT>' ] ) , retries_num = <NUM_LIT:15> ) <EOL> r . raise_for_status ( ) <EOL> for item in r . json ( ) [ '<STR_LIT>' ] : <EOL> self . title = item [ '<STR_LIT>' ] [ '<STR_LIT:title>' ] <EOL> def __eq__ ( self , other ) : <EOL> return type ( self ) == type ( other ) and self . channel_id == other . channel_id <EOL> def __hash__ ( self ) : <EOL> return hash ( self . channel_id ) <EOL> def __repr__ ( self ) : <EOL> return u'<STR_LIT>' . format ( self . channel_id , self . title ) <EOL> class YoutubeStream ( Stream ) : <EOL> ytid = db . Column ( db . String ( <NUM_LIT:11> ) , unique = True ) <EOL> vod_views = db . Column ( db . Integer ) <EOL> youtube_channel_id = db . Column ( db . String ( <NUM_LIT> ) , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> def __init__ ( self , ytid ) : <EOL> self . ytid = ytid <EOL> self . submissions = [ ] <EOL> def __eq__ ( self , other ) : <EOL> return type ( self ) == type ( other ) and self . ytid == other . ytid <EOL> def __hash__ ( self ) : <EOL> return hash ( self . ytid ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . id , self . ytid ) <EOL> def _update_vod_views ( self ) : <EOL> app . logger . info ( "<STR_LIT>" . format ( self ) ) <EOL> r = requests_get_with_retries ( <EOL> "<STR_LIT>" . format ( <EOL> self . ytid , app . config [ '<STR_LIT>' ] ) , retries_num = <NUM_LIT:15> ) <EOL> r . raise_for_status ( ) <EOL> for item in r . json ( ) [ '<STR_LIT>' ] : <EOL> self . vod_views = item [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> def _update_status ( self ) : <EOL> app . logger . info ( "<STR_LIT>" . format ( self ) ) <EOL> print "<STR_LIT>" . format ( self . ytid , app . config [ '<STR_LIT>' ] ) <EOL> r = requests_get_with_retries ( <EOL> "<STR_LIT>" . format ( <EOL> self . ytid , app . config [ '<STR_LIT>' ] ) , retries_num = <NUM_LIT:15> ) <EOL> r . raise_for_status ( ) <EOL> if not r . json ( ) [ '<STR_LIT>' ] : <EOL> self . status = '<STR_LIT>' <EOL> self . current_viewers = None <EOL> return <EOL> for item in r . json ( ) [ '<STR_LIT>' ] : <EOL> self . youtube_channel = get_or_create ( YoutubeChannel , <EOL> channel_id = item [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . youtube_channel . title = item [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if self . youtube_channel . streamer is not None : <EOL> self . streamer = self . youtube_channel . streamer <EOL> elif self . streamer is not None : <EOL> if not self . streamer . checked : <EOL> self . streamer . youtube_channel_class = self . youtube_channel <EOL> else : <EOL> self . streamer = None <EOL> self . title = item [ '<STR_LIT>' ] [ '<STR_LIT:title>' ] <EOL> if '<STR_LIT>' in item : <EOL> self . scheduled_start_time = item [ '<STR_LIT>' ] . get ( '<STR_LIT>' , None ) <EOL> if '<STR_LIT>' in item [ '<STR_LIT>' ] : <EOL> self . current_viewers = item [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if item [ '<STR_LIT>' ] [ '<STR_LIT>' ] == "<STR_LIT:none>" and not self . actual_start_time : <EOL> self . actual_start_time = item [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> if item [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> self . _go_live ( ) <EOL> if '<STR_LIT>' in item [ '<STR_LIT>' ] : <EOL> self . actual_start_time = item [ '<STR_LIT>' ] . get ( '<STR_LIT>' , None ) <EOL> else : <EOL> self . actual_start_time = item [ '<STR_LIT>' ] . get ( '<STR_LIT>' , None ) <EOL> elif item [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> self . status = '<STR_LIT>' <EOL> else : <EOL> self . status = '<STR_LIT>' <EOL> self . current_viewers = None <EOL> def _get_flair ( self ) : <EOL> fst = self . format_start_time ( start_time = False ) <EOL> status_to_flair = { "<STR_LIT>" : ( u"<STR_LIT>" , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( u"<STR_LIT>" , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( fst if fst else u"<STR_LIT>" , u"<STR_LIT>" ) , <EOL> None : ( None , None ) } <EOL> return status_to_flair [ self . status ] <EOL> def normal_url ( self ) : <EOL> return "<STR_LIT>" . format ( self . ytid ) <EOL> def html_code ( self , autoplay = False ) : <EOL> return """<STR_LIT>""" . format ( self . ytid , int ( autoplay ) ) <EOL> __mapper_args__ = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> class TwitchStream ( Stream ) : <EOL> channel = db . column_property ( db . Column ( db . String ( <NUM_LIT> ) , unique = True ) , comparator_factory = CaseInsensitiveComparator ) <EOL> last_time_live = db . Column ( db . DateTime ( ) ) <EOL> def __init__ ( self , channel ) : <EOL> self . channel = channel <EOL> self . status = '<STR_LIT>' <EOL> self . submissions = [ ] <EOL> def __eq__ ( self , other ) : <EOL> return type ( self ) == type ( other ) and self . channel == other . channel <EOL> def __hash__ ( self ) : <EOL> return hash ( self . channel ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . id , self . channel ) <EOL> def _update_title_from_channel ( self ) : <EOL> r = requests_get_with_retries ( "<STR_LIT>" . format ( self . channel ) ) <EOL> r . raise_for_status ( ) <EOL> stream = r . json ( ) <EOL> if stream is not None : <EOL> if stream [ '<STR_LIT:status>' ] is not None : <EOL> self . title = stream [ '<STR_LIT:status>' ] <EOL> def _update_status ( self ) : <EOL> app . logger . info ( "<STR_LIT>" . format ( self ) ) <EOL> streamer = Streamer . query . filter_by ( twitch_channel = self . channel ) . first ( ) <EOL> if streamer : <EOL> self . streamer = streamer <EOL> elif self . streamer is not None : <EOL> if self . streamer . twitch_channel is None and not self . streamer . checked : <EOL> self . streamer . twitch_channel = self . channel <EOL> else : <EOL> self . streamer = None <EOL> r = requests_get_with_retries ( "<STR_LIT>" . format ( self . channel ) ) <EOL> r . raise_for_status ( ) <EOL> stream = r . json ( ) [ '<STR_LIT>' ] <EOL> if stream is not None : <EOL> self . _go_live ( ) <EOL> if '<STR_LIT:status>' in stream [ '<STR_LIT>' ] : <EOL> self . title = stream [ '<STR_LIT>' ] [ '<STR_LIT:status>' ] <EOL> self . current_viewers = stream [ '<STR_LIT>' ] <EOL> self . last_time_live = datetime . utcnow ( ) <EOL> if self . actual_start_time is None : <EOL> self . actual_start_time = self . last_time_live <EOL> else : <EOL> if self . status == '<STR_LIT>' : <EOL> if datetime . utcnow ( ) - self . last_time_live > timedelta ( minutes = <NUM_LIT:12> ) : <EOL> self . status = '<STR_LIT>' <EOL> self . current_viewers = None <EOL> if self . status == '<STR_LIT>' : <EOL> self . _update_title_from_channel ( ) <EOL> def _get_flair ( self ) : <EOL> fst = self . format_start_time ( start_time = False ) <EOL> status_to_flair = { "<STR_LIT>" : ( u"<STR_LIT>" , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( u"<STR_LIT>" , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( fst if fst else u"<STR_LIT>" , u"<STR_LIT>" ) , <EOL> None : ( None , None ) } <EOL> return status_to_flair [ self . status ] <EOL> def add_submission ( self , submission ) : <EOL> if submission not in self . submissions : <EOL> self . status = '<STR_LIT>' <EOL> self . scheduled_start_time = None <EOL> self . actual_start_time = None <EOL> Stream . add_submission ( self , submission ) <EOL> def normal_url ( self ) : <EOL> return "<STR_LIT>" + self . channel <EOL> def html_code ( self , autoplay = False ) : <EOL> return """<STR_LIT>""" . format ( self . channel , self . channel , "<STR_LIT:true>" if autoplay else "<STR_LIT:false>" ) <EOL> __mapper_args__ = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> class MozillaStreamHack ( object ) : <EOL> def html_code ( self , autoplay = None ) : <EOL> return '''<STR_LIT>''' <EOL> def normal_url ( self ) : <EOL> return "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> self . id = <NUM_LIT:0> <EOL> self . current_viewers = None <EOL> self . streamer = Streamer . query . filter_by ( reddit_username = '<STR_LIT>' ) . one ( ) <EOL> class Subscriber ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> email = db . column_property ( db . Column ( db . String ( <NUM_LIT> ) , unique = True , nullable = False ) , comparator_factory = CaseInsensitiveComparator ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . id , self . email ) <EOL> def already_subscribed ( self , streamer ) : <EOL> return streamer and ( self in streamer . subscribers or self == streamer . as_subscriber ) <EOL> class Idea ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> description = db . Column ( db . Text ( ) , nullable = False ) <EOL> class ChatMessage ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> sent_on = db . Column ( db . DateTime , default = db . func . now ( ) ) <EOL> streamer = db . relationship ( '<STR_LIT>' , backref = db . backref ( '<STR_LIT>' , lazy = '<STR_LIT>' ) ) <EOL> streamer_id = db . Column ( '<STR_LIT>' , db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> sender = db . Column ( db . String ( ) ) <EOL> text = db . Column ( db . String ( ) ) <EOL> class Streamer ( db . Model , UserMixin ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> reddit_username = db . column_property ( db . Column ( db . String ( <NUM_LIT:20> ) , unique = True ) , comparator_factory = CaseInsensitiveComparator ) <EOL> twitch_channel = db . column_property ( db . Column ( db . String ( <NUM_LIT> ) , unique = True ) , comparator_factory = CaseInsensitiveComparator ) <EOL> info = db . Column ( db . Text ( ) ) <EOL> checked = db . Column ( db . Boolean ( ) , default = False ) <EOL> rtmp_secret = db . Column ( db . String ( <NUM_LIT:50> ) ) <EOL> test = db . Column ( db . Boolean ( ) , default = False ) <EOL> as_subscriber_id = db . Column ( '<STR_LIT>' , db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> as_subscriber = db . relationship ( '<STR_LIT>' , backref = db . backref ( '<STR_LIT>' ) ) <EOL> subscribers = db . relationship ( '<STR_LIT>' , secondary = streamer_subscriptions , lazy = '<STR_LIT>' , backref = db . backref ( '<STR_LIT>' , lazy = '<STR_LIT>' ) ) <EOL> need_to_notify_subscribers = db . Column ( db . Boolean , default = False ) <EOL> last_time_notified = db . Column ( db . DateTime ( ) ) <EOL> is_banned = db . Column ( db . Boolean ( ) , default = False ) <EOL> @ property <EOL> def youtube_channel ( self ) : <EOL> if self . youtube_channel_class is None : <EOL> return None <EOL> return self . youtube_channel_class . channel_id <EOL> @ youtube_channel . setter <EOL> def youtube_channel ( self , channel_id ) : <EOL> self . youtube_channel_class = get_or_create ( YoutubeChannel , channel_id = channel_id ) <EOL> @ youtube_channel . deleter <EOL> def youtube_channel ( self ) : <EOL> self . youtube_channel_class = None <EOL> rtmp_redirect_1 = db . Column ( db . String ( ) ) <EOL> rtmp_redirect_2 = db . Column ( db . String ( ) ) <EOL> rtmp_redirect_3 = db . Column ( db . String ( ) ) <EOL> def __init__ ( self , reddit_username , checked = False ) : <EOL> self . reddit_username = reddit_username <EOL> self . checked = checked <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . id , self . reddit_username ) <EOL> def get_id ( self ) : <EOL> return self . reddit_username <EOL> def already_subscribed ( self , another_streamer ) : <EOL> return another_streamer and ( another_streamer == self or ( self . as_subscriber and self . as_subscriber . already_subscribed ( another_streamer ) ) ) <EOL> def streaming_key ( self ) : <EOL> return self . reddit_username + '<STR_LIT>' + self . rtmp_secret <EOL> def generate_rtmp_stuff ( self ) : <EOL> self . rtmp_secret = str ( uuid . uuid4 ( ) ) <EOL> wpcs = get_or_create ( WPCStream , channel_name = current_user . reddit_username ) <EOL> current_user . streams . append ( wpcs ) <EOL> db . session . add ( wpcs ) <EOL> wpcs . status = '<STR_LIT>' if not wpcs . status else wpcs . status <EOL> db . session . commit ( ) <EOL> def populate_email ( self , email ) : <EOL> if not self . as_subscriber or len ( self . as_subscriber . as_streamer ) > <NUM_LIT:1> : <EOL> self . as_subscriber = get_or_create ( Subscriber , email = email ) <EOL> else : <EOL> alredy_existing_subscriber = Subscriber . query . filter_by ( email = email ) . first ( ) <EOL> if alredy_existing_subscriber : <EOL> db . session . delete ( self . as_subscriber ) <EOL> self . as_subscriber = alredy_existing_subscriber <EOL> else : <EOL> self . as_subscriber . email = email <EOL> def populate ( self , form ) : <EOL> self . info = form . info . data <EOL> tc = form . twitch_channel_extract ( ) <EOL> if tc != self . twitch_channel : <EOL> ts = self . streams . filter_by ( type = '<STR_LIT>' ) . first ( ) <EOL> if ts : <EOL> ts . streamer = None <EOL> streamer = Streamer . query . filter_by ( twitch_channel = tc ) . first ( ) <EOL> if streamer and streamer != current_user : <EOL> streamer . twitch_channel = None <EOL> for ts in streamer . streams . filter_by ( type = '<STR_LIT>' ) : <EOL> ts . streamer = self <EOL> self . twitch_channel = tc if tc else None <EOL> yc = get_or_create ( YoutubeChannel , channel_id = form . youtube_channel_extract ( ) ) <EOL> if yc != self . youtube_channel_class : <EOL> for ys in self . streams . filter_by ( type = '<STR_LIT>' ) : <EOL> ys . streamer = None <EOL> streamer = yc . streamer <EOL> if streamer and streamer != current_user : <EOL> del streamer . youtube_channel <EOL> for ys in yc . streams : <EOL> ys . streamer = self <EOL> self . youtube_channel_class = yc if yc else None </s>
