示例#1
0
            album_dir = artist_dir + '/' + name[0:254]
        else:
            album_dir = artist_dir + '/' + name

        if not os.path.exists(album_dir):
           os.makedirs(album_dir)
        else:
           DEBUG.p('this album info exist!!!!')

def new_file(path):
    f = open(path, "w")
    f.close()

def func_test(b, a = 1):
    print a

def getDoc2(id):
    return dao.getById2(id)

def getDoc(artist, albumName):
    return dao.getById(artist, albumName)

if __name__ == '__main__':
    #make_dir()
    #new_file("xxoo")
    #result = getDoc('Fabulous Trobadors', 'Duels de tchatche')
    result = getDoc2('f639b7da9b1b1f5d4a463834a3da3b82')
    DEBUG.pd(result)


示例#2
0
    def __saveAllInfos(self, jsonResultAlbum, country):
        #prepare dir
        dir_len = len(jsonResultAlbum['artistName'])
        if dir_len > 255:
            artist_dir = os.getcwd(
            ) + '/static/images/' + jsonResultAlbum['artistName'][0:200]
        else:
            artist_dir = os.getcwd(
            ) + '/static/images/' + jsonResultAlbum['artistName']
        dir_len = len(jsonResultAlbum['collectionName'])
        if dir_len > 255:
            album_dir = artist_dir + '/' + jsonResultAlbum['collectionName'][
                0:200]
        else:
            album_dir = artist_dir + '/' + jsonResultAlbum['collectionName']

        if not os.path.exists(artist_dir):
            os.makedirs(artist_dir)
        if not os.path.exists(album_dir):
            os.makedirs(album_dir)
        else:
            DEBUG.p('this album dir exist:%s' % (album_dir))
            result = dao.getById(jsonResultAlbum['artistName'],
                                 jsonResultAlbum['collectionName'])
            DEBUG.pd(result)
            if result != None:
                DEBUG.p('this album info exist in db!!!!')
                return result
            else:
                DEBUG.pw('this album info not exist in db!!!!')

        #result = dao.getById(jsonResultAlbum['artistName'], jsonResultAlbum['collectionName'])
        #coverImage_1200 = jsonResultAlbum['artworkUrl100'].replace('100x100', '1200x1200').split('/')[-1]
        #if result != None and os.path.exists(album_dir + '/' + coverImage_1200):
        #   DEBUG.p('this album info exist in db!!!!')
        #   DEBUG.p('album:%s; artist:%s'%( jsonResultAlbum['collectionName'], jsonResultAlbum['artistName']))
        #   return result

        #save album info json file
        file = open(album_dir + "/album.json", "w")
        json.dump(jsonResultAlbum, file)
        file.close()

        ##save album cover images
        ret = 0
        coverImageUrl = jsonResultAlbum['artworkUrl100']
        ret += self.__saveCoverImage(album_dir, coverImageUrl)
        coverImageUrl_170 = coverImageUrl.replace('100x100', '170x170')
        ret += self.__saveCoverImage(album_dir, coverImageUrl_170)
        coverImageUrl_600 = coverImageUrl.replace('100x100', '600x600')
        ret += self.__saveCoverImage(album_dir, coverImageUrl_600)
        coverImageUrl_1200 = coverImageUrl.replace('100x100', '1200x1200')
        ret += self.__saveCoverImage(album_dir, coverImageUrl_1200)
        if ret == 0:
            return ret

        info = {
            'album_name': '',
            'artist': '',
            'year_record': '12345',
            'music_contain': 'Nothing',
            'path': u'static/images/',
            'cover_name_1200': u'onePiece.png',
            'cover_name_170': u'onePiece.png',
            'cover_name_100': u'onePiece.png',
            'copy_right': u'lewis',
            'track_count': 1,
            'width': 0,
            'height': 0,
            'size': 0,
            'format': 'jpeg',
            'des': 'come on boy!!! day day up!!!',
            'itunes_album_url': '',
            'itunes_artist_url': ''
        }
        #DEBUG.pd(jsonResultAlbum)
        info['path'] = album_dir + '/'
        info['cover_name_1200'] = coverImageUrl_1200.split('/')[-1]
        info['cover_name_170'] = coverImageUrl_170.split('/')[-1]
        info['cover_name_100'] = coverImageUrl.split('/')[-1]
        info['album_name'] = jsonResultAlbum['collectionName']
        info['artist'] = jsonResultAlbum['artistName']
        info['cover_name'] = coverImageUrl_1200.split('/')[-1]
        info['year_record'] = jsonResultAlbum['releaseDate']
        info['track_count'] = jsonResultAlbum['trackCount']
        info['itunes_album_url'] = jsonResultAlbum['collectionViewUrl']
        if jsonResultAlbum.has_key('artistViewUrl'):
            info['itunes_artist_url'] = jsonResultAlbum['artistViewUrl']
        if jsonResultAlbum.has_key('copyright'):
            info['copy_right'] = jsonResultAlbum['copyright']

        musicContains = []
        jsonMusics = []
        jsonResultMusics = self.__getMusicLists(
            jsonResultAlbum['collectionName'], country)
        if len(jsonResultMusics) == jsonResultAlbum['trackCount']:
            for jsonResultMusic in jsonResultMusics:
                musicContains.append(jsonResultMusic['trackName'])
            jsonMusics = jsonResultMusics
        else:
            for jsonResultMusic in jsonResultMusics:
                if jsonResultMusic['artistName'] == jsonResultAlbum[
                        'artistName']:
                    musicContains.append(jsonResultMusic['trackName'])
                    jsonMusics.append(jsonResultMusic)
        try:
            if len(jsonMusics) == 0:
                for jsonResultMusic in jsonResultMusics:
                    if jsonResultMusic['collectionId'] == jsonResultAlbum[
                            'collectionId']:
                        musicContains.append(jsonResultMusic['trackName'])
                        jsonMusics.append(jsonResultMusic)
        except:
            DEBUG.p("empty music list!!!")

        #save music list json file
        file = open(album_dir + "/album_musics.json", "w")
        json.dump(jsonMusics, file)
        file.close()

        info['music_contain'] = list(set(musicContains))
        DEBUG.pd(info)

        try:
            #record info into db
            dao.addOneDoc(info)
        except:
            print 'add doc failed: %s:%s' % (info['artist'],
                                             info['album_name'])
            print traceback.print_exc()

        return info
    def __saveAllInfos(self, jsonResultAlbum, country):
        #prepare dir
        dir_len = len(jsonResultAlbum['artistName'])
        if dir_len > 255:
            artist_dir = os.getcwd() + '/static/images/' + jsonResultAlbum['artistName'][0:200]
        else:
            artist_dir = os.getcwd() + '/static/images/' + jsonResultAlbum['artistName']
        dir_len = len(jsonResultAlbum['collectionName'])
        if dir_len > 255:
            album_dir = artist_dir + '/' + jsonResultAlbum['collectionName'][0:200]
        else:
            album_dir = artist_dir + '/' + jsonResultAlbum['collectionName']

        if not os.path.exists(artist_dir):
           os.makedirs(artist_dir)
        if not os.path.exists(album_dir):
           os.makedirs(album_dir)
        else:
           DEBUG.p('this album dir exist:%s'%(album_dir))
           result = dao.getById(jsonResultAlbum['artistName'], jsonResultAlbum['collectionName']) 
           DEBUG.pd(result)
           if result != None:
              DEBUG.p('this album info exist in db!!!!')
              return result 
           else:
              DEBUG.pw('this album info not exist in db!!!!')

        #result = dao.getById(jsonResultAlbum['artistName'], jsonResultAlbum['collectionName']) 
        #coverImage_1200 = jsonResultAlbum['artworkUrl100'].replace('100x100', '1200x1200').split('/')[-1]
        #if result != None and os.path.exists(album_dir + '/' + coverImage_1200):
        #   DEBUG.p('this album info exist in db!!!!')
        #   DEBUG.p('album:%s; artist:%s'%( jsonResultAlbum['collectionName'], jsonResultAlbum['artistName']))
        #   return result

        #save album info json file
        file = open(album_dir + "/album.json","w")
        json.dump(jsonResultAlbum, file)
        file.close()

        
        ##save album cover images
        ret = 0 
        coverImageUrl = jsonResultAlbum['artworkUrl100']
        ret += self.__saveCoverImage(album_dir, coverImageUrl)
        coverImageUrl_170 = coverImageUrl.replace('100x100', '170x170')
        ret += self.__saveCoverImage(album_dir, coverImageUrl_170)
        coverImageUrl_600 = coverImageUrl.replace('100x100', '600x600')
        ret += self.__saveCoverImage(album_dir, coverImageUrl_600)
        coverImageUrl_1200 = coverImageUrl.replace('100x100', '1200x1200')
        ret += self.__saveCoverImage(album_dir, coverImageUrl_1200)
        if ret == 0:
           return ret 

        info = {
                'album_name': '',
                'artist': '',
                'year_record': '12345',
                'music_contain': 'Nothing',
                'path': u'static/images/',
                'cover_name_1200': u'onePiece.png',
                'cover_name_170': u'onePiece.png',
                'cover_name_100': u'onePiece.png',
                'copy_right': u'lewis',
                'track_count': 1,
                'width': 0,
                'height': 0,
                'size': 0,
                'format': 'jpeg',
                'des':'come on boy!!! day day up!!!',
                'itunes_album_url': '',
                'itunes_artist_url': ''
        }
        #DEBUG.pd(jsonResultAlbum)
        info['path'] = album_dir + '/'
        info['cover_name_1200'] = coverImageUrl_1200.split('/')[-1] 
        info['cover_name_170'] = coverImageUrl_170.split('/')[-1] 
        info['cover_name_100'] = coverImageUrl.split('/')[-1] 
        info['album_name'] = jsonResultAlbum['collectionName'] 
        info['artist'] = jsonResultAlbum['artistName'] 
        info['cover_name'] = coverImageUrl_1200.split('/')[-1] 
        info['year_record'] = jsonResultAlbum['releaseDate']
        info['track_count'] = jsonResultAlbum['trackCount']
        info['itunes_album_url'] = jsonResultAlbum['collectionViewUrl']
        if jsonResultAlbum.has_key('artistViewUrl'): 
           info['itunes_artist_url'] = jsonResultAlbum['artistViewUrl']
        if jsonResultAlbum.has_key('copyright'): 
           info['copy_right'] = jsonResultAlbum['copyright']

        musicContains = []
        jsonMusics = []
        jsonResultMusics = self.__getMusicLists(jsonResultAlbum['collectionName'], country)
        if len(jsonResultMusics) == jsonResultAlbum['trackCount']: 
           for jsonResultMusic in jsonResultMusics:
               musicContains.append(jsonResultMusic['trackName'])
           jsonMusics = jsonResultMusics
        else:
           for jsonResultMusic in jsonResultMusics:
               if jsonResultMusic['artistName'] == jsonResultAlbum['artistName']:
                  musicContains.append(jsonResultMusic['trackName'])
                  jsonMusics.append(jsonResultMusic)
        try:
            if len(jsonMusics) == 0:
               for jsonResultMusic in jsonResultMusics:
                   if jsonResultMusic['collectionId'] == jsonResultAlbum['collectionId']:
                      musicContains.append(jsonResultMusic['trackName'])
                      jsonMusics.append(jsonResultMusic)
        except:
            DEBUG.p("empty music list!!!")

        #save music list json file
        file = open(album_dir + "/album_musics.json","w")
        json.dump(jsonMusics, file)
        file.close()

        info['music_contain'] = list(set(musicContains)) 
        DEBUG.pd(info)

        try:
            #record info into db
            dao.addOneDoc(info)
        except:
            print 'add doc failed: %s:%s'%(info['artist'], info['album_name'])
            print traceback.print_exc()
            

        return info
示例#4
0
    if not os.path.exists(album_dir):
        os.makedirs(album_dir)
    else:
        DEBUG.p('this album info exist!!!!')


def new_file(path):
    f = open(path, "w")
    f.close()


def func_test(b, a=1):
    print a


def getDoc2(id):
    return dao.getById2(id)


def getDoc(artist, albumName):
    return dao.getById(artist, albumName)


if __name__ == '__main__':
    #make_dir()
    #new_file("xxoo")
    #result = getDoc('Fabulous Trobadors', 'Duels de tchatche')
    result = getDoc2('f639b7da9b1b1f5d4a463834a3da3b82')
    DEBUG.pd(result)