コード例 #1
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def getLicense_view(self, **kwargs):
     # Called after ping.view
     response = ApiResponse()
     response.add_child("license",
                        valid="true",
                        email="admin@localhost",
                        licenseExpires="2100-01-01T00:00:00.000Z",
                        trialExpires="2100-01-01T01:01:00.000Z")
     return response
コード例 #2
0
ファイル: api.py プロジェクト: dpedu/pysonic
    def deletePlaylist_view(self, id, **kwargs):
        user = self.library.db.get_user(cherrypy.request.login)
        plinfo, _ = self.library.get_playlist(int(id))
        assert plinfo["ownerid"] == user["id"]

        self.library.delete_playlist(plinfo["id"])
        return ApiResponse()
コード例 #3
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def scrobble_view(self, id, submission, **kwargs):
     """
     :param id: song id being played
     :param submission: True if end of song reached. False on start of track.
     """
     submission = True if submission == "true" else False
     # TODO save played track stats and/or do last.fm bullshit
     return ApiResponse()
コード例 #4
0
ファイル: api.py プロジェクト: dpedu/pysonic
    def getAlbumList_view(self, type, size=250, offset=0, **kwargs):
        qargs = {}
        if type == "random":
            qargs.update(sortby="random")
        elif type == "alphabeticalByName":
            qargs.update(sortby="name", order="asc")
        elif type == "newest":
            qargs.update(sortby="added", order="desc")
        elif type == "recent":
            qargs.update(sortby="played", order="desc")
        elif type == "frequent":
            qargs.update(sortby="plays", order="desc")

        qargs.update(limit=(offset, size))

        albums = self.library.get_albums(**qargs)

        response = ApiResponse()

        response.add_child("albumList")

        for album in albums:
            album_kw = dict(id=album["dir"],
                            parent=album["artistdir"],
                            isDir="true",
                            title=album["name"],
                            album=album["name"],
                            artist=album["artistname"],
                            coverArt=album["coverid"]
                            #year=TODO
                            # playCount="0"
                            # created="2016-05-08T05:31:31.000Z"/>)
                            )
            response.add_child("album", _parent="albumList", **album_kw)
        return response
コード例 #5
0
ファイル: api.py プロジェクト: dpedu/pysonic
    def getMusicDirectory_view(self, id, **kwargs):
        """
        List an artist dir
        """
        dir_id = int(id)
        dirtype, dirinfo, entity = self.library.db.get_subsonic_musicdir(dirid=dir_id)

        response = ApiResponse()
        response.add_child("directory")
        response.set_attrs(_path="directory", name=entity['name'], id=entity['id'],
                           parent=dirinfo['parent'], playCount=420)

        for childtype, child in entity["children"]:
            # omit not dirs and media in browser
            # if not item["isdir"] and item["type"] not in MUSIC_TYPES:
            #     continue
            # item_meta = item['metadata']
            moreargs = {}
            if childtype == "album":
                moreargs.update(name=child["name"],
                                isDir="true",  # TODO song files in artist dir
                                parent=entity["id"],
                                id=child["dir"])
                if child["coverid"]:
                    moreargs.update(coverArt=child["coverid"])
                # album=item["name"],
                #                title=item["name"],  # TODO dupe?
                #                artist=artist["name"],
                #                coverArt=item["coverid"],
            elif childtype == "song":
                moreargs.update(name=child["title"],
                                artist=child["_artist"]["name"],
                                contentType=child["format"],
                                id=child["id"],
                                duration=child["length"],
                                isDir="false",
                                parent=entity["dir"],
                                # title=xxx
                                )
                if entity["coverid"]:
                    moreargs.update(coverArt=entity["coverid"])
                # duration="230" size="8409237" suffix="mp3" track="2"  year="2005"/>
            response.add_child("child", _parent="directory",
                               size="4096",
                               type="music",
                               **moreargs)

        cherrypy.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
        return response
コード例 #6
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def getUser_view(self, username, **kwargs):
     user = {} if self.options.disable_auth else self.library.db.get_user(cherrypy.request.login)
     response = ApiResponse()
     response.add_child("user",
                        username=user["username"],
                        email=user["email"],
                        scrobblingEnabled="false",
                        adminRole="true" if user["admin"] else "false",
                        settingsRole="false",
                        downloadRole="true",
                        uploadRole="false",
                        playlistRole="true",
                        coverArtRole="false",
                        commentRole="false",
                        podcastRole="false",
                        streamRole="true",
                        jukeboxRole="false",
                        shareRole="true",
                        videoConversionRole="false",
                        avatarLastChanged="2017-08-07T20:16:24.596Z",
                        folder=0)
     return response
コード例 #7
0
ファイル: api.py プロジェクト: dpedu/pysonic
    def updatePlaylist_view(self, playlistId, songIndexToRemove=None, songIdToAdd=None, **kwargs):
        user = self.library.db.get_user(cherrypy.request.login)
        plinfo, songs = self.library.get_playlist(int(playlistId))

        assert plinfo["ownerid"] == user["id"]

        if songIndexToRemove:
            self.library.db.remove_index_from_playlist(playlistId, songIndexToRemove)
        elif songIdToAdd:
            self.library.db.add_to_playlist(playlistId, songIdToAdd)
        #TODO there are more modification methods

        return ApiResponse()
コード例 #8
0
ファイル: api.py プロジェクト: dpedu/pysonic
    def search2_view(self, query, artistCount, albumCount, songCount, **kwargs):
        response = ApiResponse()
        response.add_child("searchResult2")

        artistCount = int(artistCount)
        albumCount = int(albumCount)
        songCount = int(songCount)

        query = query.replace("*", "")  # TODO handle this

        artists = 0
        for item in self.library.get_artists():
            if query in item["name"].lower():
                response.add_child("artist", _parent="searchResult2", id=item["id"], name=item["name"])
                artists += 1
                if artists >= artistCount:
                    break

        # TODO make this more efficient
        albums = 0
        for item in self.library.get_artists():
            if query in item["name"].lower():
                response.add_child("album", _parent="searchResult2", **self.render_node(item, item["metadata"], {}, {}))
                albums += 1
                if albums >= albumCount:
                    break

        # TODO make this more efficient
        songs = 0
        for item in self.library.get_songs(limit=9999999, shuffle=False):
            if query in item["name"].lower():
                response.add_child("song", _parent="searchResult2", **self.render_node(item, item["metadata"], {}, {}))
                songs += 1
                if songs > songCount:
                    break

        return response
コード例 #9
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def getIndexes_view(self, **kwargs):
     # Get listing of top-level dir
     response = ApiResponse()
     # TODO real lastmodified date
     # TODO deal with ignoredArticles
     response.add_child("indexes", lastModified="1502310831000", ignoredArticles="The El La Los Las Le Les")
     artists = self.library.get_artists(sortby="name", order="asc")
     for letter in LETTER_GROUPS:
         index = response.add_child("index", _parent="indexes", name=letter.upper())
         for artist in artists:
             if artist["name"][0].lower() in letter:
                 response.add_child("artist", _real_parent=index, id=artist["dir"], name=artist["name"])
     return response
コード例 #10
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def getStarred_view(self, **kwargs):
     children = self.library.get_starred(cherrypy.request.login)
     response = ApiResponse()
     response.add_child("starred")
     for item in children:
         # omit not dirs and media in browser
         if not item["isdir"] and item["type"] not in MUSIC_TYPES:
             continue
         item_meta = item['metadata']
         itemtype = "song" if item["type"] in MUSIC_TYPES else "album"
         response.add_child(itemtype, _parent="starred", **self.render_node(item, item_meta, {}, {}))
     return response
コード例 #11
0
ファイル: api.py プロジェクト: dpedu/pysonic
    def getPlaylists_view(self, **kwargs):
        user = self.library.db.get_user(cherrypy.request.login)

        response = ApiResponse()
        response.add_child("playlists")
        for playlist in self.library.db.get_playlists(user["id"]):
            response.add_child("playlist",
                               _parent="playlists",
                               id=playlist["id"],
                               name=playlist["name"],
                               owner=user["username"],
                               public=playlist["public"],
                               songCount=69,
                               duration=420,
                               # changed="2018-04-05T23:23:38.263Z"
                               # created="2018-04-05T23:23:38.252Z"
                               # coverArt="pl-1"
                               )

        return response
コード例 #12
0
ファイル: api.py プロジェクト: dpedu/pysonic
    def getPlaylist_view(self, id, **kwargs):
        user = self.library.db.get_user(cherrypy.request.login)
        plinfo, songs = self.library.get_playlist(int(id))

        response = ApiResponse()
        response.add_child("playlist",
                           id=plinfo["id"],
                           name=plinfo["name"],  # TODO this element should match getPlaylists_view
                           owner=user["username"],  # TODO translate id to name
                           public=plinfo["public"],
                           songCount=69,
                           duration=420)
        for song in songs:
            response.add_child("entry",
                               _parent="playlist",
                               id=song["id"],
                               parent=song["albumid"],  # albumid seems wrong? should be dir parent?
                               isDir="false",
                               title=song["title"],
                               album=song["albumname"],
                               artist=song["artistname"],
                               track=song["track"],
                               year=song["year"],
                               genre=song["genrename"],
                               coverArt=song["albumcoverid"],
                               size=song["size"],
                               contentType=song["format"],
                               # suffix="mp3"
                               duration=song["length"],
                               bitRate=song["bitrate"] / 1024,
                               path=song["file"],
                               playCount="1",
                               # created="2015-06-09T15:26:01.000Z"
                               albumId=song["albumid"],
                               artistId=song["artistid"],
                               type="music")
        return response
コード例 #13
0
ファイル: api.py プロジェクト: dpedu/pysonic
    def getRandomSongs_view(self, size=50, genre=None, fromYear=0, toYear=0, **kwargs):
        """
        Get a playlist of random songs
        :param genre: genre name to find songs under
        :type genre: str
        """
        response = ApiResponse()
        response.add_child("randomSongs")
        children = self.library.db.get_songs(limit=size, sortby="random")
        for song in children:
            moreargs = {}
            if song["format"]:
                moreargs.update(contentType=song["format"])
            if song["albumcoverid"]:
                moreargs.update(coverArt=song["albumcoverid"])
            if song["length"]:
                moreargs.update(duration=song["length"])
            if song["track"]:
                moreargs.update(track=song["track"])
            if song["year"]:
                moreargs.update(year=song["year"])

            file_extension = song["file"].split(".")[-1]

            response.add_child("song",
                               _parent="randomSongs",
                               title=song["title"],
                               album=song["albumname"],
                               artist=song["artistname"],
                               id=song["id"],
                               isDir="false",
                               parent=song["albumid"],
                               size=song["size"],
                               suffix=file_extension,
                               type="music",
                               **moreargs)
        return response
コード例 #14
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def getArtistInfo_view(self, id, includeNotPresent="true", **kwargs):
     info = self.library.get_artist_info(id)
     response = ApiResponse()
     response.add_child("artistInfo")
     response.set_attrs("artistInfo", **info)
     return response
コード例 #15
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def getMusicFolders_view(self, **kwargs):
     response = ApiResponse()
     response.add_child("musicFolders")
     for folder in self.library.get_libraries():
         response.add_child("musicFolder", _parent="musicFolders", id=folder["id"], name=folder["name"])
     return response
コード例 #16
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def createPlaylist_view(self, name, songId, **kwargs):
     if type(songId) != list:
         songId = [songId]
     user = self.library.db.get_user(cherrypy.request.login)
     self.library.db.add_playlist(user["id"], name, songId)
     return ApiResponse()
コード例 #17
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def index(self):
     response = ApiResponse()
     response.add_child("totals", **self.library.db.get_stats())
     return response
コード例 #18
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def getGenres_view(self, **kwargs):
     response = ApiResponse()
     response.add_child("genres")
     for row in self.library.db.get_genres():
         response.add_child("genre", _parent="genres", value=row["name"], songCount=420, albumCount=69)
     return response
コード例 #19
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def unstar_view(self, id, **kwargs):
     self.library.set_starred(cherrypy.request.login, int(id), starred=False)
     return ApiResponse()
コード例 #20
0
ファイル: api.py プロジェクト: dpedu/pysonic
 def ping_view(self, **kwargs):
     # Called when the app hits the "test connection" server option
     return ApiResponse()