예제 #1
0
파일: app.py 프로젝트: sadikovi/still-wave
 def get(self):
     self.response.headers['Content-Type'] = "application/json"
     user = users.get_current_user()
     if not user:
         res = Error(401, "Not authenticated")
         self.response.set_status(res.code())
         self.response.out.write(json.dumps(res.json()))
     else:
         query = misc.unquoteParam(self.request.get("q"))
         page = misc.unquoteParam(self.request.get("p"))
         if not query:
             res = Error(400, "Query is empty or undefined")
             self.response.set_status(res.code())
             self.response.out.write(json.dumps(res.json()))
         else:
             res = manager.searchAlbum(user.user_id(), query, page)
             self.response.set_status(res.code())
             self.response.out.write(json.dumps(res.json()))
예제 #2
0
파일: app.py 프로젝트: sadikovi/still-wave
 def get(self):
     self.response.headers['Content-Type'] = "application/json"
     user = users.get_current_user()
     if not user:
         res = Error(401, "Not authenticated")
         self.response.set_status(res.code())
         self.response.out.write(json.dumps(res.json()))
     else:
         query = misc.unquoteParam(self.request.get("q"))
         page = misc.unquoteParam(self.request.get("p"))
         if not query:
             res = Error(400, "Query is empty or undefined")
             self.response.set_status(res.code())
             self.response.out.write(json.dumps(res.json()))
         else:
             res = manager.searchAlbum(user.user_id(), query, page)
             self.response.set_status(res.code())
             self.response.out.write(json.dumps(res.json()))
예제 #3
0
파일: app.py 프로젝트: sadikovi/still-wave
 def get(self):
     self.response.headers['Content-Type'] = "application/json"
     user = users.get_current_user()
     if not user:
         res = Error(401, "Not authenticated")
         self.response.set_status(res.code())
         self.response.out.write(json.dumps(res.json()))
     else:
         albumid = misc.unquoteParam(self.request.get("albumid"))
         # check album and artist
         res = manager.dislike(user.user_id(), albumid)
         self.response.set_status(res.code())
         self.response.out.write(json.dumps(res.json()))
예제 #4
0
파일: app.py 프로젝트: sadikovi/still-wave
 def get(self):
     self.response.headers['Content-Type'] = "application/json"
     user = users.get_current_user()
     if not user:
         res = Error(401, "Not authenticated")
         self.response.set_status(res.code())
         self.response.out.write(json.dumps(res.json()))
     else:
         albumid = misc.unquoteParam(self.request.get("albumid"))
         # check album and artist
         res = manager.dislike(user.user_id(), albumid)
         self.response.set_status(res.code())
         self.response.out.write(json.dumps(res.json()))
예제 #5
0
 def similarSongs(self, album, totalsongs=[], sim_container=set()):
     # fetch songs that similar to liked albums
     # limits are used
     for song in album.songs():
         # get similar songs
         similarsongs = self.db.getSimilarSongs(song.id())
         if similarsongs:
             print "[!] Similar songs found in Redis"
         else:
             # limit on loading albums
             if len(sim_container) > self._processinglimit:
                 print "[!] Processing limit is reached. No download"
                 continue
             # initialise to empty set
             similarsongs = set()
             # check source of the album
             if album.ispandora():
                 print "[!] Similar songs absent. Load from Pandora"
                 # load song info
                 res = req.loadSongById(song.id())
                 if type(res) is Error:
                     print "[!] Request for similar songs for %s (%s-%s) failed" % (
                         song.id(), album.name(), album.artist())
                 elif type(res) is Success and res.data():
                     # song is found, parse it
                     data = res.data()
                     similar = data["songExplorer"]["similar"]
                     for item in similar:
                         itemid = misc.getShareUrlId(item["@shareUrl"])
                         itempath = misc.getUrlPath(item["@trackDetailUrl"])
                         pathelems = [
                             misc.unquoteParam(x)
                             for x in itempath.split("/")
                         ]
                         if len(pathelems) > 2:
                             artist, albumname = pathelems[-3:-1]
                             sim_container.add((artist, albumname))
                             similarsongs.add(itemid)
                         else:
                             print "[!] Track detail url %s cant be parsed" % (
                                 item["@trackDetailUrl"])
                             print "[!] Song %s will be ignored" % (
                                 item["@shareUrl"])
             else:
                 print "[!] Similar songs absent. Load from Last.fm"
                 print "[!] Functionality under development"
                 """
                 mbid = album.mbid()
                 if not mbid:
                     print "[!] Album mbid is empty or None. Cant do anything about it"
                     continue
                 # fetch data from last.fm
                 res = req.loadSongById(song.id(), ispandora=False)
                 if type(res) is Error:
                     print "[!] Request for similar songs for %s (%s-%s) failed" %(song.id(), album.name(), album.artist())
                 elif type(res) is Success and res.data():
                     similar = data["similartracks"]
                     tracks = similar["track"] if "track" in similar else []
                     tracks = [tracks] if type(tracks) is DictType else tracks
                     for track in tracks:
                         trackid = track["mbid"]
                         artist, album = track["artist"]["name"], None
                         sim_container.add((artist, album))
                         similarsongs.add(trackid)
                 """
             # add similar songs to the song
             self.db.addSimilarSongs(song.id(), similarsongs)
         # songs are found in Redis or found on Pandora / dont exist
         for x in similarsongs:
             totalsongs.append(x) if x else None
     # return total songs
     return totalsongs