Exemplo n.º 1
0
def dl(albumlink, force=False):
    '''main function to download album'''
    ml = mylogger(logfile, get_funcname())

    adict = ana_cd(albumlink)
    coverlink = adict['cover']
    artist = adict['artist']
    year = adict['year']
    albumname = adict['albumname']

    albumdir = f'{artist} - {year} - {albumname}'
    if find_album(albumdir) and force == False:
        ml.warning(f'Album alread archived')
    else:
        albumfulldir = create_folder(dldir, albumdir)
        cover = os.path.join(albumfulldir, albumdir + '.jpg')
        m_cover = os.path.join(albumfulldir, albumdir + '.png')

        if os.path.isfile(cover):
            ml.warning('---- Big Cover download already !')
        else:
            ml.info('Download big cover')
            myget.dl(coverlink, out=cover)

        if os.path.isfile(m_cover):
            ml.warning('---- Small cover ready !')
        else:
            shutil.copy(cover, m_cover)
            squaresize(m_cover)

        for tracknum in range(1, adict['number'] + 1):
            songid = adict[tracknum]['id']
            singer = modstr(adict[tracknum]['singer'])
            songname = modstr(adict[tracknum]['songname'])
            songfullname = f'{singer} - {songname}.mp3'
            mp3 = os.path.join(albumfulldir, songfullname)
            ml.info(f'{tracknum} {singer} - {songname}')
            if os.path.isfile(mp3):
                ml.warning('---- Track download already !')
            else:
                try:
                    dlurl = get_dlurl(songid)
                    myget.dl(dlurl, out=mp3)
                except TypeError:
                    ml.error('Not published Track')
                    continue
                except Exception as e:
                    ml.error(e)
                    ml.error("Content incomplete -> retry")
                    myget.dl(dlurl, out=mp3)
                else:
                    addtag(mp3, songname, albumname, artist, singer, m_cover,
                           year, tracknum)
            mywait(random.randint(1, 3))
        try:
            os.remove(m_cover)
            clean_f(albumfulldir, 'tmp')
            ml.info(f'Complete download {albumdir}')
        except FileNotFoundError:
            pass
Exemplo n.º 2
0
Arquivo: mXIA.py Projeto: aka-achea/xd
    def download_album(self, workfolder, album_detail):
        ml = mylogger(logfile, get_funcname())

        artist_name = album_detail['artist_name']
        album_name = album_detail['album_name']
        year = album_detail['year']
        albumdir = f'{artist_name} - {year} - {album_name}'

        albumfulldir = create_folder(workfolder, albumdir)
        try:
            coverlink = album_detail['coverlink']
            cover = os.path.join(albumfulldir, albumdir + '.jpg')
            m_cover = os.path.join(albumfulldir, albumdir + '.png')
            if os.path.isfile(cover):
                ml.warn('---- Big Cover download already !')
            else:
                ml.info('Download big cover')
                myget.dl(coverlink, out=cover)
            if os.path.isfile(m_cover):
                ml.warn('---- Small cover ready !')
            else:
                shutil.copy(cover, m_cover)
                squaresize(m_cover)
            songid_list = album_detail['songid_list']
            download_url_dict = self.get_song_download_url(songid_list)
            ml.dbg(download_url_dict)
            for s in songid_list:
                singers = modstr(
                    album_detail['song_detail_list'][s]['singers'])
                songname = modstr(
                    album_detail['song_detail_list'][s]['songname'])
                songfullname = f'{singers} - {songname}.mp3'
                mp3 = os.path.join(albumfulldir, songfullname)
                if os.path.isfile(mp3):
                    ml.warn(f'---- {songname} download already !')
                else:
                    cdserial = str(
                        album_detail['song_detail_list'][s]['cdserial'])
                    track = str(album_detail['song_detail_list'][s]['track'])
                    ml.info(f'{cdserial}.{track} {singers} - {songname}')
                    if dlurl := download_url_dict[s]:
                        try:
                            myget.dl(dlurl, out=mp3)
                            mywait(random.randint(1, 3))
                            addtag(mp3, songname, album_name, artist_name,
                                   singers, m_cover, year, track, cdserial)
                        except AttributeError as e:
                            if "urllib.error" in str(e):
                                pass
                        except Exception as e:
                            print(e)
                            if "HTTP Error 404: Not Found" in str(e):
                                ml.err("File Not Found")
                            else:
                                raise
            os.remove(m_cover)
            clean_f(albumfulldir, 'tmp')
            ml.info('Download Complete')
Exemplo n.º 3
0
def pastepic(arr, canvas, picfolder):
    '''Paste picture on position 1'''
    piclist = os.listdir(picfolder)
    x, y = 0, 0
    count = 0
    for row in range(len(arr)):
        # print(r)
        for col in range(len(arr[0])):
            # print(c)
            x, y = 50 * col, 50 * row
            if len(piclist) == 0:
                piclist = os.listdir(picfolder)
            if arr[row][col] == 1:
                count += 1
                # print(x,y)
                pic = os.path.join(picfolder, piclist[0])
                del piclist[0]
                img = squaresize(pic)
                # img = Image.open(pic)
                # wpercent = (50/float(img.size[0]))
                # hsize = int((float(img.size[1])*float(wpercent)))
                # img = img.resize((50,hsize),Image.LANCZOS)
                canvas.paste(img, (x, y))
    print('Total use {} picture'.format(count))
Exemplo n.º 4
0
def xm_json(workfolder, year=None, force=False):
    '''Analyze json album data'''
    ml = mylogger(logfile, get_funcname())

    j = json.loads(get_text_clipboard())
    print(j)
    # j = f2json(get_text_clipboard())
    j = j['result']['data']['albumDetail']

    if year is None:
        year = input('Publish year>>')
    artist_name = modstr(j['artistName'])
    album_name = modstr(j['albumName'])
    albumdir = f'{artist_name} - {year} - {album_name}'
    if find_album(albumdir) and force == False:
        ml.warn(f'{albumdir} alread archived')
    else:
        albumfulldir = create_folder(workfolder, albumdir)
        try:
            coverlink = j['albumLogo']
            cover = os.path.join(albumfulldir, albumdir + '.jpg')
            m_cover = os.path.join(albumfulldir, albumdir + '.png')
            if os.path.isfile(cover):
                ml.warn('---- Big Cover download already !')
            else:
                ml.info('Download big cover')
                myget.dl(coverlink, out=cover)
            if os.path.isfile(m_cover):
                ml.warn('---- Small cover ready !')
            else:
                shutil.copy(cover, m_cover)
                squaresize(m_cover)
            cdcount = j['cdCount']
            songcount = j['songCount']
            for s in range(songcount):
                singers = modstr(j['songs'][s]['singers'])
                songname = modstr(j['songs'][s]['songName'])
                songfullname = f'{singers} - {songname}.mp3'
                mp3 = os.path.join(albumfulldir, songfullname)
                cdserial = str(j['songs'][s]['cdSerial'])
                track = str(j['songs'][s]['track'])
                if os.path.isfile(mp3):
                    ml.warn(f'---- {songname} download already !')
                else:
                    try:

                        ml.info(f'{cdserial}.{track} {singers} - {songname}')
                        songid = j['songs'][s]['songId']
                        location = get_songlocation(songid)
                        dlurl = decry(location)
                        print(dlurl)
                        # dlurl = 'http:'+decry(location)
                        # myget.dl(dlurl,out=mp3)
                        myget.simpledl(dlurl,
                                       mp3,
                                       verify=False,
                                       headers=headers)
                    except Exception as e:
                        ml.err(e)
                        ml.err("Content incomplete -> retry")
                        # myget.dl(dlurl,out=mp3)
                        mywait(random.randint(1, 3))
                addtag(mp3, songname, album_name, artist_name, singers,
                       m_cover, year, track, cdserial)
            os.remove(m_cover)
            clean_f(albumfulldir, 'tmp')
            ml.info('Download Complete')
        except FileNotFoundError:
            pass