示例#1
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
示例#2
0
def changeClipMetadata(clipID, name, description):
    # TODO Add Webhook for Clip Metadata Change

    clipQuery = RecordedVideo.Clips.query.filter_by(id=int(clipID)).first()

    if clipQuery is not None:
        if clipQuery.recordedVideo.owningUser == current_user.id:

            clipQuery.clipName = system.strip_html(name)
            clipQuery.description = system.strip_html(description)

            db.session.commit()
            system.newLog(6, "Clip Metadata Changed - ID #" + str(clipID))
            return True
    return False
示例#3
0
def editVideoSocketIO(message):
    if current_user.is_authenticated:
        videoID = int(message['videoID'])
        videoName = system.strip_html(message['videoName'])
        videoTopic = int(message['videoTopic'])
        videoDescription = message['videoDescription']
        videoAllowComments = False
        if message['videoAllowComments'] == "True" or message[
                'videoAllowComments'] == True:
            videoAllowComments = True

        result = videoFunc.changeVideoMetadata(videoID, videoName, videoTopic,
                                               videoDescription,
                                               videoAllowComments)
        if result is True:
            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)
示例#4
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'
示例#5
0
def vid_change_page(videoID):

    newVideoName = system.strip_html(request.form['newVidName'])
    newVideoTopic = request.form['newVidTopic']
    description = request.form['description']

    allowComments = False
    if 'allowComments' in request.form:
        allowComments = True

    result = videoFunc.changeVideoMetadata(videoID, newVideoName,
                                           newVideoTopic, description,
                                           allowComments)

    if result is True:
        flash("Changed Video Metadata", "success")
        return redirect(url_for('.view_vid_page', videoID=videoID))
    else:
        flash("Error Changing Video Metadata", "error")
        return redirect(url_for("root.main_page"))
示例#6
0
def createclipSocketIO(message):
    if current_user.is_authenticated:
        videoID = int(message['videoID'])
        clipName = system.strip_html(message['clipName'])
        clipDescription = message['clipDescription']
        startTime = float(message['clipStart'])
        stopTime = float(message['clipStop'])
        result = videoFunc.createClip(videoID, startTime, stopTime, clipName,
                                      clipDescription)
        if result[0] is True:
            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)
示例#7
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))
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))