コード例 #1
0
    def get_track(self, track_id):
        """
            Return spotify track as SearchItem
            @param track id as str
            @return SearchItem
        """
        try:
            s = Lio.File.new_for_uri("https://api.spotify.com/v1/"
                                     "tracks/%s" % track_id)
            (status, data, tag) = s.load_contents(self._cancel)
            if status:
                decode = json.loads(data.decode('utf-8'))
                album_item = SearchItem()
                album_item.name = decode['album']['name']
                album_item.cover = decode['album']['images'][0]['url']
                album_item.smallcover = decode['album']['images'][2]['url']

                track_item = SearchItem()
                track_item.is_track = True
                track_item.name = decode['name']
                track_item.album = album_item
                track_item.tracknumber = int(
                                          decode['track_number'])
                track_item.discnumber = int(
                                           decode['disc_number'])
                track_item.duration = int(
                                    decode['duration_ms']) / 1000
                for artist in decode['artists']:
                    track_item.artists.append(artist['name'])
                album_item.artists = track_item.artists
                album_item.subitems.append(track_item)
                return album_item
        except Exception as e:
            print("SpotifySearch::get_track", e)
        return None
コード例 #2
0
ファイル: search_spotify.py プロジェクト: wiccasoft/lollypop
    def get_track(self, track_id):
        """
            Return spotify track as SearchItem
            @param track id as str
            @return SearchItem
        """
        try:
            s = Lio.File.new_for_uri("https://api.spotify.com/v1/"
                                     "tracks/%s" % track_id)
            (status, data, tag) = s.load_contents(self._cancel)
            if status:
                decode = json.loads(data.decode("utf-8"))
                album_item = SearchItem()
                album_item.name = decode["album"]["name"]
                album_item.cover = decode["album"]["images"][0]["url"]
                album_item.smallcover = decode["album"]["images"][2]["url"]

                track_item = SearchItem()
                track_item.is_track = True
                track_item.name = decode["name"]
                track_item.album = album_item
                track_item.tracknumber = int(
                                          decode["track_number"])
                track_item.discnumber = int(
                                           decode["disc_number"])
                track_item.duration = int(
                                    decode["duration_ms"]) / 1000
                for artist in decode["artists"]:
                    track_item.artists.append(artist["name"])
                album_item.artists = track_item.artists
                album_item.subitems.append(track_item)
                return album_item
        except Exception as e:
            print("SpotifySearch::get_track", e)
        return None
コード例 #3
0
ファイル: search_itunes.py プロジェクト: jeims17/lollypop
 def __get_albums(self, name):
     """
         Get albums for name
         @param name as str
     """
     try:
         # Read album list
         formated = Lio.uri_escape_string(name, None,
                                          True).replace(' ', '+')
         s = Lio.File.new_for_uri("https://itunes.apple.com/search"
                                  "?entity=album&term=%s" % formated)
         (status, data, tag) = s.load_contents(self._cancel)
         if not status:
             raise
         decode = json.loads(data.decode('utf-8'))
         # For each album, get cover and tracks
         for item in decode['results']:
             album_item = SearchItem()
             album_item.name = album_item.album_name =\
                 item['collectionName']
             album_item.is_track = False
             album_item.artists = [item['artistName']]
             album_item.cover = item['artworkUrl60'].replace(
                 '60x60', '512x512')
             album_item.smallcover = item['artworkUrl100']
             s = Lio.File.new_for_uri("https://itunes.apple.com/lookup"
                                      "?id=%s&entity=song" %
                                      item['collectionId'])
             (status, data, tag) = s.load_contents(self._cancel)
             if not status:
                 raise
             decode = json.loads(data.decode('utf-8'))
             for item in decode['results']:
                 if item['wrapperType'] == "collection":
                     continue
                 track_item = SearchItem()
                 track_item.is_track = True
                 try:
                     track_item.year = decode['releaseDate'][:4]
                 except:
                     pass  # May be missing
                 track_item.name = item['trackName']
                 track_item.album = album_item.name
                 track_item.tracknumber = int(item['trackNumber'])
                 track_item.discnumber = int(item['discNumber'])
                 track_item.duration = int(item['trackTimeMillis'])\
                     / 1000
                 track_item.artists.append(item['artistName'])
                 album_item.subitems.append(track_item)
             self._items.append(album_item)
             GLib.idle_add(self.emit, 'item-found')
     except Exception as e:
         print("ItunesSearch::__get_albums(): %s" % e)
コード例 #4
0
 def __get_albums(self, name):
     """
         Get albums for name
         @param name as str
     """
     try:
         # Read album list
         formated = GLib.uri_escape_string(name, None, True).replace(
                                                                   ' ', '+')
         s = Lio.File.new_for_uri("https://itunes.apple.com/search"
                                  "?entity=album&term=%s" % formated)
         (status, data, tag) = s.load_contents(self._cancel)
         if not status:
             raise
         decode = json.loads(data.decode('utf-8'))
         # For each album, get cover and tracks
         for item in decode['results']:
             album_item = SearchItem()
             album_item.name = item['collectionName']
             album_item.is_track = False
             album_item.artists = [item['artistName']]
             album_item.cover = item['artworkUrl60'].replace('60x60',
                                                             '512x512')
             album_item.smallcover = item['artworkUrl100']
             s = Lio.File.new_for_uri("https://itunes.apple.com/lookup"
                                      "?id=%s&entity=song" %
                                      item['collectionId'])
             (status, data, tag) = s.load_contents(self._cancel)
             if not status:
                 raise
             decode = json.loads(data.decode('utf-8'))
             for item in decode['results']:
                 if item['wrapperType'] == "collection":
                     continue
                 track_item = SearchItem()
                 track_item.is_track = True
                 try:
                     track_item.year = decode['releaseDate'][:4]
                 except:
                     pass  # May be missing
                 track_item.name = item['trackName']
                 track_item.album = album_item
                 track_item.tracknumber = int(item['trackNumber'])
                 track_item.discnumber = int(item['discNumber'])
                 track_item.duration = int(item['trackTimeMillis'])\
                     / 1000
                 track_item.artists.append(item['artistName'])
                 album_item.subitems.append(track_item)
             self._items.append(album_item)
             GLib.idle_add(self.emit, 'item-found')
     except Exception as e:
         print("ItunesSearch::__get_albums(): %s" % e)
コード例 #5
0
 def __get_albums(self, name):
     """
         Get albums for name
         @param name as str
     """
     try:
         # Read album list
         formated = GLib.uri_escape_string(name, None,
                                           True).replace(" ", "+")
         s = Lio.File.new_for_uri("https://api.spotify.com/v1/search?q=%s"
                                  "&type=album" % formated)
         s.add_spotify_headers(self.__token)
         (status, data, tag) = s.load_contents(self._cancel)
         if status:
             decode = json.loads(data.decode("utf-8"))
             # For each album, get cover and tracks
             for item in decode["albums"]["items"]:
                 album_item = SearchItem()
                 album_item.name = item["name"]
                 album_item.is_track = False
                 album_item.cover = item["images"][0]["url"]
                 album_item.smallcover = item["images"][2]["url"]
                 s = Lio.File.new_for_uri("https://api.spotify.com/v1/"
                                          "albums/%s" % item["id"])
                 s.add_spotify_headers(self.__token)
                 (status, data, tag) = s.load_contents(self._cancel)
                 if status:
                     decode = json.loads(data.decode("utf-8"))
                     for item in decode["tracks"]["items"]:
                         track_item = SearchItem()
                         track_item.is_track = True
                         try:
                             track_item.year = decode["release_date"][:4]
                         except:
                             pass  # May be missing
                         track_item.name = item["name"]
                         track_item.album = album_item
                         track_item.tracknumber = int(item["track_number"])
                         track_item.discnumber = int(item["disc_number"])
                         track_item.duration = int(item["duration_ms"])\
                             / 1000
                         for artist in item["artists"]:
                             track_item.artists.append(artist["name"])
                         if not album_item.artists:
                             album_item.artists = track_item.artists
                         album_item.subitems.append(track_item)
                 self._items.append(album_item)
                 GLib.idle_add(self.emit, "item-found")
     except Exception as e:
         print("SpotifySearch::albums(): %s" % e)
コード例 #6
0
 def __get_albums(self, name):
     """
         Get albums for name
         @param name as str
     """
     try:
         # Read album list
         formated = GLib.uri_escape_string(name, None, True).replace(
                                                                   ' ', '+')
         s = Lio.File.new_for_uri("https://api.spotify.com/v1/search?q=%s"
                                  "&type=album" % formated)
         (status, data, tag) = s.load_contents(self._cancel)
         if status:
             decode = json.loads(data.decode('utf-8'))
             # For each album, get cover and tracks
             for item in decode['albums']['items']:
                 album_item = SearchItem()
                 album_item.name = item['name']
                 album_item.is_track = False
                 album_item.cover = item['images'][0]['url']
                 album_item.smallcover = item['images'][2]['url']
                 s = Lio.File.new_for_uri("https://api.spotify.com/v1/"
                                          "albums/%s" % item['id'])
                 (status, data, tag) = s.load_contents(self._cancel)
                 if status:
                     decode = json.loads(data.decode('utf-8'))
                     for item in decode['tracks']['items']:
                         track_item = SearchItem()
                         track_item.is_track = True
                         try:
                             track_item.year = decode[
                                                     'release_date'][:4]
                         except:
                             pass  # May be missing
                         track_item.name = item['name']
                         track_item.album = album_item
                         track_item.tracknumber = int(item['track_number'])
                         track_item.discnumber = int(item['disc_number'])
                         track_item.duration = int(item['duration_ms'])\
                             / 1000
                         for artist in item['artists']:
                             track_item.artists.append(artist['name'])
                         if not album_item.artists:
                             album_item.artists = track_item.artists
                         album_item.subitems.append(track_item)
                 self._items.append(album_item)
                 GLib.idle_add(self.emit, 'item-found')
     except Exception as e:
         print("SpotifySearch::albums(): %s" % e)
コード例 #7
0
ファイル: search_spotify.py プロジェクト: sujithcp/lollypop
 def __get_albums(self, name):
     """
         Get albums for name
         @param name as str
     """
     try:
         # Read album list
         formated = GLib.uri_escape_string(name, None,
                                           True).replace(' ', '+')
         s = Gio.File.new_for_uri("https://api.spotify.com/v1/search?q=%s"
                                  "&type=album" % formated)
         (status, data, tag) = s.load_contents(self._cancel)
         if status:
             decode = json.loads(data.decode('utf-8'))
             # For each album, get cover and tracks
             for item in decode['albums']['items']:
                 album_item = SearchItem()
                 album_item.name = album_item.album_name = item['name']
                 album_item.is_track = False
                 album_item.cover = item['images'][0]['url']
                 album_item.smallcover = item['images'][2]['url']
                 s = Gio.File.new_for_uri("https://api.spotify.com/v1/"
                                          "albums/%s" % item['id'])
                 (status, data, tag) = s.load_contents(self._cancel)
                 if status:
                     decode = json.loads(data.decode('utf-8'))
                     for item in decode['tracks']['items']:
                         track_item = SearchItem()
                         track_item.is_track = True
                         try:
                             track_item.year = decode['release_date'][:4]
                         except:
                             pass  # May be missing
                         track_item.name = item['name']
                         track_item.album = album_item.name
                         track_item.tracknumber = int(item['track_number'])
                         track_item.discnumber = int(item['disc_number'])
                         track_item.duration = int(item['duration_ms'])\
                             / 1000
                         for artist in item['artists']:
                             track_item.artists.append(artist['name'])
                         if not album_item.artists:
                             album_item.artists = track_item.artists
                         album_item.subitems.append(track_item)
                 self._items.append(album_item)
                 GLib.idle_add(self.emit, 'item-found')
     except Exception as e:
         print("SpotifySearch::albums(): %s" % e)
コード例 #8
0
ファイル: search_spotify.py プロジェクト: wiccasoft/lollypop
 def get_album(self, album_id):
     """
         Return spotify album as SearchItem
         @param album id as str
         @return SearchItem
     """
     try:
         s = Lio.File.new_for_uri("https://api.spotify.com/v1/"
                                  "albums/%s" % album_id)
         (status, data, tag) = s.load_contents(self._cancel)
         if status:
             decode = json.loads(data.decode("utf-8"))
             album_item = SearchItem()
             album_item.name = decode["name"]
             album_item.cover = decode["images"][0]["url"]
             album_item.smallcover = decode["images"][2]["url"]
             album_item.ex_id = album_id
             for item in decode["tracks"]["items"]:
                 track_item = SearchItem()
                 track_item.is_track = True
                 track_item.name = item["name"]
                 track_item.album = album_item.name
                 try:
                     track_item.year = decode[
                                             "release_date"][:4]
                 except:
                     pass  # May be missing
                 track_item.tracknumber = int(
                                           item["track_number"])
                 track_item.discnumber = int(
                                            item["disc_number"])
                 track_item.duration = int(
                                     item["duration_ms"]) / 1000
                 for artist in item["artists"]:
                     track_item.artists.append(artist["name"])
                 if not album_item.artists:
                     album_item.artists = track_item.artists
                 album_item.subitems.append(track_item)
             return album_item
     except Exception as e:
         print("SpotifySearch::get_album:", e)
     return None
コード例 #9
0
 def get_album(self, album_id):
     """
         Return spotify album as SearchItem
         @param album id as str
         @return SearchItem
     """
     try:
         s = Lio.File.new_for_uri("https://api.spotify.com/v1/"
                                  "albums/%s" % album_id)
         (status, data, tag) = s.load_contents(self._cancel)
         if status:
             decode = json.loads(data.decode('utf-8'))
             album_item = SearchItem()
             album_item.name = decode['name']
             album_item.cover = decode['images'][0]['url']
             album_item.smallcover = decode['images'][2]['url']
             album_item.ex_id = album_id
             for item in decode['tracks']['items']:
                 track_item = SearchItem()
                 track_item.is_track = True
                 track_item.name = item['name']
                 track_item.album = album_item.name
                 try:
                     track_item.year = decode[
                                             'release_date'][:4]
                 except:
                     pass  # May be missing
                 track_item.tracknumber = int(
                                           item['track_number'])
                 track_item.discnumber = int(
                                            item['disc_number'])
                 track_item.duration = int(
                                     item['duration_ms']) / 1000
                 for artist in item['artists']:
                     track_item.artists.append(artist['name'])
                 if not album_item.artists:
                     album_item.artists = track_item.artists
                 album_item.subitems.append(track_item)
             return album_item
     except Exception as e:
         print("SpotifySearch::get_album:", e)
     return None