def GetVideoLinks(self, category, sortBy): logging.info(category) if (sortBy == "time"): if (category == "all"): vidquery = Video.query().order(-Video.addedDate) else: vidquery = Video.query(Video.videoCategory == str( category)).order(-Video.addedDate) elif (sortBy == "dubscount"): if (category == "all"): vidquery = Video.query().order(-Video.dubsCount) else: vidquery = Video.query(Video.videoCategory == str( category)).order(-Video.dubsCount) videos = vidquery.fetch(100) # logging.info(str(videos)) Videos = [] for video in videos: vidobj = dict() vidobj["videoname"] = str(video.name) vidobj["videolink"] = str(video.videolink) vidobj["videocat"] = str(video.videoCategory) vidobj["dubscount"] = str(video.dubsCount) vidobj["addeddate"] = str(video.addedDate) Videos.append(vidobj) return json.dumps(Videos)
def AddNewAudio(self,blobkey,audioname,videoLink,composer,composeremail,starttime,language,uniqueID): vid = Video.query(Video.videolink == videoLink) v = vid.get() v.dubsCount = int(v.dubsCount) +1 v.put() recordedAudiosList = [] # if(uniqueID != ""): # userQuery=User.query(ancestor=self.UserKey(uniqueID)) # user = userQuery.get() # response = dict() # if(user != None): # recordedAudiosList = user.recordedAudios # recordedAudiosList.append(blobkey) # user.put() audioKey=blobkey aud = Audio(parent=self.AudioLink(videoLink)) aud.audiolink = audioKey aud.videolink = videoLink aud.name = audioname aud.audioblobkey = audioKey aud.upvotes = 0 aud.downvotes=0 aud.composer = composer aud.composerEmail=composeremail aud.recordeddate = datetime.now() aud.starttime = starttime aud.language = language aud.viewCount = 0 aud.put() post = dict() post["result"] = audioKey return json.dumps(post)
def GetVideoLinksBydate(self, offset, limit, startdate, enddate): # logging.info(category) startdate = datetime.strptime(startdate, '%Y-%m-%d') enddate = datetime.strptime(enddate, '%Y-%m-%d') vidquery = Video.query(Video.addedDate >= startdate, Video.addedDate <= enddate).order(-Video.addedDate) videos = vidquery.fetch(int(limit), offset=int(offset)) # logging.info(str(videos)) Videos = [] for video in videos: vidobj = dict() vidobj["videoname"] = str(video.name.encode('utf-8')) vidobj["videolink"] = str(video.videolink) vidobj["videocat"] = str(video.videoCategory) vidobj["dubscount"] = str(video.dubsCount) vidobj["addeddate"] = str(video.addedDate) vidobj["videoGAEID"] = str(video.key.id()) uniqueID = video.addedUser # logging.info(uniqueID) if(uniqueID != None): userQuery = User.query(ancestor=self.UserKey(uniqueID)) user = userQuery.get() if(user != None): vidobj["userName"] = user.userName vidobj["userDisplayName"] = user.userDisplayName vidobj["userUniqueID"] = str(uniqueID) # logging.info(video.key.id()) Videos.append(vidobj) return Videos
def AddNewVideo(self, name, videoLink, videocat): # v = self.VideoLink(videoLink) vidquery = Video.query(ancestor=self.VideoLink(videoLink)) videos = vidquery.get() if (videos != None): logging.info(str(videos.videolink)) if (str(videos.videolink) == videoLink): post = dict() post["error"] = "Already Exists" return json.dumps(post) else: vid = Video(parent=self.VideoLink(videoLink)) # name="sample",videolink=videoLink,audiolink="",videoCategory="Entertainment" vid.name = name vid.videolink = videoLink vid.audiolink = "" vid.videoCategory = videocat vid.dubsCount = 0 vid.addedDate = datetime.now() vid.put() post = dict() post["result"] = "Added new video" return json.dumps(post)
def AddNewAudio(self, blobkeys, audioname, videoLink, composer, composeremail, starttime, language): # logging.info(str(blob)) vid = Video.query(Video.videolink == videoLink) v = vid.get() v.dubsCount = int(v.dubsCount) + 1 v.put() audioKeys = blobkeys aud = Audio(parent=self.AudioLink(videoLink)) aud.audiolink = audioKeys[0] aud.videolink = videoLink aud.name = audioname aud.audioblobkey = audioKeys aud.upvotes = 0 aud.downvotes = 0 aud.composer = composer aud.composerEmail = composeremail aud.recordeddate = datetime.now() aud.starttime = starttime aud.language = language aud.viewCount = 0 aud.put() post = dict() post["result"] = audioKeys return json.dumps(post)
def DeleteVideosObject(self, vidUrl): video = Video.query(ancestor=self.VideoLink(vidUrl)) vidobj = video.get() vidobj.status = "deleted" audquery = Audio.query(ancestor=self.AudioLink(vidUrl)) audios = audquery.fetch(100) for aud in audios: aud.status = "deleted" vidobj.put()
def ModifyVideoMetadata(self, videoLink, VideoCat): video = Video.query(ancestor=self.VideoLink(videoLink)) vidobj = video.get() if(VideoCat != "" and VideoCat != None): vidobj.videoCategory = VideoCat vidobj.put() resp = {} resp["response"] = "success" return resp
def GetVideoDetails(self, videoUrl): vid = Video.query(Video.videolink == videoUrl) video = vid.get() vidobj = dict() vidobj["videoname"] = str(video.name) vidobj["videolink"] = str(video.videolink) vidobj["videocat"] = str(video.videoCategory) vidobj["dubscount"] = str(video.dubsCount) vidobj["addeddate"] = str(video.addedDate) return json.dumps(vidobj)
def GetVideoDetails(self, videoUrl): vid = Video.query(Video.videolink == videoUrl) video = vid.get() vidobj = dict() vidobj["videoname"] = str(video.name.encode('utf-8')) vidobj["videolink"] = str(video.videolink) vidobj["videocat"] = str(video.videoCategory) vidobj["dubscount"] = str(video.dubsCount) vidobj["addeddate"] = str(video.addedDate) vidobj["videoGAEID"] = str(video.key.id()) vidobj["srtblobkey"] = str(video.srtBlobKey) return json.dumps(vidobj)
def GetVideoLinks(self, category, sortBy, offset, limit): # logging.info(category) if(sortBy == "time"): if(category == "all"): vidquery = Video.query().order(-Video.addedDate) else: vidquery = Video.query(Video.videoCategory == str(category)).order(-Video.addedDate) elif(sortBy == "dubscount"): if(category == "all"): vidquery = Video.query().order(-Video.dubsCount) else: vidquery = Video.query(Video.videoCategory == str(category)).order(-Video.dubsCount) if(limit == "" or limit == None): videos = vidquery.fetch(100) else: videos = vidquery.fetch(int(limit), offset=int(offset)) Videos = [] for video in videos: vidobj = dict() vidobj["videoname"] = str(video.name.encode('utf-8')) vidobj["videolink"] = str(video.videolink) vidobj["videocat"] = str(video.videoCategory) vidobj["dubscount"] = str(video.dubsCount) vidobj["addeddate"] = str(video.addedDate) vidobj["videoGAEID"] = str(video.key.id()) addedUser = video.addedUser if(addedUser != None and addedUser != ""): userQuery = User.query(ancestor=self.UserKey(addedUser)) user = userQuery.get() if(user != None): vidobj["userDisplayName"] = user.userDisplayName # vidobj["videoAddedBy"] = str(video.addedUser) # logging.info(video.key.id()) Videos.append(vidobj) return json.dumps(Videos)
def AddSrtToVideo(self, name, videoLink, uniqueID, srtBlobKey): vidKeys = Video.query(ancestor=self.VideoLink(videoLink)).fetch(1, keys_only=True) if(len(vidKeys) == 0): logging.info("Reaching AddSrtToVideo none: ") post = dict() post["error"] = "Video Not Found" return json.dumps(post) else: vidKey = vidKeys[0] vid = vidKey.get() vid.srtBlobKey = srtBlobKey vid.put() post = dict() logging.info("Reaching AddSrtToVideo after put: " + srtBlobKey + " videolink: " + videoLink) post["result"] = "Added new Srt file" return json.dumps(post)
def getVideoSearch(self, searchterm): vidquery = Video.query( ndb.AND(Video.name >= searchterm, Video.name <= searchterm + u'\ufffd')) videos = vidquery.fetch(100) # logging.info(str(videos)) Videos = [] for video in videos: vidobj = dict() vidobj["videoname"] = str(video.name) vidobj["videolink"] = str(video.videolink) vidobj["videocat"] = str(video.videoCategory) vidobj["dubscount"] = str(video.dubsCount) vidobj["addeddate"] = str(video.addedDate) Videos.append(vidobj) return json.dumps(Videos)
def AddNewVideo(self, name, videoLink, videocat, uniqueID): # v = self.VideoLink(videoLink) vidquery = Video.query(ancestor=self.VideoLink(videoLink)) videos = vidquery.get() if(videos != None): # logging.info(str(videos.videolink)) if(str(videos.videolink) == videoLink): post = dict() post["error"] = "Already Exists" return json.dumps(post) else: # userQuery=User.query(ancestor=self.UserKey(uniqueID)) # user = userQuery.get() # response = dict() # if(user != None): # # logging.info(str(user.uniqueID)) # videosByUser = [] # videosByUser = user.addedVideos # videosByUser.append(videoLink) # user.addedVideos = videosByUser # user.put() vid = Video(parent=self.VideoLink(videoLink)) # name="sample",videolink=videoLink,audiolink="",videoCategory="Entertainment" vid.name = str(name.encode('utf-8').lower()) vid.videolink = videoLink vid.audiolink = "" vid.videoCategory = videocat vid.dubsCount = 0 vid.addedDate = datetime.now() vid.addedUser = uniqueID vid.put() post = dict() post["result"] = "Added new video" return json.dumps(post)
def UpdateVideosObject(self): # goes through each video added by the user and assigns uniqueid to video # userQuery = User.query().fetch(500) #fetches all 500 users # videos = [] # resp = {} # for user in userQuery: # logging.info(user.uniqueID) # userID = user.uniqueID # videos = user.addedVideos # for vid in videos: # video = Video.query(ancestor = self.VideoLink(vid)) # vidobj = video.get() # if(vidobj != None): # logging.info(" HHHH "+str(vidobj.addedUser)) # if(vidobj.addedUser == None): # vidobj.addedUser = userID # vidobj.put() # resp["result"] ="modified success" # return resp # goes through each video added by the user and assigns uniqueid to video vidquery = Video.query() videos = vidquery.fetch(200) resp = {} for vid in videos: # logging.info(" HHHH "+str(vid.addedUser)) if(vid != None): # if(vid != None): # vidstatus = vid.status # if(vidstatus != None and vidname != ""): vid.status = "active" vid.put() resp["result"] = "modified success" return resp
def AddNewAudio(self, audioname, audioLink, videoLink, composer, composeremail, starttime, language, uniqueID): vid = Video.query(Video.videolink == videoLink) v = vid.get() v.dubsCount = int(v.dubsCount) + 1 v.put() # Generating a new UUID as the audio link aud = Audio(parent=self.AudioLink(videoLink)) aud.audiolink = audioLink aud.videolink = videoLink aud.name = audioname aud.upvotes = 0 aud.downvotes = 0 aud.composer = composer aud.composerEmail = composeremail aud.recordeddate = datetime.now() aud.starttime = starttime aud.language = language aud.viewCount = 0 aud.put() post = dict() post["result"] = audioLink return json.dumps(post)