def handle_new_viewer(streamData):
    channelLoc = str(streamData['data'])

    sysSettings = settings.settings.query.first()

    requestedChannel = Channel.Channel.query.filter_by(channelLoc=channelLoc).first()
    stream = Stream.Stream.query.filter_by(streamKey=requestedChannel.streamKey).first()

    currentViewers = xmpp.getChannelCounts(requestedChannel.channelLoc)

    streamName = ""
    streamTopic = 0

    requestedChannel.currentViewers = currentViewers
    db.session.commit()

    if stream is not None:
        stream.currentViewers = currentViewers
        db.session.commit()
        streamName = stream.streamName
        streamTopic = stream.topic

    else:
        streamName = requestedChannel.channelName
        streamTopic = requestedChannel.topic

    if requestedChannel.imageLocation is None:
        channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/static/img/video-placeholder.jpg")
    else:
        channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/images/" + requestedChannel.imageLocation)

    join_room(streamData['data'])

    if current_user.is_authenticated:
        pictureLocation = current_user.pictureLocation
        if current_user.pictureLocation is None:
            pictureLocation = '/static/img/user2.png'
        else:
            pictureLocation = '/images/' + pictureLocation

        webhookFunc.runWebhook(requestedChannel.id, 2, channelname=requestedChannel.channelName,
                   channelurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/channel/" + str(requestedChannel.id)),
                   channeltopic=requestedChannel.topic, channelimage=channelImage, streamer=templateFilters.get_userName(requestedChannel.owningUser),
                   channeldescription=str(requestedChannel.description), streamname=streamName, streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/view/" + requestedChannel.channelLoc),
                   streamtopic=templateFilters.get_topicName(streamTopic), streamimage=(sysSettings.siteProtocol + sysSettings.siteAddress + "/stream-thumb/" + requestedChannel.channelLoc + ".png"),
                   user=current_user.username, userpicture=(sysSettings.siteProtocol + sysSettings.siteAddress + str(pictureLocation)))
    else:
        webhookFunc.runWebhook(requestedChannel.id, 2, channelname=requestedChannel.channelName,
                   channelurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/channel/" + str(requestedChannel.id)),
                   channeltopic=requestedChannel.topic, channelimage=channelImage, streamer=templateFilters.get_userName(requestedChannel.owningUser),
                   channeldescription=str(requestedChannel.description), streamname=streamName,
                   streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/view/" + requestedChannel.channelLoc),
                   streamtopic=templateFilters.get_topicName(streamTopic), streamimage=(sysSettings.siteProtocol + sysSettings.siteAddress + "/stream-thumb/" + requestedChannel.channelLoc + ".png"),
                   user="******", userpicture=(sysSettings.siteProtocol + sysSettings.siteAddress + '/static/img/user2.png'))

    handle_viewer_total_request(streamData, room=streamData['data'])

    db.session.commit()
    db.session.close()
    return 'OK'
Exemplo n.º 2
0
def rtmp_stage2_user_auth_check(channelLoc, ipaddress):
    sysSettings = settings.settings.query.first()

    currentTime = datetime.datetime.utcnow()

    requestedChannel = Channel.Channel.query.filter_by(channelLoc=channelLoc).first()

    if requestedChannel is not None:
        authedStream = Stream.Stream.query.filter_by(streamKey=requestedChannel.streamKey).first()

        if authedStream is not None:

            authedStream.currentViewers = int(xmpp.getChannelCounts(requestedChannel.channelLoc))
            authedStream.totalViewers = int(xmpp.getChannelCounts(requestedChannel.channelLoc))
            db.session.commit()

            if requestedChannel.imageLocation is None:
                channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/static/img/video-placeholder.jpg")
            else:
                channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/images/" + requestedChannel.imageLocation)

            webhookFunc.runWebhook(requestedChannel.id, 0, channelname=requestedChannel.channelName, channelurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/channel/" + str(requestedChannel.id)), channeltopic=requestedChannel.topic,
                       channelimage=channelImage, streamer=templateFilters.get_userName(requestedChannel.owningUser), channeldescription=str(requestedChannel.description),
                       streamname=authedStream.streamName, streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/view/" + requestedChannel.channelLoc), streamtopic=templateFilters.get_topicName(authedStream.topic),
                       streamimage=(sysSettings.siteProtocol + sysSettings.siteAddress + "/stream-thumb/" + requestedChannel.channelLoc + ".png"))

            subscriptionQuery = subscriptions.channelSubs.query.filter_by(channelID=requestedChannel.id).all()
            for sub in subscriptionQuery:
                # Create Notification for Channel Subs
                newNotification = notifications.userNotification(templateFilters.get_userName(requestedChannel.owningUser) + " has started a live stream in " + requestedChannel.channelName, "/view/" + str(requestedChannel.channelLoc),
                                                                 "/images/" + str(requestedChannel.owner.pictureLocation), sub.userID)
                db.session.add(newNotification)
            db.session.commit()

            try:
                subsFunc.processSubscriptions(requestedChannel.id,
                                 sysSettings.siteName + " - " + requestedChannel.channelName + " has started a stream",
                                 "<html><body><img src='" + sysSettings.siteProtocol + sysSettings.siteAddress + sysSettings.systemLogo + "'><p>Channel " + requestedChannel.channelName +
                                 " has started a new video stream.</p><p>Click this link to watch<br><a href='" + sysSettings.siteProtocol + sysSettings.siteAddress + "/view/" + str(requestedChannel.channelLoc)
                                 + "'>" + requestedChannel.channelName + "</a></p>")
            except:
                system.newLog(0, "Subscriptions Failed due to possible misconfiguration")

            returnMessage = {'time': str(currentTime), 'request': 'Stage2', 'success': True, 'channelLoc': requestedChannel.channelLoc, 'ipAddress': str(ipaddress), 'message': 'Success - Stream Authenticated & Initialized'}
            db.session.close()
            return returnMessage
        else:
            returnMessage = {'time': str(currentTime), 'request': 'Stage2', 'success': False, 'channelLoc': requestedChannel.channelLoc, 'ipAddress': str(ipaddress), 'message': 'Failed - No Matching Stage 1 Connection'}
            db.session.close()
            return returnMessage
    else:
        returnMessage = {'time': str(currentTime), 'request': 'Stage2', 'success': False, 'channelLoc': channelLoc, 'ipAddress': str(ipaddress), 'message': 'Failed - Passed Stage 1 Channel ID Does Not Match Any Known Channels'}
        db.session.close()
        return returnMessage
Exemplo n.º 3
0
def changeVideoMetadata(videoID, newVideoName, newVideoTopic, description,
                        allowComments):

    recordedVidQuery = RecordedVideo.RecordedVideo.query.filter_by(
        id=videoID, owningUser=current_user.id).first()
    sysSettings = settings.settings.query.first()

    if recordedVidQuery is not None:

        recordedVidQuery.channelName = system.strip_html(newVideoName)
        recordedVidQuery.topic = newVideoTopic
        recordedVidQuery.description = system.strip_html(description)
        recordedVidQuery.allowComments = allowComments

        if recordedVidQuery.channel.imageLocation is None:
            channelImage = (sysSettings.siteProtocol +
                            sysSettings.siteAddress +
                            "/static/img/video-placeholder.jpg")
        else:
            channelImage = (sysSettings.siteProtocol +
                            sysSettings.siteAddress + "/images/" +
                            recordedVidQuery.channel.imageLocation)

        webhookFunc.runWebhook(
            recordedVidQuery.channel.id,
            9,
            channelname=recordedVidQuery.channel.channelName,
            channelurl=(sysSettings.siteProtocol + sysSettings.siteAddress +
                        "/channel/" + str(recordedVidQuery.channel.id)),
            channeltopic=templateFilters.get_topicName(
                recordedVidQuery.channel.topic),
            channelimage=channelImage,
            streamer=templateFilters.get_userName(
                recordedVidQuery.channel.owningUser),
            channeldescription=str(recordedVidQuery.channel.description),
            videoname=recordedVidQuery.channelName,
            videodate=recordedVidQuery.videoDate,
            videodescription=recordedVidQuery.description,
            videotopic=templateFilters.get_topicName(recordedVidQuery.topic),
            videourl=(sysSettings.siteProtocol + sysSettings.siteAddress +
                      '/videos/' + recordedVidQuery.videoLocation),
            videothumbnail=(sysSettings.siteProtocol +
                            sysSettings.siteAddress + '/videos/' +
                            recordedVidQuery.thumbnailLocation))
        db.session.commit()
        system.newLog(
            4, "Video Metadata Changed - ID # " + str(recordedVidQuery.id))
        return True
    return False
Exemplo n.º 4
0
def user_registered_sighandler(app, user, confirm_token):
    defaultRoleQuery = Sec.Role.query.filter_by(default=True)
    for role in defaultRoleQuery:
        user_datastore.add_role_to_user(user, role.name)
    user.authType = 0
    user.xmppToken = str(os.urandom(32).hex())
    user.uuid = str(uuid.uuid4())
    webhookFunc.runWebhook("ZZZ", 20, user=user.username)
    system.newLog(1,
                  "A New User has Registered - Username:"******"An email has been sent to the email provided. Please check your email and verify your account to activate."
        )
    db.session.commit()
Exemplo n.º 5
0
def updateStreamData(message):
    channelLoc = message['channel']

    sysSettings = settings.settings.query.first()
    channelQuery = Channel.Channel.query.filter_by(
        channelLoc=channelLoc, owningUser=current_user.id).first()

    if channelQuery is not None:
        stream = channelQuery.stream[0]
        stream.streamName = system.strip_html(message['name'])
        stream.topic = int(message['topic'])
        db.session.commit()

        if channelQuery.imageLocation is None:
            channelImage = (sysSettings.siteProtocol +
                            sysSettings.siteAddress +
                            "/static/img/video-placeholder.jpg")
        else:
            channelImage = (sysSettings.siteProtocol +
                            sysSettings.siteAddress + "/images/" +
                            channelQuery.imageLocation)

        webhookFunc.runWebhook(
            channelQuery.id,
            4,
            channelname=channelQuery.channelName,
            channelurl=(sysSettings.siteProtocol + sysSettings.siteAddress +
                        "/channel/" + str(channelQuery.id)),
            channeltopic=channelQuery.topic,
            channelimage=channelImage,
            streamer=templateFilters.get_userName(channelQuery.owningUser),
            channeldescription=str(channelQuery.description),
            streamname=stream.streamName,
            streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress +
                       "/view/" + channelQuery.channelLoc),
            streamtopic=templateFilters.get_topicName(stream.topic),
            streamimage=(sysSettings.siteProtocol + sysSettings.siteAddress +
                         "/stream-thumb/" + channelQuery.channelLoc + ".png"))
        db.session.commit()
        db.session.close()
    db.session.commit()
    db.session.close()
    return 'OK'
Exemplo n.º 6
0
def togglePublishedSocketIO(message):
    sysSettings = settings.settings.query.first()
    if current_user.is_authenticated:
        videoID = int(message['videoID'])
        videoQuery = RecordedVideo.RecordedVideo.query.filter_by(
            owningUser=current_user.id, id=videoID).first()
        if videoQuery is not None:
            newState = not videoQuery.published
            videoQuery.published = newState

            if videoQuery.channel.imageLocation is None:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress +
                                "/static/img/video-placeholder.jpg")
            else:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress + "/images/" +
                                videoQuery.channel.imageLocation)

            if newState is True:

                webhookFunc.runWebhook(
                    videoQuery.channel.id,
                    6,
                    channelname=videoQuery.channel.channelName,
                    channelurl=(sysSettings.siteProtocol +
                                sysSettings.siteAddress + "/channel/" +
                                str(videoQuery.channel.id)),
                    channeltopic=templateFilters.get_topicName(
                        videoQuery.channel.topic),
                    channelimage=channelImage,
                    streamer=templateFilters.get_userName(
                        videoQuery.channel.owningUser),
                    channeldescription=str(videoQuery.channel.description),
                    videoname=videoQuery.channelName,
                    videodate=videoQuery.videoDate,
                    videodescription=str(videoQuery.description),
                    videotopic=templateFilters.get_topicName(videoQuery.topic),
                    videourl=(sysSettings.siteProtocol +
                              sysSettings.siteAddress + '/play/' +
                              str(videoQuery.id)),
                    videothumbnail=(sysSettings.siteProtocol +
                                    sysSettings.siteAddress + '/videos/' +
                                    str(videoQuery.thumbnailLocation)))

                subscriptionQuery = subscriptions.channelSubs.query.filter_by(
                    channelID=videoQuery.channel.id).all()
                for sub in subscriptionQuery:
                    # Create Notification for Channel Subs
                    newNotification = notifications.userNotification(
                        templateFilters.get_userName(
                            videoQuery.channel.owningUser) +
                        " has posted a new video to " +
                        videoQuery.channel.channelName + " titled " +
                        videoQuery.channelName, '/play/' + str(videoQuery.id),
                        "/images/" +
                        str(videoQuery.channel.owner.pictureLocation),
                        sub.userID)
                    db.session.add(newNotification)
                db.session.commit()

                subsFunc.processSubscriptions(
                    videoQuery.channel.id, sysSettings.siteName + " - " +
                    videoQuery.channel.channelName + " has posted a new video",
                    "<html><body><img src='" + sysSettings.siteProtocol +
                    sysSettings.siteAddress + sysSettings.systemLogo +
                    "'><p>Channel " + videoQuery.channel.channelName +
                    " has posted a new video titled <u>" +
                    videoQuery.channelName +
                    "</u> to the channel.</p><p>Click this link to watch<br><a href='"
                    + sysSettings.siteProtocol + sysSettings.siteAddress +
                    "/play/" + str(videoQuery.id) + "'>" +
                    videoQuery.channelName + "</a></p>")

            db.session.commit()
            db.session.close()
            return 'OK'
        else:
            db.session.commit()
            db.session.close()
            return abort(500)
    else:
        db.session.commit()
        db.session.close()
        return abort(401)
Exemplo n.º 7
0
def rtmp_rec_Complete_handler(channelLoc, path):
    sysSettings = settings.settings.query.first()

    currentTime = datetime.datetime.now()

    requestedChannel = Channel.Channel.query.filter_by(
        channelLoc=channelLoc).first()

    if requestedChannel is not None:

        pendingVideo = RecordedVideo.RecordedVideo.query.filter_by(
            channelID=requestedChannel.id, videoLocation="",
            pending=True).first()

        videoPath = path.replace('/tmp/', requestedChannel.channelLoc + '/')
        imagePath = videoPath.replace('.flv', '.png')
        gifPath = videoPath.replace('.flv', '.gif')
        videoPath = videoPath.replace('.flv', '.mp4')

        pendingVideo.thumbnailLocation = imagePath
        pendingVideo.videoLocation = videoPath
        pendingVideo.gifLocation = gifPath

        videos_root = current_app.config['WEB_ROOT'] + 'videos/'
        fullVidPath = videos_root + videoPath

        pendingVideo.pending = False

        if requestedChannel.autoPublish is True:
            pendingVideo.published = True
        else:
            pendingVideo.published = False

        db.session.commit()

        if requestedChannel.imageLocation is None:
            channelImage = (sysSettings.siteProtocol +
                            sysSettings.siteAddress +
                            "/static/img/video-placeholder.jpg")
        else:
            channelImage = (sysSettings.siteProtocol +
                            sysSettings.siteAddress + "/images/" +
                            requestedChannel.imageLocation)

        if requestedChannel.autoPublish is True:
            webhookFunc.runWebhook(
                requestedChannel.id,
                6,
                channelname=requestedChannel.channelName,
                channelurl=(sysSettings.siteProtocol +
                            sysSettings.siteAddress + "/channel/" +
                            str(requestedChannel.id)),
                channeltopic=templateFilters.get_topicName(
                    requestedChannel.topic),
                channelimage=channelImage,
                streamer=templateFilters.get_userName(
                    requestedChannel.owningUser),
                channeldescription=str(requestedChannel.description),
                videoname=pendingVideo.channelName,
                videodate=pendingVideo.videoDate,
                videodescription=pendingVideo.description,
                videotopic=templateFilters.get_topicName(pendingVideo.topic),
                videourl=(sysSettings.siteProtocol + sysSettings.siteAddress +
                          '/play/' + str(pendingVideo.id)),
                videothumbnail=(sysSettings.siteProtocol +
                                sysSettings.siteAddress + '/videos/' +
                                str(pendingVideo.thumbnailLocation)))

            subscriptionQuery = subscriptions.channelSubs.query.filter_by(
                channelID=requestedChannel.id).all()
            for sub in subscriptionQuery:
                # Create Notification for Channel Subs
                newNotification = notifications.userNotification(
                    templateFilters.get_userName(requestedChannel.owningUser) +
                    " has posted a new video to " +
                    requestedChannel.channelName + " titled " +
                    pendingVideo.channelName, '/play/' + str(pendingVideo.id),
                    "/images/" + str(requestedChannel.owner.pictureLocation),
                    sub.userID)
                db.session.add(newNotification)
            db.session.commit()

            subsFunc.processSubscriptions(
                requestedChannel.id, sysSettings.siteName + " - " +
                requestedChannel.channelName + " has posted a new video",
                "<html><body><img src='" + sysSettings.siteProtocol +
                sysSettings.siteAddress + sysSettings.systemLogo +
                "'><p>Channel " + requestedChannel.channelName +
                " has posted a new video titled <u>" +
                pendingVideo.channelName +
                "</u> to the channel.</p><p>Click this link to watch<br><a href='"
                + sysSettings.siteProtocol + sysSettings.siteAddress +
                "/play/" + str(pendingVideo.id) + "'>" +
                pendingVideo.channelName + "</a></p>")

        while not os.path.exists(fullVidPath):
            time.sleep(1)

        returnMessage = {
            'time': str(currentTime),
            'request': 'RecordingClose',
            'success': True,
            'channelLoc': requestedChannel.channelLoc,
            'ipAddress': None,
            'message': 'Success - Recorded Video Processing Complete'
        }
        db.session.close()
        return returnMessage
    else:
        returnMessage = {
            'time': str(currentTime),
            'request': 'RecordingClose',
            'success': False,
            'channelLoc': channelLoc,
            'ipAddress': None,
            'message': 'Failed - Requested Channel Does Not Exist'
        }
        return returnMessage
Exemplo n.º 8
0
def rtmp_user_deauth_check(key, ipaddress):
    sysSettings = settings.settings.query.first()

    currentTime = datetime.datetime.now()

    authedStream = Stream.Stream.query.filter_by(streamKey=key).all()

    channelRequest = Channel.Channel.query.filter_by(streamKey=key).first()

    if authedStream is not []:
        for stream in authedStream:
            streamUpvotes = upvotes.streamUpvotes.query.filter_by(
                streamID=stream.id).all()
            pendingVideo = RecordedVideo.RecordedVideo.query.filter_by(
                channelID=channelRequest.id,
                videoLocation="",
                originalStreamID=stream.id).first()

            wasRecorded = False
            recordingID = None
            endTimestamp = datetime.datetime.now()
            length = (endTimestamp - stream.startTimestamp).total_seconds()

            if pendingVideo is not None:
                pendingVideo.length = length
                pendingVideo.channelName = stream.streamName
                pendingVideo.views = stream.totalViewers
                pendingVideo.topic = stream.topic
                wasRecorded = True
                recordingID = pendingVideo.id

                for upvote in streamUpvotes:
                    newVideoUpvote = upvotes.videoUpvotes(
                        upvote.userID, pendingVideo.id)
                    db.session.add(newVideoUpvote)
                db.session.commit()

            topicName = "Unknown"
            topicQuery = topics.topics.query.filter_by(id=stream.topic).first()
            if topicQuery is not None:
                topicName = topicQuery.name

            newStreamHistory = logs.streamHistory(
                stream.uuid, stream.channel.owningUser,
                stream.channel.owner.username, stream.linkedChannel,
                stream.channel.channelName, stream.streamName,
                stream.startTimestamp, endTimestamp, stream.totalViewers,
                stream.get_upvotes(), wasRecorded, stream.topic, topicName,
                recordingID)
            db.session.add(newStreamHistory)
            db.session.commit()

            for vid in streamUpvotes:
                db.session.delete(vid)
            db.session.delete(stream)
            db.session.commit()

            if channelRequest.imageLocation is None:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress +
                                "/static/img/video-placeholder.jpg")
            else:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress + "/images/" +
                                channelRequest.imageLocation)

            webhookFunc.runWebhook(
                channelRequest.id,
                1,
                channelname=channelRequest.channelName,
                channelurl=(sysSettings.siteProtocol +
                            sysSettings.siteAddress + "/channel/" +
                            str(channelRequest.id)),
                channeltopic=channelRequest.topic,
                channelimage=channelImage,
                streamer=templateFilters.get_userName(
                    channelRequest.owningUser),
                channeldescription=str(channelRequest.description),
                streamname=stream.streamName,
                streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress +
                           "/view/" + channelRequest.channelLoc),
                streamtopic=templateFilters.get_topicName(stream.topic),
                streamimage=(sysSettings.siteProtocol +
                             sysSettings.siteAddress + "/stream-thumb/" +
                             str(channelRequest.channelLoc) + ".png"))
        returnMessage = {
            'time': str(currentTime),
            'request': 'StreamClose',
            'success': True,
            'channelLoc': channelRequest.channelLoc,
            'ipAddress': str(ipaddress),
            'message': 'Success - Stream Closed'
        }
        db.session.close()
        return returnMessage
    else:
        returnMessage = {
            'time': str(currentTime),
            'request': 'StreamClose',
            'success': False,
            'channelLoc': None,
            'ipAddress': str(ipaddress),
            'message': 'Failed - No Stream Listed Under Key'
        }
        db.session.close()
        return returnMessage
Exemplo n.º 9
0
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('/')
Exemplo n.º 10
0
def comments_vid_page(videoID):
    sysSettings = settings.settings.query.first()

    recordedVid = RecordedVideo.RecordedVideo.query.filter_by(
        id=videoID).first()

    if recordedVid is not None:

        if request.method == 'POST':

            comment = system.strip_html(request.form['commentText'])
            currentUser = current_user.id

            newComment = comments.videoComments(currentUser, comment,
                                                recordedVid.id)
            db.session.add(newComment)
            db.session.commit()

            if recordedVid.channel.imageLocation is None:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress +
                                "/static/img/video-placeholder.jpg")
            else:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress + "/images/" +
                                recordedVid.channel.imageLocation)

            pictureLocation = ""
            if current_user.pictureLocation is None:
                pictureLocation = '/static/img/user2.png'
            else:
                pictureLocation = '/images/' + pictureLocation

            newNotification = notifications.userNotification(
                templateFilters.get_userName(current_user.id) +
                " commented on your video - " + recordedVid.channelName,
                '/play/' + str(recordedVid.id),
                "/images/" + str(current_user.pictureLocation),
                recordedVid.owningUser)
            db.session.add(newNotification)
            db.session.commit()

            webhookFunc.runWebhook(
                recordedVid.channel.id,
                7,
                channelname=recordedVid.channel.channelName,
                channelurl=(sysSettings.siteProtocol +
                            sysSettings.siteAddress + "/channel/" +
                            str(recordedVid.channel.id)),
                channeltopic=templateFilters.get_topicName(
                    recordedVid.channel.topic),
                channelimage=channelImage,
                streamer=templateFilters.get_userName(
                    recordedVid.channel.owningUser),
                channeldescription=str(recordedVid.channel.description),
                videoname=recordedVid.channelName,
                videodate=recordedVid.videoDate,
                videodescription=recordedVid.description,
                videotopic=templateFilters.get_topicName(recordedVid.topic),
                videourl=(sysSettings.siteProtocol + sysSettings.siteAddress +
                          '/videos/' + recordedVid.videoLocation),
                videothumbnail=(sysSettings.siteProtocol +
                                sysSettings.siteAddress + '/videos/' +
                                recordedVid.thumbnailLocation),
                user=current_user.username,
                userpicture=(sysSettings.siteProtocol +
                             sysSettings.siteAddress + str(pictureLocation)),
                comment=comment)
            flash('Comment Added', "success")
            system.newLog(
                4, "Video Comment Added by " + current_user.username +
                "to Video ID #" + str(recordedVid.id))

        elif request.method == 'GET':
            if request.args.get('action') == "delete":
                commentID = int(request.args.get('commentID'))
                commentQuery = comments.videoComments.query.filter_by(
                    id=commentID).first()
                if commentQuery is not None:
                    if current_user.has_role(
                            'Admin'
                    ) or recordedVid.owningUser == current_user.id or commentQuery.userID == current_user.id:
                        upvoteQuery = upvotes.commentUpvotes.query.filter_by(
                            commentID=commentQuery.id).all()
                        for vote in upvoteQuery:
                            db.session.delete(vote)
                        db.session.delete(commentQuery)
                        db.session.commit()
                        system.newLog(
                            4, "Video Comment Deleted by " +
                            current_user.username + "to Video ID #" +
                            str(recordedVid.id))
                        flash('Comment Deleted', "success")
                    else:
                        flash("Not Authorized to Remove Comment", "error")

    else:
        flash('Invalid Video ID', 'error')
        return redirect(url_for('root.main_page'))

    return redirect(url_for('.view_vid_page', videoID=videoID))
Exemplo n.º 11
0
def user_deauth_check():
    sysSettings = settings.settings.query.first()

    key = request.form['name']
    ipaddress = request.form['addr']

    authedStream = Stream.Stream.query.filter_by(streamKey=key).all()

    channelRequest = Channel.Channel.query.filter_by(streamKey=key).first()

    if authedStream is not []:
        for stream in authedStream:
            streamUpvotes = upvotes.streamUpvotes.query.filter_by(
                streamID=stream.id).all()
            pendingVideo = RecordedVideo.RecordedVideo.query.filter_by(
                channelID=channelRequest.id, videoLocation="",
                pending=True).first()

            if pendingVideo is not None:
                pendingVideo.channelName = stream.streamName
                pendingVideo.views = stream.totalViewers
                pendingVideo.topic = stream.topic

                for upvote in streamUpvotes:
                    newVideoUpvote = upvotes.videoUpvotes(
                        upvote.userID, pendingVideo.id)
                    db.session.add(newVideoUpvote)
                db.session.commit()

            for vid in streamUpvotes:
                db.session.delete(vid)
            db.session.delete(stream)
            db.session.commit()

            # End RTMP Restream Function
            if channelRequest.restreamDestinations != []:
                if channelRequest.channelLoc in globalvars.restreamSubprocesses:
                    for restream in globalvars.restreamSubprocesses[
                            channelRequest.channelLoc]:
                        #p = globalvars.restreamSubprocesses[channelRequest.channelLoc][restream]
                        restream.kill()
                try:
                    del globalvars.restreamSubprocesses[
                        channelRequest.channelLoc]
                except KeyError:
                    pass

            if channelRequest.channelLoc in globalvars.edgeRestreamSubprocesses:
                for p in globalvars.edgeRestreamSubprocesses[
                        channelRequest.channelLoc]:
                    p.kill()
                try:
                    del globalvars.edgeRestreamSubprocesses[
                        channelRequest.channelLoc]
                except KeyError:
                    pass

            returnMessage = {
                'time': str(datetime.datetime.now()),
                'status': 'Stream Closed',
                'key': str(key),
                'channelName': str(channelRequest.channelName),
                'userName': str(channelRequest.owningUser),
                'ipAddress': str(ipaddress)
            }

            print(returnMessage)

            if channelRequest.imageLocation is None:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress +
                                "/static/img/video-placeholder.jpg")
            else:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress + "/images/" +
                                channelRequest.imageLocation)

            webhookFunc.runWebhook(
                channelRequest.id,
                1,
                channelname=channelRequest.channelName,
                channelurl=(sysSettings.siteProtocol +
                            sysSettings.siteAddress + "/channel/" +
                            str(channelRequest.id)),
                channeltopic=channelRequest.topic,
                channelimage=channelImage,
                streamer=templateFilters.get_userName(
                    channelRequest.owningUser),
                channeldescription=str(channelRequest.description),
                streamname=stream.streamName,
                streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress +
                           "/view/" + channelRequest.channelLoc),
                streamtopic=templateFilters.get_topicName(stream.topic),
                streamimage=(sysSettings.siteProtocol +
                             sysSettings.siteAddress + "/stream-thumb/" +
                             str(channelRequest.channelLoc) + ".png"))
        return 'OK'
    else:
        returnMessage = {
            'time': str(datetime.datetime.now()),
            'status': 'Stream Closure Failure - No Such Stream',
            'key': str(key),
            'ipAddress': str(ipaddress)
        }
        print(returnMessage)
        db.session.close()
        return abort(400)
Exemplo n.º 12
0
def user_auth_check():
    sysSettings = settings.settings.query.first()

    key = request.form['name']
    ipaddress = request.form['addr']

    requestedChannel = Channel.Channel.query.filter_by(channelLoc=key).first()

    if requestedChannel is not None:
        authedStream = Stream.Stream.query.filter_by(
            streamKey=requestedChannel.streamKey).first()

        if authedStream is not None:
            returnMessage = {
                'time': str(datetime.datetime.now()),
                'status': 'Successful Channel Auth',
                'key': str(requestedChannel.streamKey),
                'channelName': str(requestedChannel.channelName),
                'ipAddress': str(ipaddress)
            }
            print(returnMessage)

            if requestedChannel.imageLocation is None:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress +
                                "/static/img/video-placeholder.jpg")
            else:
                channelImage = (sysSettings.siteProtocol +
                                sysSettings.siteAddress + "/images/" +
                                requestedChannel.imageLocation)

            webhookFunc.runWebhook(
                requestedChannel.id,
                0,
                channelname=requestedChannel.channelName,
                channelurl=(sysSettings.siteProtocol +
                            sysSettings.siteAddress + "/channel/" +
                            str(requestedChannel.id)),
                channeltopic=requestedChannel.topic,
                channelimage=channelImage,
                streamer=templateFilters.get_userName(
                    requestedChannel.owningUser),
                channeldescription=str(requestedChannel.description),
                streamname=authedStream.streamName,
                streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress +
                           "/view/" + requestedChannel.channelLoc),
                streamtopic=templateFilters.get_topicName(authedStream.topic),
                streamimage=(sysSettings.siteProtocol +
                             sysSettings.siteAddress + "/stream-thumb/" +
                             requestedChannel.channelLoc + ".png"))

            subscriptionQuery = subscriptions.channelSubs.query.filter_by(
                channelID=requestedChannel.id).all()
            for sub in subscriptionQuery:
                # Create Notification for Channel Subs
                newNotification = notifications.userNotification(
                    templateFilters.get_userName(requestedChannel.owningUser) +
                    " has started a live stream in " +
                    requestedChannel.channelName,
                    "/view/" + str(requestedChannel.channelLoc),
                    "/images/" + str(requestedChannel.owner.pictureLocation),
                    sub.userID)
                db.session.add(newNotification)
            db.session.commit()

            try:
                subsFunc.processSubscriptions(
                    requestedChannel.id, sysSettings.siteName + " - " +
                    requestedChannel.channelName + " has started a stream",
                    "<html><body><img src='" + sysSettings.siteProtocol +
                    sysSettings.siteAddress + sysSettings.systemLogo +
                    "'><p>Channel " + requestedChannel.channelName +
                    " has started a new video stream.</p><p>Click this link to watch<br><a href='"
                    + sysSettings.siteProtocol + sysSettings.siteAddress +
                    "/view/" + str(requestedChannel.channelLoc) + "'>" +
                    requestedChannel.channelName + "</a></p>")
            except:
                system.newLog(
                    0, "Subscriptions Failed due to possible misconfiguration")

            inputLocation = "rtmp://" + coreNginxRTMPAddress + ":1935/live/" + requestedChannel.channelLoc

            # Begin RTMP Restream Function
            if requestedChannel.restreamDestinations != []:
                globalvars.restreamSubprocesses[
                    requestedChannel.channelLoc] = []
                for rtmpRestream in requestedChannel.restreamDestinations:
                    if rtmpRestream.enabled == True:
                        p = subprocess.Popen([
                            "ffmpeg", "-i", inputLocation, "-c", "copy", "-f",
                            "flv", rtmpRestream.url, "-c:v", "libx264",
                            "-maxrate",
                            str(sysSettings.restreamMaxBitrate) + "k",
                            "-bufsize", "6000k", "-c:a", "aac", "-b:a", "160k",
                            "-ac", "2"
                        ],
                                             stdout=subprocess.DEVNULL,
                                             stderr=subprocess.DEVNULL)
                        globalvars.restreamSubprocesses[
                            requestedChannel.channelLoc].append(p)

            # Start OSP Edge Nodes
            ospEdgeNodeQuery = settings.edgeStreamer.query.filter_by(
                active=True).all()
            if ospEdgeNodeQuery is not []:
                globalvars.edgeRestreamSubprocesses[
                    requestedChannel.channelLoc] = []

                for node in ospEdgeNodeQuery:
                    if node.address != sysSettings.siteAddress:
                        subprocessConstructor = [
                            "ffmpeg", "-i", inputLocation, "-c", "copy"
                        ]
                        subprocessConstructor.append("-f")
                        subprocessConstructor.append("flv")
                        if sysSettings.adaptiveStreaming:
                            subprocessConstructor.append(
                                "rtmp://" + node.address +
                                "/stream-data-adapt/" +
                                requestedChannel.channelLoc)
                        else:
                            subprocessConstructor.append(
                                "rtmp://" + node.address + "/stream-data/" +
                                requestedChannel.channelLoc)

                        p = subprocess.Popen(subprocessConstructor,
                                             stdout=subprocess.DEVNULL,
                                             stderr=subprocess.DEVNULL)
                        globalvars.edgeRestreamSubprocesses[
                            requestedChannel.channelLoc].append(p)

            db.session.close()
            return 'OK'
        else:
            returnMessage = {
                'time': str(datetime.datetime.now()),
                'status': 'Failed Channel Auth. No Authorized Stream Key',
                'channelName': str(key),
                'ipAddress': str(ipaddress)
            }
            print(returnMessage)
            db.session.close()
            return abort(400)
    else:
        returnMessage = {
            'time': str(datetime.datetime.now()),
            'status':
            'Failed Channel Auth. Channel Loc does not match Channel',
            'channelName': str(key),
            'ipAddress': str(ipaddress)
        }
        print(returnMessage)
        db.session.close()
        return abort(400)
Exemplo n.º 13
0
def upload_vid():
    sysSettings = settings.settings.query.first()
    if not sysSettings.allowUploads:
        db.session.close()
        flash("Video Upload Disabled", "error")
        return redirect(url_for('root.main_page'))

    currentTime = datetime.datetime.now()

    channel = int(request.form['uploadToChannelID'])
    topic = int(request.form['uploadTopic'])
    thumbnailFilename = request.form['thumbnailFilename']
    videoFilename= request.form['videoFilename']

    ChannelQuery = Channel.Channel.query.filter_by(id=channel).first()

    if ChannelQuery.owningUser != current_user.id:
        flash('You are not allowed to upload to this channel!')
        db.session.close()
        return redirect(url_for('root.main_page'))

    videoPublishState = ChannelQuery.autoPublish

    newVideo = RecordedVideo.RecordedVideo(current_user.id, channel, ChannelQuery.channelName, ChannelQuery.topic, 0, "", currentTime, ChannelQuery.allowComments, videoPublishState)

    videoLoc = ChannelQuery.channelLoc + "/" + videoFilename.rsplit(".", 1)[0] + '_' + datetime.datetime.strftime(currentTime, '%Y%m%d_%H%M%S') + ".mp4"
    videos_root = current_app.config['WEB_ROOT'] + 'videos/'
    videoPath = videos_root + videoLoc

    if videoFilename != "":
        if not os.path.isdir(videos_root + ChannelQuery.channelLoc):
            try:
                os.mkdir(videos_root + ChannelQuery.channelLoc)
            except OSError:
                system.newLog(4, "File Upload Failed - OSError - Unable to Create Directory - Username:"******"Error uploading video - Unable to create directory","error")
                db.session.close()
                return redirect(url_for("root.main_page"))
        shutil.move(current_app.config['VIDEO_UPLOAD_TEMPFOLDER'] + '/' + videoFilename, videoPath)
    else:
        db.session.close()
        flash("Error uploading video - Couldn't move video file")
        return redirect(url_for('root.main_page'))

    newVideo.videoLocation = videoLoc

    if thumbnailFilename != "":
        thumbnailLoc = ChannelQuery.channelLoc + '/' + thumbnailFilename.rsplit(".", 1)[0] + '_' +  datetime.datetime.strftime(currentTime, '%Y%m%d_%H%M%S') + videoFilename.rsplit(".", 1)[-1]

        thumbnailPath = videos_root + thumbnailLoc
        try:
            shutil.move(current_app.config['VIDEO_UPLOAD_TEMPFOLDER'] + '/' + thumbnailFilename, thumbnailPath)
        except:
            flash("Thumbnail Upload Failed Due to Missing File","error")
        newVideo.thumbnailLocation = thumbnailLoc
    else:
        thumbnailLoc = ChannelQuery.channelLoc + '/' + videoFilename.rsplit(".", 1)[0] + '_' +  datetime.datetime.strftime(currentTime, '%Y%m%d_%H%M%S') + ".png"

        subprocess.call(['ffmpeg', '-ss', '00:00:01', '-i', videos_root + videoLoc, '-s', '384x216', '-vframes', '1', videos_root + thumbnailLoc])
        newVideo.thumbnailLocation = thumbnailLoc

    newGifFullThumbnailLocation = ChannelQuery.channelLoc + '/' + videoFilename.rsplit(".", 1)[0] + '_' + datetime.datetime.strftime(currentTime, '%Y%m%d_%H%M%S') + ".gif"
    gifresult = subprocess.call(['ffmpeg', '-ss', '00:00:01', '-t', '3', '-i', videos_root + videoLoc, '-filter_complex', '[0:v] fps=30,scale=w=384:h=-1,split [a][b];[a] palettegen=stats_mode=single [p];[b][p] paletteuse=new=1', '-y', videos_root + newGifFullThumbnailLocation])
    newVideo.gifLocation = newGifFullThumbnailLocation

    if request.form['videoTitle'] != "":
        newVideo.channelName = system.strip_html(request.form['videoTitle'])
    else:
        newVideo.channelName = currentTime

    newVideo.topic = topic

    newVideo.description = system.strip_html(request.form['videoDescription'])

    if os.path.isfile(videoPath):
        newVideo.pending = False
        db.session.add(newVideo)
        db.session.commit()

        if ChannelQuery.autoPublish is True:
            newVideo.published = True
        else:
            newVideo.published = False
        db.session.commit()

        if ChannelQuery.imageLocation is None:
            channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/static/img/video-placeholder.jpg")
        else:
            channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/images/" + ChannelQuery.imageLocation)
        system.newLog(4, "File Upload Successful - Username:"******"/channel/" + str(ChannelQuery.id)),
                       channeltopic=templateFilters.get_topicName(ChannelQuery.topic),
                       channelimage=channelImage, streamer=templateFilters.get_userName(ChannelQuery.owningUser),
                       channeldescription=str(ChannelQuery.description), videoname=newVideo.channelName,
                       videodate=newVideo.videoDate, videodescription=newVideo.description,
                       videotopic=templateFilters.get_topicName(newVideo.topic),
                       videourl=(sysSettings.siteProtocol + sysSettings.siteAddress + '/play/' + str(newVideo.id)),
                       videothumbnail=(sysSettings.siteProtocol + sysSettings.siteAddress + '/videos/' + newVideo.thumbnailLocation))

            subscriptionQuery = subscriptions.channelSubs.query.filter_by(channelID=ChannelQuery.id).all()
            for sub in subscriptionQuery:
                # Create Notification for Channel Subs
                newNotification = notifications.userNotification(templateFilters.get_userName(ChannelQuery.owningUser) + " has posted a new video to " + ChannelQuery.channelName + " titled " + newVideo.channelName, '/play/' + str(newVideo.id),
                                                                 "/images/" + ChannelQuery.owner.pictureLocation, sub.userID)
                db.session.add(newNotification)
            db.session.commit()

            try:
                subsFunc.processSubscriptions(ChannelQuery.id,
                                 sysSettings.siteName + " - " + ChannelQuery.channelName + " has posted a new video",
                                 "<html><body><img src='" + sysSettings.siteProtocol + sysSettings.siteAddress + sysSettings.systemLogo + "'><p>Channel " + ChannelQuery.channelName + " has posted a new video titled <u>" + newVideo.channelName +
                                 "</u> to the channel.</p><p>Click this link to watch<br><a href='" + sysSettings.siteProtocol + sysSettings.siteAddress + "/play/" + str(newVideo.id) + "'>" + newVideo.channelName + "</a></p>")
            except:
                system.newLog(0, "Subscriptions Failed due to possible misconfiguration")

    videoID = newVideo.id
    db.session.commit()
    db.session.close()
    flash("Video upload complete")
    return redirect(url_for('play.view_vid_page', videoID=videoID))
Exemplo n.º 14
0
def toggle_chanSub(payload):
    if current_user.is_authenticated:
        sysSettings = settings.settings.query.first()
        if 'channelID' in payload:
            channelQuery = Channel.Channel.query.filter_by(
                id=int(payload['channelID'])).first()
            if channelQuery is not None:
                currentSubscription = subscriptions.channelSubs.query.filter_by(
                    channelID=channelQuery.id, userID=current_user.id).first()
                subState = False
                if currentSubscription is None:
                    newSub = subscriptions.channelSubs(channelQuery.id,
                                                       current_user.id)
                    db.session.add(newSub)
                    subState = True

                    channelImage = None
                    if channelQuery.imageLocation is None:
                        channelImage = (sysSettings.siteProtocol +
                                        sysSettings.siteAddress +
                                        "/static/img/video-placeholder.jpg")
                    else:
                        channelImage = (sysSettings.siteProtocol +
                                        sysSettings.siteAddress + "/images/" +
                                        channelQuery.imageLocation)

                    pictureLocation = current_user.pictureLocation
                    if current_user.pictureLocation is None:
                        pictureLocation = '/static/img/user2.png'
                    else:
                        pictureLocation = '/images/' + pictureLocation

                    # Create Notification for Channel Owner on New Subs
                    newNotification = notifications.userNotification(
                        current_user.username + " has subscribed to " +
                        channelQuery.channelName,
                        "/channel/" + str(channelQuery.id),
                        "/images/" + str(current_user.pictureLocation),
                        channelQuery.owningUser)
                    db.session.add(newNotification)
                    db.session.commit()

                    webhookFunc.runWebhook(
                        channelQuery.id,
                        10,
                        channelname=channelQuery.channelName,
                        channelurl=(sysSettings.siteProtocol +
                                    sysSettings.siteAddress + "/channel/" +
                                    str(channelQuery.id)),
                        channeltopic=templateFilters.get_topicName(
                            channelQuery.topic),
                        channelimage=str(channelImage),
                        streamer=templateFilters.get_userName(
                            channelQuery.owningUser),
                        channeldescription=str(channelQuery.description),
                        user=current_user.username,
                        userpicture=sysSettings.siteProtocol +
                        sysSettings.siteAddress + str(pictureLocation))
                else:
                    db.session.delete(currentSubscription)
                db.session.commit()
                db.session.close()
                emit('sendChanSubResults', {'state': subState},
                     broadcast=False)
    db.session.close()
    return 'OK'