Пример #1
0
 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)
Пример #2
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)
Пример #3
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)
Пример #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://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)
Пример #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 = 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)
Пример #6
0
    def __get_album(self, itunes_id):
        """
            Get itunes album items
            @param id as int
            @return SearchItem/None
        """
        if not Gio.NetworkMonitor.get_default().get_network_available():
                return
        language = getdefaultlocale()[0][0:2]
        try:
            debug("ItunesCharts::__get_album(): %s" % itunes_id)
            url = self.__INFO % (itunes_id, language)
            f = Gio.File.new_for_uri(url)
            (status, data, tag) = f.load_contents(self.__cancel)
            if not status or self.__stop:
                return
            decode = json.loads(data.decode('utf-8'))
            item = decode['results'][0]
            album_item = SearchItem()
            album_item.name = item['collectionName']
            album_item.album_name = album_item.name
            album_item.artists.append(item['artistName'])
            album_item.cover = item['artworkUrl60'].replace(
                                               '60x60',
                                               '512x512')

            for item in decode['results'][1:]:
                track_item = SearchItem()
                track_item.is_track = True
                track_item.name = item['trackName']
                track_item.album = album_item.name
                track_item.year = item['releaseDate'][:4]
                track_item.tracknumber = int(
                                          item['trackNumber'])
                track_item.discnumber = int(
                                           item['discNumber'])
                track_item.duration = int(
                                    item['trackTimeMillis']) / 1000
                if album_item.artists[0] != item['artistName']:
                    track_item.artists.append(album_item.artists[0])
                track_item.artists.append(item['artistName'])
                album_item.subitems.append(track_item)
            return album_item
        except Exception as e:
            print("ItunesCharts::__get_album()", e)
        return None
Пример #7
0
    def __get_album(self, itunes_id):
        """
            Get itunes album items
            @param id as int
            @return SearchItem/None
        """
        if not get_network_available():
                return
        language = getdefaultlocale()[0][0:2]
        try:
            debug("ItunesCharts::__get_album(): %s" % itunes_id)
            url = self.__INFO % (itunes_id, language)
            f = Gio.File.new_for_uri(url)
            (status, data, tag) = f.load_contents(self.__cancel)
            if not status or self.__stop:
                return
            decode = json.loads(data.decode('utf-8'))
            item = decode['results'][0]
            album_item = SearchItem()
            album_item.name = item['collectionName']
            album_item.album_name = album_item.name
            album_item.artists.append(item['artistName'])
            album_item.cover = item['artworkUrl60'].replace(
                                               '60x60',
                                               '512x512')

            for item in decode['results'][1:]:
                track_item = SearchItem()
                track_item.is_track = True
                track_item.name = item['trackName']
                track_item.album = album_item.name
                track_item.year = item['releaseDate'][:4]
                track_item.tracknumber = int(
                                          item['trackNumber'])
                track_item.discnumber = int(
                                           item['discNumber'])
                track_item.duration = int(
                                    item['trackTimeMillis']) / 1000
                if album_item.artists[0] != item['artistName']:
                    track_item.artists.append(album_item.artists[0])
                track_item.artists.append(item['artistName'])
                album_item.subitems.append(track_item)
            return album_item
        except Exception as e:
            print("ItunesCharts::__get_album()", e)
        return None
Пример #8
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
Пример #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
Пример #10
0
    def __get_album(self, itunes_id):
        """
            Get itunes album items
            @param id as int
            @return SearchItem/None
        """
        if not get_network_available():
            return
        country = getdefaultlocale()[0][3:]
        try:
            debug("ItunesCharts::__get_album(): %s" % itunes_id)
            url = self.__INFO % (itunes_id, country)
            f = Lio.File.new_for_uri(url)
            (status, data, tag) = f.load_contents(self.__cancel)
            if not status or self.__stop:
                return
            decode = json.loads(data.decode("utf-8"))
            item = decode["results"][0]
            album_item = SearchItem()
            album_item.name = item["collectionName"]
            album_item.artists.append(item["artistName"])
            album_item.cover = item["artworkUrl60"].replace("60x60", "512x512")

            for item in decode["results"][1:]:
                track_item = SearchItem()
                track_item.is_track = True
                track_item.name = item["trackName"]
                track_item.album = album_item
                track_item.year = item["releaseDate"][:4]
                track_item.tracknumber = int(item["trackNumber"])
                track_item.discnumber = int(item["discNumber"])
                track_item.duration = int(item["trackTimeMillis"]) / 1000
                if album_item.artists[0] != item["artistName"]:
                    track_item.artists.append(album_item.artists[0])
                track_item.artists.append(item["artistName"])
                album_item.subitems.append(track_item)
            return album_item
        except Exception as e:
            print("ItunesCharts::__get_album()", e)
        return None
Пример #11
0
    def do(self, search_items):
        """
            Return tracks containing name
            @param search items as [str]
            @return tracks as [SearchItem]
        """
        self.__stop = False
        # Local search
        added_album_ids = []
        added_track_ids = []
        for item in search_items:
            if self.__stop:
                return
            albums = []
            tracks_non_album_artist = []
            # Get all albums for all artists and non album_artist tracks
            for artist_id in Lp().artists.search(item):
                if self.__stop:
                    return
                for album_id in Lp().albums.get_ids([artist_id], []):
                    if (album_id, artist_id) not in albums:
                        albums.append((album_id, artist_id))
                for track_id, track_name in Lp(
                ).tracks.get_as_non_album_artist(artist_id):
                    tracks_non_album_artist.append((track_id, track_name))

            for album_id, artist_id in albums:
                if self.__stop:
                    return
                if album_id in added_album_ids:
                    continue
                search_item = SearchItem()
                search_item.id = album_id
                added_album_ids.append(album_id)
                search_item.is_track = False
                search_item.artist_ids = [artist_id]
                search_item.year = Lp().albums.get_year(album_id)
                self._items.append(search_item)
                GLib.idle_add(self.emit, 'item-found')

            try:
                year = int(item)
                albums = Lp().albums.get_by_year(year)
            except:
                albums = []
            albums += Lp().albums.search(item)
            for album_id in albums:
                if self.__stop:
                    return
                if album_id in added_album_ids:
                    continue
                search_item = SearchItem()
                search_item.id = album_id
                added_album_ids.append(album_id)
                search_item.is_track = False
                search_item.artist_ids = Lp().albums.get_artist_ids(album_id)
                search_item.year = Lp().albums.get_year(album_id)
                self._items.append(search_item)
                GLib.idle_add(self.emit, 'item-found')

            for track_id, track_name in Lp().tracks.search(
                    item) + tracks_non_album_artist:
                if self.__stop:
                    return
                if track_id in added_track_ids:
                    continue
                search_item = SearchItem()
                search_item.id = track_id
                added_track_ids.append(track_id)
                search_item.is_track = True
                search_item.artist_ids = Lp().tracks.get_artist_ids(track_id)
                self._items.append(search_item)
                GLib.idle_add(self.emit, 'item-found')
        self._finished = True
        GLib.idle_add(self.emit, 'item-found')