def UserVotesAnAudio(self, audioKey, direction, uniqueID): userQuery = User.query(ancestor=self.UserKey(uniqueID)) user = userQuery.get() response = dict() if (user != None): if (direction == "up"): upVotedList = [] upVotedList = user.upVotedAudios q = Audio.query(Audio.audiolink == audioKey) aud = q.get() # if(upVoteStatus == "1"): upvotecount = aud.upvotes upvotecount = int(upvotecount) + 1 aud.upvotes = upvotecount upVotedList.append(audioKey) response["result"] = "Upvoted Successfully" user.upVotedAudios = upVotedList else: downVotedList = [] downVotedList = user.downVotedAudios q = Audio.query(Audio.audiolink == audioKey) aud = q.get() downvotecount = aud.downvotes downvotecount = int(downvotecount) + 1 aud.downvotes = downvotecount downVotedList.append(audioKey) response["result"] = "Downvoted Successfully" user.downVotedAudios = downVotedList user.put() aud.put() return json.dumps(response)
def IncreaseViewCount(self, audiokey, viewcount): q = Audio.query(Audio.audiolink == audiokey) aud = q.get() aud.viewCount = int(viewcount) aud.put() post = dict() post["result"] = "View count Incresed by 1" return json.dumps(post)
def GetAudiosList(self, videoLink, language, offset, limit, uniqueID, byUser, handle): if (language != ""): audquery = Audio.query(ancestor=self.AudioLink(videoLink)).filter( Audio.language == str(language)).order(-Audio.viewCount) elif (byUser == "true"): audquery = Audio.query( Audio.composer == handle).order(-Audio.recordeddate) else: audquery = Audio.query( ancestor=self.AudioLink(videoLink)).order(-Audio.viewCount) audios = audquery.fetch(int(limit), offset=int(offset)) Audios = [] upVotedList = [] downVotedList = [] if (uniqueID != ""): userQuery = User.query(ancestor=self.UserKey(uniqueID)) user = userQuery.get() response = dict() if (user != None): upVotedList = user.upVotedAudios downVotedList = user.downVotedAudios for audio in audios: aud = dict() aud["audname"] = audio.name aud["audkey"] = str(audio.audiolink) aud["composer"] = audio.composer aud["starttime"] = str(audio.starttime) aud["viewcount"] = str(audio.viewCount) aud["language"] = str(audio.language) aud["upvotes"] = str(audio.upvotes) aud["downvotes"] = str(audio.downvotes) aud["videolink"] = str(audio.videolink) aud["recordeddate"] = str(audio.recordeddate) aud["audioGAEID"] = str(audio.key.id()) # logging.info(upVotedList) if (audio.audiolink in upVotedList): aud["voted"] = "up" elif (audio.audiolink in downVotedList): aud["voted"] = "down" else: aud["voted"] = "none" # aud["audname"]=audio.name # logging.info(audio.audiolink) Audios.append(aud) return Audios
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 UpdateAudiosObject(self): audquery = Audio.query() audios = audquery.fetch(200) resp = {} for aud in audios: # logging.info(" HHHH "+str(vid.addedUser)) if(aud != None): aud.status = "active" aud.put() resp["result"] = "modified success" return resp
def UpdateUserDisplayName(self, uniqueID, newName): userQuery = User.query(ancestor=self.UserKey(uniqueID)) user = userQuery.get() response = dict() if (user != None): audquery = Audio.query(Audio.composerEmail == uniqueID) audios = audquery.fetch() for audio in audios: audio.composer = newName audio.put() user.userDisplayName = newName user.put() response["newName"] = newName return response
def ModifyAudioMetadata(self, audioKey, AudioName, AudioLang, starttime): logging.info(audioKey) audio = Audio.query(Audio.audiolink == audioKey) audobj = audio.get() if(AudioName != "" and AudioName != None): audobj.name = AudioName if(AudioLang != "" and AudioLang != None): audobj.language = AudioLang if(starttime != "" and starttime != None): audobj.starttime = starttime audobj.put() resp = {} resp["response"] = "success" return resp
def GetAudioByLink(self, videoLink): audquery = Audio.query( ancestor=self.AudioLink(videoLink)).order(-Audio.viewCount) audios = audquery.fetch(100) Audios = [] for audio in audios: aud = dict() aud["audname"] = audio.name aud["audkey"] = str(audio.audiolink) aud["composer"] = audio.composer aud["starttime"] = str(audio.starttime) aud["viewcount"] = str(audio.viewCount) aud["language"] = str(audio.language) # aud["audname"]=audio.name logging.info(audio.audiolink) Audios.append(aud) return json.dumps(Audios)
def UserUpVotesAnAudio(self, audioKey, upVoteStatus, uniqueID): userQuery = User.query(ancestor=self.UserKey(uniqueID)) user = userQuery.get() response = {} if (user != None): upVotedList = [] upVotedList = user.upVotedAudios q = Audio.query(Audio.audiolink == audioKey) aud = q.get() # if(upVoteStatus == "1"): upvotecount = aud.upvotes upvotecount = int(upvotecount) + 1 aud.upvotes = upvotecount upVotedList.append(audioKey) response["upvoteIncreased"] = "Upvoted Successfully" user.upVotedAudios = upVotedList user.put() aud.put()
def GetAudioDetails(self, audkey, uniqueID): upVotedList = [] downVotedList = [] if(str(uniqueID) != ""): userQuery = User.query(ancestor=self.UserKey(uniqueID)) user = userQuery.get() if(user != None): upVotedList = user.upVotedAudios downVotedList = user.downVotedAudios q = Audio.query(Audio.audiolink == audkey) # q = ndb.gql("Select * from Audio where audioblobkey = :1",audBlobkey) Audios = [] audio = q.get() # logging.info(audio) if(audio != None): aud = dict() aud["audname"] = audio.name aud["audkey"] = str(audio.audiolink) aud["composer"] = audio.composer aud["starttime"] = str(audio.starttime) aud["viewcount"] = str(audio.viewCount) aud["language"] = str(audio.language) aud["upvotes"] = str(audio.upvotes) aud["downvotes"] = str(audio.downvotes) aud["recordeddate"] = str(audio.recordeddate) aud["audioGAEID"] = str(audio.key.id()) if(audkey in upVotedList): aud["voted"] = "up" elif(audkey in downVotedList): aud["voted"] = "down" else: aud["voted"] = "none" # aud["audname"]=audio.name Audios.append(aud) else: aud = dict() aud["error"] = "Url contains in valid audio key" Audios.append(aud) return json.dumps(Audios)
def GetAudiosListByDate(self, offset, limit, startdate, enddate): startdate = datetime.strptime(startdate, '%Y-%m-%d') enddate = datetime.strptime(enddate, '%Y-%m-%d') # logging.info(startdate) audquery = Audio.query(Audio.recordeddate >= startdate, Audio.recordeddate <= enddate) audios = audquery.fetch(int(limit), offset=int(offset)) Audios = [] # upVotedList=[] # downVotedList=[] # if(uniqueID != ""): # userQuery=User.query(ancestor=self.UserKey(uniqueID)) # user = userQuery.get() # response = dict() # if(user != None): # upVotedList = user.upVotedAudios # downVotedList = user.downVotedAudios for audio in audios: aud = dict() aud["audname"] = audio.name aud["audkey"] = str(audio.audioblobkey) aud["userDisplayName"] = audio.composer aud["uniqueID"] = str(audio.composerEmail) uniqueID = audio.composerEmail userQuery = User.query(ancestor=self.UserKey(uniqueID)) user = userQuery.get() if(user != None): aud["userName"] = user.userName aud["starttime"] = str(audio.starttime) aud["viewcount"] = str(audio.viewCount) aud["language"] = str(audio.language) aud["upvotes"] = str(audio.upvotes) aud["downvotes"] = str(audio.downvotes) aud["videolink"] = str(audio.videolink) aud["recordeddate"] = str(audio.recordeddate) aud["audioGAEID"] = str(audio.key.id()) Audios.append(aud) return Audios
def UserDownVotesAnAudio(self, audioKey, downVoteStatus, uniqueID): userQuery = User.query(ancestor=self.UserKey(uniqueID)) user = userQuery.get() response = dict() if (user != None): downVotedList = [] downVotedList = user.downVotedAudios q = Audio.query(Audio.audiolink == audioKey) aud = q.get() if (downVoteStatus == "1"): downvotecount = aud.downvotes downvotecount = int(downvotecount) + 1 aud.downvotes = downvotecount downVotedList.append(audioKey) response["downvoteIncreased"] = "downvoted Successfully" else: downvotecount = aud.downvotes downvotecount = int(downvotecount) - 1 aud.downvotes = downvotecount downVotedList.remove(audioKey) response["downvoteReduced"] = "downvote Reduced Successfully" user.downVotedAudios = downVotedList user.put() aud.put()
def GetAudioDetails(self, audkey): # audquery = Audio.query(ancestor=self.AudioLink(videoLink)) q = Audio.query(Audio.audiolink == audkey) # q = ndb.gql("Select * from Audio where audioblobkey = :1",audBlobkey) Audios = [] audio = q.get() logging.info(audio) if (audio != None): aud = dict() aud["audname"] = audio.name aud["audkey"] = str(audio.audiolink) aud["composer"] = audio.composer aud["starttime"] = str(audio.starttime) aud["viewcount"] = str(audio.viewCount) aud["language"] = str(audio.language) # aud["audname"]=audio.name Audios.append(aud) else: aud = dict() aud["error"] = "Url contains in valid audio key" Audios.append(aud) return json.dumps(Audios)
def GetAudioSearch(self, searchterm, videoLink): audquery = Audio.query(ancestor=self.AudioLink(videoLink)).filter(ndb.AND(Audio.name >= searchterm, Audio.name <= searchterm + u'\ufffd')) # audquery=Audio.query() audios = audquery.fetch(100) # logging.info(str(videos)) Audios = [] for audio in audios: audobj = dict() audobj["audioname"] = str(audio.name) audobj["audiokey"] = str(audio.audiolink) audobj["viewcount"] = str(audio.viewCount) audobj["language"] = str(audio.language) audobj["upvotes"] = str(audio.upvotes) audobj["downvotes"] = str(audio.downvotes) audobj["recordeddate"] = str(audio.recordeddate) audobj["audioGAEID"] = str(audio.key.id()) Audios.append(audobj) return json.dumps(Audios)
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)
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 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)