Ejemplo n.º 1
0
    def getPages(self):
        pageData = self.bsdata.find("ul", {"class": "pagination-list"})
        if pageData is None:
            err = "pagination-list"
            apc = artistDBPageClass(err=err)
            return apc

        lis = pageData.findAll("li", {"class": "pagination-page"})
        ppp = 20

        if len(lis) > 1:
            lastPage = self.getNamesAndURLs(lis[-1])
            try:
                tot = lastPage[0].name
            except:
                tot = None
                #raise ValueError("Error getting last page from {0}".format(lastPage))

            try:
                tot = int(tot)
                apc = artistDBPageClass(ppp=ppp,
                                        tot=tot,
                                        redo=False,
                                        more=True)
            except:
                tot = 1
                apc = artistDBPageClass(ppp=ppp,
                                        tot=tot,
                                        redo=False,
                                        more=False)

        else:
            tot = 1

        return apc
Ejemplo n.º 2
0
    def getPages(self):
        apc = artistDBPageClass()
        from numpy import ceil
        bsdata = self.bsdata

        try:
            pages = bsdata.find("ul", {"class": "pagination"})
            lis = pages.findAll("li")
            txts = [li.text for li in lis]
            npages = 0
            for item in txts:
                try:
                    npages = max([npages, int(item)])
                except:
                    continue

            apc = artistDBPageClass(ppp=100,
                                    tot=100 * npages,
                                    redo=False,
                                    more=True)
        except:
            apc = artistDBPageClass(ppp=100, tot=1, redo=False, more=False)

        return apc
Ejemplo n.º 3
0
    def getPages(self):
        from numpy import ceil
        bsdata = self.bsdata


        pageData = bsdata.find("div", {"class": "pagination bottom"})
        if pageData is None:
            err = "pagination bottom"
            apc = artistDBPageClass(err=err)
            return apc
        else:
            x = pageData.find("strong", {"class": "pagination_total"})
            if x is None:
                err = "pagination_total"
                apc = artistDBPageClass(err=err)
                return apc
            else:
                txt = x.text
                txt = txt.strip()
                txt = txt.replace("\n", "")
                retval = [tmp.strip() for tmp in txt.split('of')]

                try:
                    ppp   = int(retval[0].split('–')[-1])
                    tot   = int(retval[1].replace(",", ""))
                except:
                    err   = "int"
                    apc   = artistDBPageClass(err=err)
                    return apc

                if ppp < 500:
                    if tot < 25 or ppp == tot:
                        apc   = artistDBPageClass(ppp=ppp, tot=tot, redo=False, more=False)
                    else:
                        apc   = artistDBPageClass(ppp=ppp, tot=tot, redo=True, more=False)
                else:
                    if tot < 500:
                        apc   = artistDBPageClass(ppp=ppp, tot=tot, redo=False, more=False)
                    else:
                        apc   = artistDBPageClass(ppp=ppp, tot=tot, redo=False, more=True)
                        
                return apc
            
        return artistDBPageClass()
Ejemplo n.º 4
0
    def getData(self, inputdata):
        self.getDataBase(inputdata)
        self.checkData()

        if self.dbdata is not None:
            return self.dbdata
        if not isinstance(self.bsdata, dict):
            raise ValueError("Could not parse LastFM API data")

        tracks = self.bsdata["Tracks"]
        albums = self.bsdata["Albums"]
        if len(tracks) > 0:
            artistData = {
                "Name": tracks[0]["artistName"],
                "URL": tracks[0]["artistURL"],
                "MBID": tracks[0]["artistMBID"]
            }
        elif len(albums) > 0:
            artistData = {
                "Name": albums[0]["artistName"],
                "URL": albums[0]["artistURL"],
                "MBID": albums[0]["artistMBID"]
            }
        else:
            return None
            raise ValueError("No track/album data!")

        artistName = artistData["Name"]
        artistURL = artistData["URL"]
        artistID = self.dbUtils.getArtistID(artistURL)
        generalData = None
        externalData = {"MusicBrainzID": artistData["MBID"]}
        #mbID       = mbutil.getArtistID(artistData['MBID']

        trackData = [{
            "Name": track["name"],
            "URL": track["URL"],
            "Counts": int(track["counts"])
        } for track in tracks if int(track["counts"]) > 50]
        counts = sorted([x["Counts"] for x in trackData], reverse=True)
        idx = min([len(counts) - 1, 1000 - 1])
        trackData = [v for v in trackData if v['Counts'] >= counts[idx]]

        albumData = [{
            "Name": album["name"],
            "URL": album["URL"],
            "Counts": int(album["counts"])
        } for album in albums if int(album["counts"]) > 25]
        counts = sorted([x["Counts"] for x in albumData], reverse=True)
        idx = min([len(counts) - 1, 1000 - 1])
        albumData = [v for v in albumData if v['Counts'] >= counts[idx]]

        mediaData = {}
        if len(trackData) > 0:
            mediaName = "Tracks"
            mediaData[mediaName] = []
            for artistTrack in trackData:
                m = md5()
                m.update(artistTrack['Name'].encode('utf-8'))
                m.update(artistTrack['URL'].encode('utf-8'))
                hashval = m.hexdigest()
                code = str(int(hashval, 16) % int(1e7))

                album = artistTrack["Name"]
                albumURL = artistTrack["URL"]
                albumArtists = [artistData["Name"]]

                amdc = artistDBMediaDataClass(album=album,
                                              url=albumURL,
                                              artist=albumArtists,
                                              code=code,
                                              year=None)
                mediaData[mediaName].append(amdc)

        if len(albumData) > 0:
            mediaName = "Albums"
            mediaData[mediaName] = []
            for artistAlbum in albumData:
                m = md5()
                m.update(artistAlbum['Name'].encode('utf-8'))
                m.update(artistAlbum['URL'].encode('utf-8'))
                hashval = m.hexdigest()
                code = str(int(hashval, 16) % int(1e7))

                album = artistAlbum["Name"]
                albumURL = artistAlbum["URL"]
                albumArtists = [artistName]

                amdc = artistDBMediaDataClass(album=album,
                                              url=albumURL,
                                              artist=albumArtists,
                                              code=code,
                                              year=None)
                mediaData[mediaName].append(amdc)

        artist = artistDBNameClass(name=artistName, err=None)
        meta = artistDBMetaClass(title=None, url=artistURL)
        url = artistDBURLClass(url=artistURL)
        ID = artistDBIDClass(ID=artistID)
        pages = artistDBPageClass(ppp=1, tot=1, redo=False, more=False)
        profile = artistDBProfileClass(general=generalData,
                                       external=externalData)
        media = artistDBMediaClass()
        media.media = mediaData
        mediaCounts = self.getMediaCounts(media)
        info = self.getInfo()

        adc = artistDBDataClass(artist=artist,
                                meta=meta,
                                url=url,
                                ID=ID,
                                pages=pages,
                                profile=profile,
                                mediaCounts=mediaCounts,
                                media=media,
                                info=info)

        return adc
Ejemplo n.º 5
0
 def getPages(self):
     apc = artistDBPageClass(ppp=1, tot=1, redo=False, more=False)
     return apc
Ejemplo n.º 6
0
    def getData(self, inputdata):
        self.getDataBase(inputdata)
        self.checkData()

        if self.dbdata is not None:
            return self.dbdata
        if not isinstance(self.bsdata, dict):
            raise ValueError("Could not parse Spotify API data")

        artistData = self.bsdata['Artist']
        artistID = artistData.name
        artistURI = artistData.get('uri')
        artistType = artistData.get('stype')
        artistPopularity = artistData.get('popularity')
        artistName = artistData.get('name')
        artistAPIURL = artistData.get('href')
        artistGenres = artistData.get('genres', [])
        artistFollowers = artistData.get('followers')
        artistURL = artistData.get('urls', {}).get('spotify')

        generalData = {"Type": artistType}
        genresData = artistGenres if len(artistGenres) > 0 else None
        externalData = {'SpotifyAPI': {"URL": artistAPIURL, "URI": artistURI}}
        extraData = {
            'Followers': artistFollowers,
            "Popularity": artistPopularity
        }

        mediaData = {}
        albumsData = self.bsdata['Albums']
        if len(albumsData) > 0:
            albumsURL = albumsData.get('href')
            if albumsData.get('artistID') != artistID:
                raise ValueError(
                    "ArtistIDs do not match for Spotify API Data! [{0}, {1}]".
                    format(albumsData.get('artistID'), artistID))

            mediaData = {}
            for albumData in albumsData.get('albums', []):
                albumID = albumData.get('sid')
                albumGroup = albumData.get('album_group')
                albumType = albumData.get('album_type')
                albumSType = albumData.get('stype')
                albumArtists = [{
                    artist['sid']: artist['name']
                } for artist in albumData.get('artists', [])]
                albumURL = albumData.get('urls', {}).get('spotify')
                albumURI = albumData.get('uri')
                albumAPI = albumData.get('href')
                albumName = albumData.get('name')
                albumTracks = albumData.get('numtracks')
                albumDate = albumData.get('date')
                try:
                    albumYear = to_datetime(
                        albumDate).year if albumDate is not None else None
                except:
                    albumYear = None

                if all([albumGroup, albumType]):
                    mediaName = " + ".join([albumGroup, albumType])
                elif albumGroup is not None:
                    mediaName = albumGroup
                elif albumType is not None:
                    mediaName = albumType
                else:
                    mediaName = "Unknown"

                amdc = artistDBMediaDataClass(album=albumName,
                                              url=albumURL,
                                              artist=albumArtists,
                                              code=albumID,
                                              year=albumYear,
                                              aclass=albumSType,
                                              aformat={
                                                  "URI": albumURI,
                                                  "API": albumAPI,
                                                  "Date": albumDate,
                                                  "NumTracks": albumTracks
                                              })
                if mediaData.get(mediaName) is None:
                    mediaData[mediaName] = []
                mediaData[mediaName].append(amdc)

        artist = artistDBNameClass(name=artistName, err=None)
        meta = artistDBMetaClass(title=None, url=artistURL)
        url = artistDBURLClass(url=artistURL)
        ID = artistDBIDClass(ID=artistID)
        pages = artistDBPageClass(ppp=1, tot=1, redo=False, more=False)
        profile = artistDBProfileClass(general=generalData,
                                       external=externalData,
                                       extra=extraData,
                                       genres=genresData)
        media = artistDBMediaClass()
        media.media = mediaData
        mediaCounts = self.getMediaCounts(media)
        info = self.getInfo()

        adc = artistDBDataClass(artist=artist,
                                meta=meta,
                                url=url,
                                ID=ID,
                                pages=pages,
                                profile=profile,
                                mediaCounts=mediaCounts,
                                media=media,
                                info=info)

        return adc
Ejemplo n.º 7
0
    def getData(self, inputdata):
        self.getDataBase(inputdata)
        self.checkData()

        if self.dbdata is not None:
            return self.dbdata
        if not isinstance(self.bsdata, dict):
            raise ValueError("Could not parse Deezer API data")

        artist = self.bsdata

        artistTracks = artist["Tracks"]
        artistAlbums = artist["Albums"]
        artistName = artist["Name"]
        artistID = artist["ID"]
        artistURL = artist["URL"]
        generalData = {"Type": artist["Type"]}

        mediaData = {}
        mediaName = "Tracks"
        mediaData[mediaName] = []
        for code, artistTrack in artistTracks.items():
            album = artistTrack["Name"]
            albumURL = artistTrack["URL"]
            albumArtists = [artistName]

            amdc = artistDBMediaDataClass(album=album,
                                          url=albumURL,
                                          artist=albumArtists,
                                          code=code,
                                          year=None)
            mediaData[mediaName].append(amdc)

        mediaData = {}
        mediaName = "Albums"
        mediaData[mediaName] = []
        for code, artistAlbum in artistAlbums.items():
            album = artistAlbum["Name"]
            albumURL = artistAlbum["URL"]
            albumArtists = [artistName]

            amdc = artistDBMediaDataClass(album=album,
                                          url=albumURL,
                                          artist=albumArtists,
                                          code=code,
                                          year=None)
            mediaData[mediaName].append(amdc)

        artist = artistDBNameClass(name=artistName, err=None)
        meta = artistDBMetaClass(title=None, url=artistURL)
        url = artistDBURLClass(url=artistURL)
        ID = artistDBIDClass(ID=artistID)
        pages = artistDBPageClass(ppp=1, tot=1, redo=False, more=False)
        profile = artistDBProfileClass(general=generalData)
        media = artistDBMediaClass()
        media.media = mediaData
        mediaCounts = self.getMediaCounts(media)
        info = self.getInfo()

        adc = artistDBDataClass(artist=artist,
                                meta=meta,
                                url=url,
                                ID=ID,
                                pages=pages,
                                profile=profile,
                                mediaCounts=mediaCounts,
                                media=media,
                                info=info)

        return adc
Ejemplo n.º 8
0
    def getData(self, inputdata):
        self.getDataBase(inputdata)
        self.checkData()
        
        if self.dbdata is not None:
            return self.dbdata
        if not isinstance(self.bsdata, dict):
            raise ValueError("Could not parse Discogs API data")
            
        artistData = self.bsdata["Artist"]
        albumsData = self.bsdata["Albums"]
        
        artistID   = artistData.name
        artistName  = artistData["name"]
        url         = "https://www.discogs.com/artist/{0}".format(artistID)

        generalData = {}
        generalData["RealName"]   = artistData["realname"]
        generalData["Aliases"]    = artistData["MasterAliases"]
        generalData["Groups"]     = artistData["MasterGroups"]
        generalData["Members"]    = artistData["MasterMembers"]
        generalData["Variations"] = artistData["MasterNameVariations"]
        generalData = {k: v for k,v in generalData.items() if v is not None}
        generalData = generalData if len(generalData) > 0 else None
            

        ########################################################################
        # Get Releases
        ########################################################################
        mediaData = {}
        if isinstance(albumsData,list):
            for item in albumsData:
                code        = item.get('id')
                albumType   = item.get('type')
                albumFormat = item.get('format')
                albumLabel  = item.get('label')
                albumName   = item.get('name')
                albumURL    = item.get('url')
                albumRole   = item.get('role')
                albumArtist = item.get('artist')
                albumYear   = item.get('year')
                albumMain   = item.get('main_release')

                mediaName = self.getMediaType(item)

                amdc = artistDBMediaDataClass(album=albumName, url=albumURL, artist=albumArtist, code=code, aformat=albumFormat, aclass={"Label": albumLabel, "Main": albumMain}, year=albumYear)
                if mediaData.get(mediaName) is None:
                    mediaData[mediaName] = []
                mediaData[mediaName].append(amdc)
        elif isinstance(albumsData,dict):
            mediaData = albumsData
        else:
            raise ValueError("Not sure how to process albums [{0}]".format(albumsData))
            
            
        artist      = artistDBNameClass(name=artistName, err=None)
        meta        = artistDBMetaClass(title=None, url=url)
        url         = artistDBURLClass(url=url)
        ID          = artistDBIDClass(ID=artistID)
        pages       = artistDBPageClass(ppp=1, tot=1, redo=False, more=False)
        profile     = artistDBProfileClass(general=generalData)
        media       = artistDBMediaClass()
        media.media = mediaData
        mediaCounts = self.getMediaCounts(media)
        info        = artistDBFileInfoClass(info=None)
        
        adc = artistDBDataClass(artist=artist, meta=meta, url=url, ID=ID, pages=pages, profile=profile, mediaCounts=mediaCounts, media=media, info=info)
        
        return adc