예제 #1
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
예제 #2
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)
예제 #3
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
예제 #4
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)
예제 #5
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))