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
def togglePublishedClipSocketIO(message): if current_user.is_authenticated: clipID = int(message['clipID']) clipQuery = RecordedVideo.Clips.query.filter_by(id=clipID).first() if clipQuery is not None and current_user.id == clipQuery.recordedVideo.owningUser: newState = not clipQuery.published clipQuery.published = newState if newState is True: subscriptionQuery = subscriptions.channelSubs.query.filter_by( channelID=clipQuery.recordedVideo.channel.id).all() for sub in subscriptionQuery: # Create Notification for Channel Subs newNotification = notifications.userNotification( templateFilters.get_userName( clipQuery.recordedVideo.owningUser) + " has posted a new clip to " + clipQuery.recordedVideo.channel.channelName + " titled " + clipQuery.clipName, '/clip/' + str(clipQuery.id), "/images/" + str(clipQuery.recordedVideo.channel.owner. pictureLocation), sub.userID) db.session.add(newNotification) 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)
def createClip(videoID, clipStart, clipStop, clipName, clipDescription): settingsQuery = settings.settings.query.first() # TODO Add Webhook for Clip Creation recordedVidQuery = RecordedVideo.RecordedVideo.query.filter_by( id=int(videoID), owningUser=current_user.id).first() if recordedVidQuery is not None: clipLength = clipStop - clipStart if settingsQuery.maxClipLength < 301: if clipLength > settingsQuery.maxClipLength: return False, None if clipStop > clipStart: videos_root = globalvars.videoRoot + 'videos/' # Generate Clip Object newClip = RecordedVideo.Clips(recordedVidQuery.id, None, clipStart, clipStop, clipName, clipDescription) newClip.published = False db.session.add(newClip) db.session.commit() newClipQuery = RecordedVideo.Clips.query.filter_by( id=newClip.id).first() videoLocation = videos_root + recordedVidQuery.videoLocation # Establish Locations for Clips and Thumbnails clipVideoLocation = recordedVidQuery.channel.channelLoc + '/clips/' + 'clip-' + str( newClipQuery.id) + ".mp4" clipThumbNailLocation = recordedVidQuery.channel.channelLoc + '/clips/' + 'clip-' + str( newClipQuery.id) + ".png" clipGifLocation = recordedVidQuery.channel.channelLoc + '/clips/' + 'clip-' + str( newClipQuery.id) + ".gif" # Set Clip Object Values for Locations newClipQuery.videoLocation = clipVideoLocation newClipQuery.thumbnailLocation = clipThumbNailLocation newClipQuery.gifLocation = clipGifLocation # Set Full Path for Locations to be handled by FFMPEG fullvideoLocation = videos_root + clipVideoLocation fullthumbnailLocation = videos_root + clipThumbNailLocation fullgifLocation = videos_root + clipGifLocation # Create Clip Directory if doesn't exist if not os.path.isdir(videos_root + recordedVidQuery.channel.channelLoc + '/clips'): os.mkdir(videos_root + recordedVidQuery.channel.channelLoc + '/clips') # FFMPEG Subprocess to Clip Video and generate Thumbnails clipVideo = subprocess.call([ 'ffmpeg', '-ss', str(clipStart), '-i', videoLocation, '-t', str(newClipQuery.length), fullvideoLocation ]) processResult = subprocess.call([ 'ffmpeg', '-ss', str(clipStart), '-i', videoLocation, '-s', '384x216', '-vframes', '1', fullthumbnailLocation ]) gifprocessResult = subprocess.call([ 'ffmpeg', '-ss', str(clipStart), '-t', '3', '-i', videoLocation, '-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', fullgifLocation ]) redirectID = newClipQuery.id newClipQuery.published = True system.newLog(6, "New Clip Created - ID #" + str(redirectID)) subscriptionQuery = subscriptions.channelSubs.query.filter_by( channelID=recordedVidQuery.channel.id).all() for sub in subscriptionQuery: # Create Notification for Channel Subs newNotification = notifications.userNotification( templateFilters.get_userName(recordedVidQuery.owningUser) + " has posted a new clip to " + recordedVidQuery.channel.channelName + " titled " + clipName, '/clip/' + str(newClipQuery.id), "/images/" + str(recordedVidQuery.channel.owner.pictureLocation), sub.userID) db.session.add(newNotification) db.session.commit() db.session.close() return True, redirectID return False, None
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)
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
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 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)
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))
def handle_upvoteChange(streamData): loc = streamData['loc'] vidType = str(streamData['vidType']) myUpvote = False totalUpvotes = 0 totalQuery = None myVoteQuery = None if vidType == 'stream': loc = str(loc) channelQuery = Channel.Channel.query.filter_by(channelLoc=loc).first() if channelQuery.stream: stream = channelQuery.stream[0] myVoteQuery = upvotes.streamUpvotes.query.filter_by(userID=current_user.id, streamID=stream.id).first() if myVoteQuery is None: newUpvote = upvotes.streamUpvotes(current_user.id, stream.id) db.session.add(newUpvote) # Create Notification for Channel Owner on New Like newNotification = notifications.userNotification(current_user.username + " liked your live stream - " + channelQuery.channelName, "/view/" + str(channelQuery.channelLoc), "/images/" + str(current_user.pictureLocation), channelQuery.owningUser) db.session.add(newNotification) else: db.session.delete(myVoteQuery) totalQuery = upvotes.streamUpvotes.query.filter_by(streamID=stream.id).count() myVoteQuery = upvotes.streamUpvotes.query.filter_by(userID=current_user.id, streamID=stream.id).first() db.session.commit() elif vidType == 'video': loc = int(loc) videoQuery = RecordedVideo.RecordedVideo.query.filter_by(id=loc).first() if videoQuery is not None: myVoteQuery = upvotes.videoUpvotes.query.filter_by(userID=current_user.id, videoID=loc).first() if myVoteQuery is None: newUpvote = upvotes.videoUpvotes(current_user.id, loc) db.session.add(newUpvote) # Create Notification for Video Owner on New Like newNotification = notifications.userNotification(current_user.username + " liked your video - " + videoQuery.channelName, "/play/" + str(videoQuery.id), "/images/" + str(current_user.pictureLocation), videoQuery.owningUser) db.session.add(newNotification) else: db.session.delete(myVoteQuery) totalQuery = upvotes.videoUpvotes.query.filter_by(videoID=loc).count() myVoteQuery = upvotes.videoUpvotes.query.filter_by(userID=current_user.id, videoID=loc).first() db.session.commit() elif vidType == "comment": loc = int(loc) videoCommentQuery = comments.videoComments.query.filter_by(id=loc).first() if videoCommentQuery is not None: myVoteQuery = upvotes.commentUpvotes.query.filter_by(userID=current_user.id, commentID=videoCommentQuery.id).first() if myVoteQuery is None: newUpvote = upvotes.commentUpvotes(current_user.id, videoCommentQuery.id) db.session.add(newUpvote) # Create Notification for Video Owner on New Like newNotification = notifications.userNotification(current_user.username + " liked your comment on a video", "/play/" + str(videoCommentQuery.videoID), "/images/" + str(current_user.pictureLocation), videoCommentQuery.userID) db.session.add(newNotification) else: db.session.delete(myVoteQuery) totalQuery = upvotes.commentUpvotes.query.filter_by(commentID=loc).count() myVoteQuery = upvotes.commentUpvotes.query.filter_by(userID=current_user.id, commentID=loc).first() db.session.commit() elif vidType == 'clip': loc = int(loc) clipQuery = RecordedVideo.Clips.query.filter_by(id=loc).first() if clipQuery is not None: myVoteQuery = upvotes.clipUpvotes.query.filter_by(userID=current_user.id, clipID=loc).first() if myVoteQuery is None: newUpvote = upvotes.clipUpvotes(current_user.id, loc) db.session.add(newUpvote) # Create Notification for Clip Owner on New Like newNotification = notifications.userNotification(current_user.username + " liked your clip - " + clipQuery.clipName, "/clip/" + str(clipQuery.id), "/images/" + str(current_user.pictureLocation), clipQuery.recordedVideo.owningUser) db.session.add(newNotification) else: db.session.delete(myVoteQuery) totalQuery = upvotes.clipUpvotes.query.filter_by(clipID=loc).count() myVoteQuery = upvotes.clipUpvotes.query.filter_by(userID=current_user.id, clipID=loc).first() db.session.commit() if totalQuery is not None: totalUpvotes = totalQuery if myVoteQuery is not None: myUpvote = True db.session.close() emit('upvoteTotalResponse', {'totalUpvotes': str(totalUpvotes), 'myUpvote': str(myUpvote), 'type': vidType, 'loc': loc}) return 'OK'
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'