def page_not_found(e): sysSettings = settings.settings.query.first() system.newLog(0, "500 Error - " + str(request.url)) return render_template(themes.checkOverride('500.html'), sysSetting=sysSettings, previous=request.referrer, error=e), 500
def streamers_page(): sysSettings = settings.settings.query.first() streamerIDs = [] if sysSettings.showEmptyTables: for channel in db.session.query(Channel.Channel.owningUser).distinct(): if channel.owningUser not in streamerIDs: streamerIDs.append(channel.owningUser) else: openStreams = Stream.Stream.query.all() for stream in openStreams: if stream.channel.owningUser not in streamerIDs: streamerIDs.append(stream.channel.owningUser) for recordedVidInstance in db.session.query( RecordedVideo.RecordedVideo.owningUser).distinct(): if recordedVidInstance.owningUser not in streamerIDs: streamerIDs.append(recordedVidInstance.owningUser) streamerList = [] for userID in streamerIDs: userQuery = Sec.User.query.filter_by(id=userID).first() if userQuery is not None: streamerList.append(userQuery) return render_template(themes.checkOverride('streamers.html'), streamerList=streamerList)
def channels_page(): sysSettings = settings.settings.query.first() if sysSettings.showEmptyTables: channelList = Channel.Channel.query.all() else: channelList = [] for channel in Channel.Channel.query.all(): if len(channel.recordedVideo) > 0: channelList.append(channel) return render_template(themes.checkOverride('channels.html'), channelList=channelList)
def search_page(): if 'term' in request.form: search = str(request.form['term']) topicList = topics.topics.query.filter(topics.topics.name.contains(search)).all() streamerList = [] streamerList1 = Sec.User.query.filter(Sec.User.username.contains(search)).all() streamerList2 = Sec.User.query.filter(Sec.User.biography.contains(search)).all() for stream in streamerList1: if stream.has_role('Streamer'): streamerList.append(stream) for stream in streamerList2: if stream not in streamerList and stream.has_role('streamer'): streamerList.append(stream) channelList = [] channelList1 = Channel.Channel.query.filter(Channel.Channel.channelName.contains(search)).all() channelList2 = Channel.Channel.query.filter(Channel.Channel.description.contains(search)).all() for channel in channelList1: channelList.append(channel) for channel in channelList2: if channel not in channelList: channelList.append(channel) videoList = [] videoList1 = RecordedVideo.RecordedVideo.query.filter(RecordedVideo.RecordedVideo.channelName.contains(search)).filter(RecordedVideo.RecordedVideo.pending == False, RecordedVideo.RecordedVideo.published == True).all() videoList2 = RecordedVideo.RecordedVideo.query.filter(RecordedVideo.RecordedVideo.description.contains(search)).filter(RecordedVideo.RecordedVideo.pending == False, RecordedVideo.RecordedVideo.published == True).all() for video in videoList1: videoList.append(video) for video in videoList2: if video not in videoList: videoList.append(video) streamList = Stream.Stream.query.filter(Stream.Stream.streamName.contains(search)).all() clipList = [] clipList1 = RecordedVideo.Clips.query.filter(RecordedVideo.Clips.clipName.contains(search)).filter(RecordedVideo.Clips.published == True).all() clipList2 = RecordedVideo.Clips.query.filter(RecordedVideo.Clips.description.contains(search)).filter(RecordedVideo.Clips.published == True).all() for clip in clipList1: clipList.append(clip) for clip in clipList2: if clip not in clipList: clipList.append(clip) return render_template(themes.checkOverride('search.html'), topicList=topicList, streamerList=streamerList, channelList=channelList, videoList=videoList, streamList=streamList, clipList=clipList) return redirect(url_for('root.main_page'))
def topic_view_page(topicID): topicID = int(topicID) streamsQuery = Stream.Stream.query.filter_by(topic=topicID).all() recordedVideoQuery = RecordedVideo.RecordedVideo.query.filter_by(topic=topicID, pending=False, published=True).all() # Sort Video to Show Newest First recordedVideoQuery.sort(key=lambda x: x.videoDate, reverse=True) clipsList = [] for vid in recordedVideoQuery: for clip in vid.clips: if clip.published is True: clipsList.append(clip) clipsList.sort(key=lambda x: x.views, reverse=True) return render_template(themes.checkOverride('videoListView.html'), openStreams=streamsQuery, recordedVids=recordedVideoQuery, clipsList=clipsList, title="Topics - Videos")
def topic_page(): sysSettings = settings.settings.query.first() if sysSettings.showEmptyTables: topicsList = topics.topics.query.all() else: topicIDList = [] for streamInstance in db.session.query(Stream.Stream.topic).distinct(): topicIDList.append(streamInstance.topic) for recordedVidInstance in db.session.query(RecordedVideo.RecordedVideo.topic).distinct(): if recordedVidInstance.topic not in topicIDList: topicIDList.append(recordedVidInstance.topic) topicsList = [] for item in topicIDList: topicQuery = topics.topics.query.filter_by(id=item).first() if topicQuery is not None: topicsList.append(topicQuery) topicsList.sort(key=lambda x: x.name) return render_template(themes.checkOverride('topics.html'), topicsList=topicsList)
def channel_view_page(chanID): chanID = int(chanID) channelData = Channel.Channel.query.filter_by(id=chanID).first() if channelData is not None: openStreams = Stream.Stream.query.filter_by(linkedChannel=chanID).all() recordedVids = RecordedVideo.RecordedVideo.query.filter_by( channelID=chanID, pending=False, published=True).all() # Sort Video to Show Newest First recordedVids.sort(key=lambda x: x.videoDate, reverse=True) clipsList = [] for vid in recordedVids: for clip in vid.clips: if clip.published is True: clipsList.append(clip) clipsList.sort(key=lambda x: x.views, reverse=True) subState = False if current_user.is_authenticated: chanSubQuery = subscriptions.channelSubs.query.filter_by( channelID=channelData.id, userID=current_user.id).first() if chanSubQuery is not None: subState = True return render_template(themes.checkOverride('videoListView.html'), channelData=channelData, openStreams=openStreams, recordedVids=recordedVids, clipsList=clipsList, subState=subState, title="Channels - Videos") else: flash("No Such Channel", "error") return redirect(url_for("root.main_page"))
def streamers_view_page(userID): userID = int(userID) streamerQuery = Sec.User.query.filter_by(id=userID).first() if streamerQuery is not None: if streamerQuery.has_role('Streamer'): userChannels = Channel.Channel.query.filter_by( owningUser=userID).all() streams = [] for channel in userChannels: for stream in channel.stream: streams.append(stream) recordedVideoQuery = RecordedVideo.RecordedVideo.query.filter_by( owningUser=userID, pending=False, published=True).all() # Sort Video to Show Newest First recordedVideoQuery.sort(key=lambda x: x.videoDate, reverse=True) clipsList = [] for vid in recordedVideoQuery: for clip in vid.clips: if clip.published is True: clipsList.append(clip) clipsList.sort(key=lambda x: x.views, reverse=True) return render_template(themes.checkOverride('videoListView.html'), openStreams=streams, recordedVids=recordedVideoQuery, userChannels=userChannels, clipsList=clipsList, title=streamerQuery.username, streamerData=streamerQuery) flash('Invalid Streamer', 'error') return redirect(url_for("root.main_page"))
def oAuthAuthorize(provider): oAuthClient = oauth.create_client(provider) oAuthProviderQuery = settings.oAuthProvider.query.filter_by( name=provider).first() if oAuthProviderQuery is not None: try: token = oAuthClient.authorize_access_token() except: return redirect('/login') userData = oAuthClient.get(oAuthProviderQuery.profile_endpoint) userDataDict = userData.json() userQuery = Sec.User.query.filter_by( oAuthID=userDataDict[oAuthProviderQuery.id_value], oAuthProvider=provider, authType=1).first() # Default expiration time to 365 days into the future if 'expires_at' not in token: if 'expires_in' in token: token['expires_at'] = datetime.timedelta(seconds=int( token['exipires_in'])) + datetime.datetime.utcnow() else: token['expires_at'] = time() + (365 * 24 * 3600) # If oAuth ID, Provider, and Auth Type Match - Initiate Login if userQuery is not None: existingTokenQuery = Sec.OAuth2Token.query.filter_by( user=userQuery.id).all() for existingToken in existingTokenQuery: db.session.delete(existingToken) db.session.commit() newToken = None if 'refresh_token' in token: newToken = Sec.OAuth2Token(provider, token['token_type'], token['access_token'], token['refresh_token'], token['expires_at'], userQuery.id) else: newToken = Sec.OAuth2Token(provider, token['token_type'], token['access_token'], None, token['expires_at'], userQuery.id) db.session.add(newToken) db.session.commit() if userQuery.active is False: flash( "User has been Disabled. Please contact your administrator", "error") return redirect('/login') else: login_user(userQuery) if oAuthProviderQuery.preset_auth_type == "Discord": discord_processLogin(userDataDict, userQuery) elif oAuthProviderQuery.preset_auth_type == "Reddit": reddit_processLogin(userDataDict, userQuery) elif oAuthProviderQuery.preset_auth_type == "Facebook": facebook_processLogin(oAuthProviderQuery.api_base_url, userDataDict, userQuery) if userQuery.email is None or userQuery.email == 'None': flash("Please Add an Email Address to your User Profile", "error") return redirect(url_for('settings.user_page')) else: return redirect(url_for('root.main_page')) # If No Match, Determine if a User Needs to be created else: existingEmailQuery = None hasEmail = False if oAuthProviderQuery.email_value in userDataDict: existingEmailQuery = Sec.User.query.filter_by( email=userDataDict[ oAuthProviderQuery.email_value]).first() hasEmail = True else: flash("Please Add an Email Address to your User Profile", "error") # No Username Match - Create New User if existingEmailQuery is None: convertedUsername = userDataDict[ oAuthProviderQuery.username_value].replace(" ", "_") userDataDict[ oAuthProviderQuery.username_value] = convertedUsername existingUsernameQuery = Sec.User.query.filter_by( username=convertedUsername).first() requestedUsername = convertedUsername if existingUsernameQuery is not None: requestedUsername = requestedUsername + str( random.randint(1, 9999)) if hasEmail is True: user_datastore.create_user( email=userDataDict[oAuthProviderQuery.email_value], username=requestedUsername, active=True, confirmed_at=datetime.datetime.utcnow(), authType=1, oAuthID=userDataDict[oAuthProviderQuery.id_value], oAuthProvider=provider) else: user_datastore.create_user( email=None, username=requestedUsername, active=True, confirmed_at=datetime.datetime.utcnow(), authType=1, oAuthID=userDataDict[oAuthProviderQuery.id_value], oAuthProvider=provider) db.session.commit() user = Sec.User.query.filter_by( username=requestedUsername).first() defaultRoleQuery = Sec.Role.query.filter_by(default=True) for role in defaultRoleQuery: user_datastore.add_role_to_user(user, role.name) user.uuid = str(uuid.uuid4()) user.xmppToken = str(os.urandom(32).hex()) if oAuthProviderQuery.preset_auth_type == "Discord": discord_processLogin(userDataDict, user) elif oAuthProviderQuery.preset_auth_type == "Reddit": reddit_processLogin(userDataDict, user) elif oAuthProviderQuery.preset_auth_type == "Facebook": facebook_processLogin(oAuthProviderQuery.api_base_url, userDataDict, user) newToken = None if 'refresh_token' in token: newToken = Sec.OAuth2Token(provider, token['token_type'], token['access_token'], token['refresh_token'], token['expires_at'], user.id) else: newToken = Sec.OAuth2Token(provider, token['token_type'], token['access_token'], None, token['expires_at'], user.id) db.session.add(newToken) db.session.commit() login_user(user) runWebhook("ZZZ", 20, user=user.username) newLog( 1, "A New User has Registered - Username:"******"An existing OAuth User exists under this email address with another provider", "error") return redirect('/')
def view_page(loc): sysSettings = settings.settings.query.first() xmppserver = sysSettings.siteAddress if ejabberdServer != "127.0.0.1" and ejabberdServer != "localhost": xmppserver = ejabberdServer requestedChannel = Channel.Channel.query.filter_by(channelLoc=loc).first() if requestedChannel is not None: if requestedChannel.protected and sysSettings.protectionEnabled: if not securityFunc.check_isValidChannelViewer( requestedChannel.id): return render_template( themes.checkOverride('channelProtectionAuth.html')) # Pull ejabberd Chat Options for Room #from app import ejabberd #chatOptions = ejabberd.get_room_options(requestedChannel.channelLoc, 'conference.' + sysSettings.siteAddress) #for option in chatOptions: # print(option) # Generate CSV String for Banned Chat List bannedWordQuery = banList.chatBannedWords.query.all() bannedWordArray = [] for bannedWord in bannedWordQuery: bannedWordArray.append(bannedWord.word) streamData = Stream.Stream.query.filter_by( streamKey=requestedChannel.streamKey).first() streamURL = '' edgeQuery = settings.edgeStreamer.query.filter_by(active=True).all() if edgeQuery == []: if sysSettings.adaptiveStreaming is True: streamURL = '/live-adapt/' + requestedChannel.channelLoc + '.m3u8' else: streamURL = '/live/' + requestedChannel.channelLoc + '/index.m3u8' else: # Handle Selecting the Node using Round Robin Logic if sysSettings.adaptiveStreaming is True: streamURL = '/edge-adapt/' + requestedChannel.channelLoc + '.m3u8' else: streamURL = '/edge/' + requestedChannel.channelLoc + '/index.m3u8' topicList = topics.topics.query.all() chatOnly = request.args.get("chatOnly") if chatOnly == "True" or chatOnly == "true": if requestedChannel.chatEnabled: hideBar = False hideBarReq = request.args.get("hideBar") if hideBarReq == "True" or hideBarReq == "true": hideBar = True guestUser = None if 'guestUser' in request.args and current_user.is_authenticated is False: guestUser = request.args.get("guestUser") userQuery = Sec.User.query.filter_by( username=guestUser).first() if userQuery is not None: flash("Invalid User", "error") return (redirect(url_for("root.main_page"))) return render_template(themes.checkOverride('chatpopout.html'), stream=streamData, streamURL=streamURL, sysSettings=sysSettings, channel=requestedChannel, hideBar=hideBar, guestUser=guestUser, xmppserver=xmppserver, bannedWords=bannedWordArray) else: flash("Chat is Not Enabled For This Stream", "error") isEmbedded = request.args.get("embedded") requestedChannel = Channel.Channel.query.filter_by( channelLoc=loc).first() if isEmbedded is None or isEmbedded == "False" or isEmbedded == "false": secureHash = None rtmpURI = None endpoint = 'live' if requestedChannel.protected: if current_user.is_authenticated: secureHash = None if current_user.authType == 0: secureHash = hashlib.sha256( (current_user.username + requestedChannel.channelLoc + current_user.password ).encode('utf-8')).hexdigest() else: secureHash = hashlib.sha256(( current_user.username + requestedChannel.channelLoc + current_user.oAuthID).encode('utf-8')).hexdigest() username = current_user.username rtmpURI = 'rtmp://' + sysSettings.siteAddress + ":1935/" + endpoint + "/" + requestedChannel.channelLoc + "?username="******"&hash=" + secureHash else: # TODO Add method for Unauthenticated Guest Users with an invite code to view RTMP rtmpURI = 'rtmp://' + sysSettings.siteAddress + ":1935/" + endpoint + "/" + requestedChannel.channelLoc else: rtmpURI = 'rtmp://' + sysSettings.siteAddress + ":1935/" + endpoint + "/" + requestedChannel.channelLoc clipsList = [] for vid in requestedChannel.recordedVideo: for clip in vid.clips: if clip.published is True: clipsList.append(clip) clipsList.sort(key=lambda x: x.views, reverse=True) subState = False if current_user.is_authenticated: chanSubQuery = subscriptions.channelSubs.query.filter_by( channelID=requestedChannel.id, userID=current_user.id).first() if chanSubQuery is not None: subState = True return render_template(themes.checkOverride('channelplayer.html'), stream=streamData, streamURL=streamURL, topics=topicList, channel=requestedChannel, clipsList=clipsList, subState=subState, secureHash=secureHash, rtmpURI=rtmpURI, xmppserver=xmppserver, bannedWords=bannedWordArray) else: isAutoPlay = request.args.get("autoplay") if isAutoPlay is None: isAutoPlay = False elif isAutoPlay.lower() == 'true': isAutoPlay = True else: isAutoPlay = False countViewers = request.args.get("countViewers") if countViewers is None: countViewers = True elif countViewers.lower() == 'false': countViewers = False else: countViewers = False return render_template( themes.checkOverride('channelplayer_embed.html'), channel=requestedChannel, stream=streamData, streamURL=streamURL, topics=topicList, isAutoPlay=isAutoPlay, countViewers=countViewers, xmppserver=xmppserver) else: flash("No Live Stream at URL", "error") return redirect(url_for("root.main_page"))
def main_page(): firstRunCheck = system.check_existing_settings() if firstRunCheck is False: return render_template('/firstrun.html') else: sysSettings = settings.settings.query.first() activeStreams = Stream.Stream.query.order_by( Stream.Stream.currentViewers).all() recordedQuery = None clipQuery = None # Sort by Most Views if sysSettings.sortMainBy == 0: recordedQuery = RecordedVideo.RecordedVideo.query.filter_by(pending=False, published=True) \ .join(Channel.Channel, RecordedVideo.RecordedVideo.channelID == Channel.Channel.id) \ .join(Sec.User, RecordedVideo.RecordedVideo.owningUser == Sec.User.id) \ .with_entities(RecordedVideo.RecordedVideo.id, RecordedVideo.RecordedVideo.owningUser, RecordedVideo.RecordedVideo.views, RecordedVideo.RecordedVideo.length, RecordedVideo.RecordedVideo.thumbnailLocation, RecordedVideo.RecordedVideo.channelName, RecordedVideo.RecordedVideo.topic, RecordedVideo.RecordedVideo.videoDate, Sec.User.pictureLocation, Channel.Channel.protected, Channel.Channel.channelName.label('ChanName')) \ .order_by(RecordedVideo.RecordedVideo.views.desc()).limit(16) clipQuery = RecordedVideo.Clips.query.filter_by(published=True) \ .join(RecordedVideo.RecordedVideo, RecordedVideo.Clips.parentVideo == RecordedVideo.RecordedVideo.id) \ .join(Channel.Channel, Channel.Channel.id == RecordedVideo.RecordedVideo.channelID) \ .join(Sec.User, Sec.User.id == Channel.Channel.owningUser) \ .with_entities(RecordedVideo.Clips.id, RecordedVideo.Clips.thumbnailLocation, Channel.Channel.owningUser, RecordedVideo.Clips.views, RecordedVideo.Clips.length, RecordedVideo.Clips.clipName, Channel.Channel.protected, Channel.Channel.channelName, RecordedVideo.RecordedVideo.topic, RecordedVideo.RecordedVideo.videoDate, Sec.User.pictureLocation) \ .order_by(RecordedVideo.Clips.views.desc()).limit(16) # Sort by Most Recent elif sysSettings.sortMainBy == 1: recordedQuery = RecordedVideo.RecordedVideo.query.filter_by(pending=False, published=True) \ .join(Channel.Channel, RecordedVideo.RecordedVideo.channelID == Channel.Channel.id) \ .join(Sec.User, RecordedVideo.RecordedVideo.owningUser == Sec.User.id) \ .with_entities(RecordedVideo.RecordedVideo.id, RecordedVideo.RecordedVideo.owningUser, RecordedVideo.RecordedVideo.views, RecordedVideo.RecordedVideo.length, RecordedVideo.RecordedVideo.thumbnailLocation, RecordedVideo.RecordedVideo.channelName, RecordedVideo.RecordedVideo.topic, RecordedVideo.RecordedVideo.videoDate, Sec.User.pictureLocation, Channel.Channel.protected, Channel.Channel.channelName.label('ChanName')) \ .order_by(RecordedVideo.RecordedVideo.videoDate.desc()).limit(16) clipQuery = RecordedVideo.Clips.query.filter_by(published=True) \ .join(RecordedVideo.RecordedVideo, RecordedVideo.Clips.parentVideo == RecordedVideo.RecordedVideo.id) \ .join(Channel.Channel, Channel.Channel.id == RecordedVideo.RecordedVideo.channelID) \ .join(Sec.User, Sec.User.id == Channel.Channel.owningUser) \ .with_entities(RecordedVideo.Clips.id, RecordedVideo.Clips.thumbnailLocation, Channel.Channel.owningUser, RecordedVideo.Clips.views, RecordedVideo.Clips.length, RecordedVideo.Clips.clipName, Channel.Channel.protected, Channel.Channel.channelName, RecordedVideo.RecordedVideo.topic, RecordedVideo.RecordedVideo.videoDate, Sec.User.pictureLocation) \ .order_by(RecordedVideo.RecordedVideo.videoDate.desc()).limit(16) # Sort by Random elif sysSettings.sortMainBy == 2: recordedQuery = RecordedVideo.RecordedVideo.query.filter_by(pending=False, published=True)\ .join(Channel.Channel, RecordedVideo.RecordedVideo.channelID == Channel.Channel.id)\ .join(Sec.User, RecordedVideo.RecordedVideo.owningUser == Sec.User.id)\ .with_entities(RecordedVideo.RecordedVideo.id, RecordedVideo.RecordedVideo.owningUser, RecordedVideo.RecordedVideo.views, RecordedVideo.RecordedVideo.length, RecordedVideo.RecordedVideo.thumbnailLocation, RecordedVideo.RecordedVideo.channelName, RecordedVideo.RecordedVideo.topic, RecordedVideo.RecordedVideo.videoDate, Sec.User.pictureLocation, Channel.Channel.protected, Channel.Channel.channelName.label('ChanName'))\ .order_by(func.random()).limit(16) clipQuery = RecordedVideo.Clips.query.filter_by(published=True)\ .join(RecordedVideo.RecordedVideo, RecordedVideo.Clips.parentVideo == RecordedVideo.RecordedVideo.id)\ .join(Channel.Channel, Channel.Channel.id==RecordedVideo.RecordedVideo.channelID)\ .join(Sec.User, Sec.User.id == Channel.Channel.owningUser)\ .with_entities(RecordedVideo.Clips.id, RecordedVideo.Clips.thumbnailLocation, Channel.Channel.owningUser, RecordedVideo.Clips.views, RecordedVideo.Clips.length, RecordedVideo.Clips.clipName, Channel.Channel.protected, Channel.Channel.channelName, RecordedVideo.RecordedVideo.topic, RecordedVideo.RecordedVideo.videoDate, Sec.User.pictureLocation)\ .order_by(func.random()).limit(16) # Fall Through - Sort by Views else: if sysSettings.sortMainBy == 0: recordedQuery = RecordedVideo.RecordedVideo.query.filter_by(pending=False, published=True) \ .join(Channel.Channel, RecordedVideo.RecordedVideo.channelID == Channel.Channel.id) \ .join(Sec.User, RecordedVideo.RecordedVideo.owningUser == Sec.User.id) \ .with_entities(RecordedVideo.RecordedVideo.id, RecordedVideo.RecordedVideo.owningUser, RecordedVideo.RecordedVideo.views, RecordedVideo.RecordedVideo.length, RecordedVideo.RecordedVideo.thumbnailLocation, RecordedVideo.RecordedVideo.channelName, RecordedVideo.RecordedVideo.topic, RecordedVideo.RecordedVideo.videoDate, Sec.User.pictureLocation, Channel.Channel.protected, Channel.Channel.channelName.label('ChanName')) \ .order_by(RecordedVideo.RecordedVideo.views.desc()).limit(16) clipQuery = RecordedVideo.Clips.query.filter_by(published=True) \ .join(RecordedVideo.RecordedVideo, RecordedVideo.Clips.parentVideo == RecordedVideo.RecordedVideo.id) \ .join(Channel.Channel, Channel.Channel.id == RecordedVideo.RecordedVideo.channelID) \ .join(Sec.User, Sec.User.id == Channel.Channel.owningUser) \ .with_entities(RecordedVideo.Clips.id, RecordedVideo.Clips.thumbnailLocation, Channel.Channel.owningUser, RecordedVideo.Clips.views, RecordedVideo.Clips.length, RecordedVideo.Clips.clipName, Channel.Channel.protected, Channel.Channel.channelName, RecordedVideo.RecordedVideo.topic, RecordedVideo.RecordedVideo.videoDate, Sec.User.pictureLocation) \ .order_by(RecordedVideo.Clips.views.desc()).limit(16) return render_template(themes.checkOverride('index.html'), streamList=activeStreams, videoList=recordedQuery, clipList=clipQuery)
def notification_page(): notificationQuery = notifications.userNotification.query.filter_by( userID=current_user.id, read=False).order_by(notifications.userNotification.timestamp.desc()) return render_template(themes.checkOverride('notifications.html'), notificationList=notificationQuery)
def view_vid_page(videoID): sysSettings = settings.settings.query.first() videos_root = globalvars.videoRoot + 'videos/' recordedVid = RecordedVideo.RecordedVideo.query.filter_by( id=videoID).first() if recordedVid is not None: if recordedVid.published is False: if current_user.is_authenticated: if current_user != recordedVid.owningUser and current_user.has_role( 'Admin') is False: flash("No Such Video at URL", "error") return redirect(url_for("root.main_page")) else: flash("No Such Video at URL", "error") return redirect(url_for("root.main_page")) if recordedVid.channel.protected and sysSettings.protectionEnabled: if not securityFunc.check_isValidChannelViewer( recordedVid.channel.id): return render_template( themes.checkOverride('channelProtectionAuth.html')) # Check if the file exists in location yet and redirect if not ready if path.exists(videos_root + recordedVid.videoLocation) is False: return render_template(themes.checkOverride('notready.html'), video=recordedVid) # Check if the DB entry for the video has a length, if not try to determine or fail if recordedVid.length is None: fullVidPath = videos_root + recordedVid.videoLocation duration = None try: duration = videoFunc.getVidLength(fullVidPath) except: return render_template(themes.checkOverride('notready.html'), video=recordedVid) recordedVid.length = duration db.session.commit() recordedVid.views = recordedVid.views + 1 recordedVid.channel.views = recordedVid.channel.views + 1 topicList = topics.topics.query.all() streamURL = '/videos/' + recordedVid.videoLocation isEmbedded = request.args.get("embedded") newView = views.views(1, recordedVid.id) db.session.add(newView) db.session.commit() # Function to allow custom start time on Video startTime = None if 'startTime' in request.args: startTime = request.args.get("startTime") try: startTime = float(startTime) except: startTime = None if isEmbedded is None or isEmbedded == "False": randomRecorded = RecordedVideo.RecordedVideo.query.filter( RecordedVideo.RecordedVideo.pending == False, RecordedVideo.RecordedVideo.id != recordedVid.id, RecordedVideo.RecordedVideo.published == True).order_by( func.random()).limit(12) subState = False if current_user.is_authenticated: chanSubQuery = subscriptions.channelSubs.query.filter_by( channelID=recordedVid.channel.id, userID=current_user.id).first() if chanSubQuery is not None: subState = True return render_template(themes.checkOverride('vidplayer.html'), video=recordedVid, streamURL=streamURL, topics=topicList, randomRecorded=randomRecorded, subState=subState, startTime=startTime) else: isAutoPlay = request.args.get("autoplay") if isAutoPlay is None: isAutoPlay = False elif isAutoPlay.lower() == 'true': isAutoPlay = True else: isAutoPlay = False return render_template( themes.checkOverride('vidplayer_embed.html'), video=recordedVid, streamURL=streamURL, topics=topicList, isAutoPlay=isAutoPlay, startTime=startTime) else: flash("No Such Video at URL", "error") return redirect(url_for("root.main_page"))
def view_page(loc): sysSettings = settings.settings.query.first() xmppserver = sysSettings.siteAddress if ejabberdServer != "127.0.0.1" and ejabberdServer != "localhost": xmppserver = ejabberdServer requestedChannel = Channel.Channel.query.filter_by(channelLoc=loc).first() if requestedChannel is not None: if requestedChannel.protected and sysSettings.protectionEnabled: if not securityFunc.check_isValidChannelViewer( requestedChannel.id): return render_template( themes.checkOverride('channelProtectionAuth.html')) # Pull ejabberd Chat Options for Room #from app import ejabberd #chatOptions = ejabberd.get_room_options(requestedChannel.channelLoc, 'conference.' + sysSettings.siteAddress) #for option in chatOptions: # print(option) # Generate CSV String for Banned Chat List bannedWordQuery = banList.chatBannedWords.query.all() bannedWordArray = [] for bannedWord in bannedWordQuery: bannedWordArray.append(bannedWord.word) streamData = Stream.Stream.query.filter_by( streamKey=requestedChannel.streamKey).first() # Stream URL Generation streamURL = '' edgeQuery = settings.edgeStreamer.query.filter_by(active=True).all() if sysSettings.proxyFQDN != None: if sysSettings.adaptiveStreaming is True: streamURL = '/proxy-adapt/' + requestedChannel.channelLoc + '.m3u8' else: streamURL = '/proxy/' + requestedChannel.channelLoc + '/index.m3u8' elif edgeQuery != []: # Handle Selecting the Node using Round Robin Logic if sysSettings.adaptiveStreaming is True: streamURL = '/edge-adapt/' + requestedChannel.channelLoc + '.m3u8' else: streamURL = '/edge/' + requestedChannel.channelLoc + '/index.m3u8' else: if sysSettings.adaptiveStreaming is True: streamURL = '/live-adapt/' + requestedChannel.channelLoc + '.m3u8' else: streamURL = '/live/' + requestedChannel.channelLoc + '/index.m3u8' topicList = topics.topics.query.all() chatOnly = request.args.get("chatOnly") # Grab List of Stickers for Chat stickerList = [] stickerSelectorList = {'builtin': [], 'global': [], 'channel': []} # Build Built-In Stickers builtinStickerList = [{ 'name': 'oe-angry', 'filename': 'angry.png' }, { 'name': 'oe-smiling', 'filename': 'smiling.png' }, { 'name': 'oe-surprised', 'filename': 'surprised.png' }, { 'name': 'oe-cry', 'filename': 'cry.png' }, { 'name': 'oe-frown', 'filename': 'frown.png' }, { 'name': 'oe-laugh', 'filename': 'laugh.png' }, { 'name': 'oe-think', 'filename': 'thinking.png' }, { 'name': 'oe-thumbsup', 'filename': 'thumbsup.png' }, { 'name': 'oe-thumbsdown', 'filename': 'thumbsdown.png' }, { 'name': 'oe-heart', 'filename': 'heart.png' }, { 'name': 'oe-star', 'filename': 'star.png' }, { 'name': 'oe-fire', 'filename': 'fire.png' }, { 'name': 'oe-checkmark', 'filename': 'checkmark.png' }] for sticker in builtinStickerList: newSticker = { 'name': sticker['name'], 'file': '/static/img/stickers/' + sticker['filename'], 'category': 'builtin' } stickerList.append(newSticker) stickerSelectorList['builtin'].append(newSticker) # Build Global Stickers stickerQuery = stickers.stickers.query.filter_by(channelID=None).all() for sticker in stickerQuery: category = 'global' stickerFolder = "/images/stickers/" newSticker = { 'name': sticker.name, 'file': stickerFolder + sticker.filename, 'category': category } stickerList.append(newSticker) stickerSelectorList[category].append(newSticker) # Build Channel Stickers stickerQuery = stickers.stickers.query.filter_by( channelID=requestedChannel.id).all() for sticker in stickerQuery: category = 'channel' stickerFolder = "/images/stickers/" + requestedChannel.channelLoc + "/" newSticker = { 'name': sticker.name, 'file': stickerFolder + sticker.filename, 'category': category } stickerList.append(newSticker) stickerSelectorList[category].append(newSticker) if chatOnly == "True" or chatOnly == "true": if requestedChannel.chatEnabled: hideBar = False hideBarReq = request.args.get("hideBar") if hideBarReq == "True" or hideBarReq == "true": hideBar = True guestUser = None if 'guestUser' in request.args and current_user.is_authenticated is False: guestUser = request.args.get("guestUser") userQuery = Sec.User.query.filter_by( username=guestUser).first() if userQuery is not None: flash("Invalid User", "error") return (redirect(url_for("root.main_page"))) return render_template(themes.checkOverride('chatpopout.html'), stream=streamData, streamURL=streamURL, sysSettings=sysSettings, channel=requestedChannel, hideBar=hideBar, guestUser=guestUser, xmppserver=xmppserver, stickerList=stickerList, stickerSelectorList=stickerSelectorList, bannedWords=bannedWordArray) else: flash("Chat is Not Enabled For This Stream", "error") isEmbedded = request.args.get("embedded") #requestedChannel = Channel.Channel.query.filter_by(channelLoc=loc).first() if isEmbedded is None or isEmbedded == "False" or isEmbedded == "false": secureHash = None rtmpURI = None endpoint = 'live' if requestedChannel.protected: if current_user.is_authenticated: secureHash = None if current_user.authType == 0: secureHash = hashlib.sha256( (current_user.username + requestedChannel.channelLoc + current_user.password ).encode('utf-8')).hexdigest() else: secureHash = hashlib.sha256(( current_user.username + requestedChannel.channelLoc + current_user.oAuthID).encode('utf-8')).hexdigest() username = current_user.username rtmpURI = 'rtmp://' + sysSettings.siteAddress + ":1935/" + endpoint + "/" + requestedChannel.channelLoc + "?username="******"&hash=" + secureHash else: # TODO Add method for Unauthenticated Guest Users with an invite code to view RTMP rtmpURI = 'rtmp://' + sysSettings.siteAddress + ":1935/" + endpoint + "/" + requestedChannel.channelLoc else: rtmpURI = 'rtmp://' + sysSettings.siteAddress + ":1935/" + endpoint + "/" + requestedChannel.channelLoc clipsList = [] for vid in requestedChannel.recordedVideo: for clip in vid.clips: if clip.published is True: clipsList.append(clip) clipsList.sort(key=lambda x: x.views, reverse=True) subState = False if current_user.is_authenticated: chanSubQuery = subscriptions.channelSubs.query.filter_by( channelID=requestedChannel.id, userID=current_user.id).first() if chanSubQuery is not None: subState = True return render_template(themes.checkOverride('channelplayer.html'), stream=streamData, streamURL=streamURL, topics=topicList, channel=requestedChannel, clipsList=clipsList, subState=subState, secureHash=secureHash, rtmpURI=rtmpURI, xmppserver=xmppserver, stickerList=stickerList, stickerSelectorList=stickerSelectorList, bannedWords=bannedWordArray) else: isAutoPlay = request.args.get("autoplay") if isAutoPlay is None: isAutoPlay = False elif isAutoPlay.lower() == 'true': isAutoPlay = True else: isAutoPlay = False countViewers = request.args.get("countViewers") if countViewers is None: countViewers = True elif countViewers.lower() == 'false': countViewers = False else: countViewers = False return render_template( themes.checkOverride('channelplayer_embed.html'), channel=requestedChannel, stream=streamData, streamURL=streamURL, topics=topicList, isAutoPlay=isAutoPlay, countViewers=countViewers, xmppserver=xmppserver) else: flash("No Live Stream at URL", "error") return redirect(url_for("root.main_page"))
def view_clip_page(clipID): sysSettings = settings.settings.query.first() videos_root = globalvars.videoRoot + 'videos/' clipQuery = RecordedVideo.Clips.query.filter_by(id=int(clipID)).first() if clipQuery is not None: recordedVid = RecordedVideo.RecordedVideo.query.filter_by( id=clipQuery.recordedVideo.id).first() if clipQuery.published is False: if current_user.is_authenticated: if current_user != clipQuery.recordedVideo.owningUser and current_user.has_role( 'Admin') is False: flash("No Such Video at URL", "error") return redirect(url_for("root.main_page")) else: flash("No Such Video at URL", "error") return redirect(url_for("root.main_page")) if recordedVid.channel.protected and sysSettings.protectionEnabled: if not securityFunc.check_isValidChannelViewer( clipQuery.recordedVideo.channel.id): return render_template( themes.checkOverride('channelProtectionAuth.html')) if recordedVid is not None: clipQuery.views = clipQuery.views + 1 clipQuery.recordedVideo.channel.views = clipQuery.recordedVideo.channel.views + 1 if recordedVid.length is None: fullVidPath = videos_root + recordedVid.videoLocation duration = videoFunc.getVidLength(fullVidPath) recordedVid.length = duration db.session.commit() topicList = topics.topics.query.all() streamURL = '/videos/' + clipQuery.videoLocation isEmbedded = request.args.get("embedded") if isEmbedded is None or isEmbedded == "False": randomClips = RecordedVideo.Clips.query.filter( RecordedVideo.Clips.id != clipQuery.id).filter( RecordedVideo.Clips.published == True).order_by( func.random()).limit(12) subState = False if current_user.is_authenticated: chanSubQuery = subscriptions.channelSubs.query.filter_by( channelID=recordedVid.channel.id, userID=current_user.id).first() if chanSubQuery is not None: subState = True return render_template(themes.checkOverride('clipplayer.html'), video=recordedVid, streamURL=streamURL, topics=topicList, randomClips=randomClips, subState=subState, clip=clipQuery) #else: # isAutoPlay = request.args.get("autoplay") # if isAutoPlay == None: # isAutoPlay = False # elif isAutoPlay.lower() == 'true': # isAutoPlay = True # else: # isAutoPlay = False # return render_template(themes.checkOverride('vidplayer_embed.html'), video=recordedVid, streamURL=streamURL, topics=topicList, isAutoPlay=isAutoPlay, startTime=startTime) else: flash("No Such Clip at URL", "error") return redirect(url_for("root.main_page"))
def view_page(loc): sysSettings = settings.settings.query.first() requestedChannel = Channel.Channel.query.filter_by(channelLoc=loc).first() if requestedChannel is not None: if requestedChannel.protected and sysSettings.protectionEnabled: if not securityFunc.check_isValidChannelViewer( requestedChannel.id): return render_template( themes.checkOverride('channelProtectionAuth.html')) streamData = Stream.Stream.query.filter_by( streamKey=requestedChannel.streamKey).first() streamURL = '' edgeQuery = settings.edgeStreamer.query.filter_by(active=True).all() if edgeQuery == []: if sysSettings.adaptiveStreaming is True: streamURL = '/live-adapt/' + requestedChannel.channelLoc + '.m3u8' else: streamURL = '/live/' + requestedChannel.channelLoc + '/index.m3u8' else: # Handle Selecting the Node using Round Robin Logic if sysSettings.adaptiveStreaming is True: streamURL = '/edge-adapt/' + requestedChannel.channelLoc + '.m3u8' else: streamURL = '/edge/' + requestedChannel.channelLoc + '/index.m3u8' requestedChannel.views = requestedChannel.views + 1 if streamData is not None: streamData.totalViewers = streamData.totalViewers + 1 db.session.commit() topicList = topics.topics.query.all() chatOnly = request.args.get("chatOnly") if chatOnly == "True" or chatOnly == "true": if requestedChannel.chatEnabled: hideBar = False hideBarReq = request.args.get("hideBar") if hideBarReq == "True" or hideBarReq == "true": hideBar = True guestUser = None if 'guestUser' in request.args and current_user.is_authenticated is False: guestUser = request.args.get("guestUser") userQuery = Sec.User.query.filter_by( username=guestUser).first() if userQuery is not None: flash("Invalid User", "error") return (redirect(url_for("root.main_page"))) return render_template(themes.checkOverride('chatpopout.html'), stream=streamData, streamURL=streamURL, sysSettings=sysSettings, channel=requestedChannel, hideBar=hideBar, guestUser=guestUser) else: flash("Chat is Not Enabled For This Stream", "error") isEmbedded = request.args.get("embedded") newView = views.views(0, requestedChannel.id) db.session.add(newView) db.session.commit() requestedChannel = Channel.Channel.query.filter_by( channelLoc=loc).first() if isEmbedded is None or isEmbedded == "False" or isEmbedded == "false": secureHash = None rtmpURI = None endpoint = 'live' if requestedChannel.protected: if current_user.is_authenticated: secureHash = None if current_user.authType == 0: secureHash = hashlib.sha256( (current_user.username + requestedChannel.channelLoc + current_user.password ).encode('utf-8')).hexdigest() else: secureHash = hashlib.sha256(( current_user.username + requestedChannel.channelLoc + current_user.oAuthID).encode('utf-8')).hexdigest() username = current_user.username rtmpURI = 'rtmp://' + sysSettings.siteAddress + ":1935/" + endpoint + "/" + requestedChannel.channelLoc + "?username="******"&hash=" + secureHash else: rtmpURI = 'rtmp://' + sysSettings.siteAddress + ":1935/" + endpoint + "/" + requestedChannel.channelLoc clipsList = [] for vid in requestedChannel.recordedVideo: for clip in vid.clips: if clip.published is True: clipsList.append(clip) clipsList.sort(key=lambda x: x.views, reverse=True) subState = False if current_user.is_authenticated: chanSubQuery = subscriptions.channelSubs.query.filter_by( channelID=requestedChannel.id, userID=current_user.id).first() if chanSubQuery is not None: subState = True return render_template(themes.checkOverride('channelplayer.html'), stream=streamData, streamURL=streamURL, topics=topicList, channel=requestedChannel, clipsList=clipsList, subState=subState, secureHash=secureHash, rtmpURI=rtmpURI) else: isAutoPlay = request.args.get("autoplay") if isAutoPlay is None: isAutoPlay = False elif isAutoPlay.lower() == 'true': isAutoPlay = True else: isAutoPlay = False countViewers = request.args.get("countViewers") if countViewers is None: countViewers = True elif countViewers.lower() == 'false': countViewers = False else: countViewers = False return render_template( themes.checkOverride('channelplayer_embed.html'), channel=requestedChannel, stream=streamData, streamURL=streamURL, topics=topicList, isAutoPlay=isAutoPlay, countViewers=countViewers) else: flash("No Live Stream at URL", "error") return redirect(url_for("root.main_page"))