Esempio 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
Esempio n. 2
0
File: mXIA.py Progetto: 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')
Esempio n. 3
0
def qdl_album(weblink,q=1,dlfolder=dldir): 
    '''QQ Music Album download'''
    ml = mylogger(logfile,get_funcname()) 
    aDict = ana_album(weblink)
    m_artist = aDict['artist']
    m_year = aDict['year']
    m_album = aDict['album']
    albumdir = f'{m_artist} - {m_year} - {m_album}'
    albumfulldir = create_folder(dlfolder,albumdir)
    cover = albumdir+'.jpg'
    m_cover = albumdir+'.png'
    if os.path.isfile(cover):
        ml.warn('---- Cover download already !') 
    else:
        myget.dl(aDict['cover'],out=cover)
        shutil.copyfile(cover,m_cover)
    
    tracknum = aDict['TrackNum']
    for s in range(1,tracknum+1):
        m_song = aDict[s][1]
        m_singer = aDict[s][2]
        mp3 = m_singer+' - '+m_song +quality[q][1]
        m_trackid = str(s) 
        ml.info(f'{str(s)}.{aDict[s][1]}') 
        if os.path.isfile(mp3):
            ml.warn('---- Track download already !') 
        else:
            songmid = aDict[s][0]
            vkey,guid = get_vkeyguid(songmid,q)
            dlurl = get_dlurl(vkey,guid,songmid,q)
            try:
                myget.dl(dlurl,mp3)
                addtag(mp3,m_song,m_album,m_artist,m_singer,m_cover,m_year,m_trackid)   
            except HTTPError as e:
                if '403' in str(e):
                    ml.err('Track download forbidden')
                else:
                    raise
            except ConnectionResetError as e:
                mywait(10)
                qdl_album(weblink,q=1,dlfolder=dldir)
    if count_f(albumfulldir,'mp3') == int(tracknum) :
        ml.info('Disc Download complete')
        try:
            os.remove(m_cover)
        except FileNotFoundError:
            pass
    else:
        ml.error('Some track download fail')    
    clean_f(albumfulldir,'tmp')
    ml.info('Download Complete:  '+albumdir)
Esempio n. 4
0
File: mXIA.py Progetto: aka-achea/xd
def chromef12(year=None, autoclose=False):
    """
    Chrome F12 find xhr and close page
    ensure filter XHR
    """
    imgpath = os.path.join(PurePath(__file__).parent, 'img')
    if clickbutton(os.path.join(imgpath, 'xm.png')):
        auto.press('f12')
    else:
        raise
    mywait(1)
    auto.press('f5')
    mywait(2)
    if clickbutton(os.path.join(imgpath, 'getalbumdetail.png')):
        auto.click(button='right')
        mywait(1)
    else:
        raise
    if clickbutton(os.path.join(imgpath, 'copy.png')):
        mywait(1)
    else:
        raise
    if clickbutton(os.path.join(imgpath, 'copyresponse.png')):
        album_detail = xm_json(year=year)
    else:
        raise
    if autoclose:
        auto.hotkey('ctrl', 'w')
    return album_detail
Esempio n. 5
0
File: xd.py Progetto: aka-achea/xd
def xd():
    l = mylogger(logfile, get_funcname())
    parser = argparse.ArgumentParser(description='Xiami download tool')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-s', '--song', help='Download single song ')
    group.add_argument('-c', '--cds', help='Download CD', action='store_true')
    group.add_argument('-a', '--artist', help='Download all CD of artist')
    group.add_argument('-f', '--favorite', help='Download favorite list')
    group.add_argument('-t', '--top', help='Download top songs')
    args = parser.parse_args()

    if args.song:
        l.info('Begin download single song')
        link = args.song
        l.debug(link)

    elif args.cds == True:
        l.info('Begin download CDs')
        for w in os.listdir(dldir):
            if os.path.basename(w)[-4:] == 'html':
                l.info(w)
                w = os.path.join(dldir, w)
                web = 'file:///' + w
                # l.info(web)
                dl_cd(web, dldir)
                os.remove(w)
                l.info('Remove ' + w)
                mywait(60)

    elif args.artist:
        l.info('Begin download all CD of artist')
        link = args.artist
        l.info(link)

    elif args.favorite:
        l.info('Begin download all CD of artist')
        link = args.favorite
        l.info(link)

    else:
        parser.print_help()
Esempio n. 6
0
def dl_cd(web, workfolder):
    l = mylogger(logfile, get_funcname())
    # html = op_simple(web)[0]
    aDict = ana_cd(web)
    if aDict == False:
        return False
    else:
        albumdir = create_folder(workfolder, aDict['fullname'])
        albumfulldir = os.path.join(workfolder, albumdir)
        l.debug(albumfulldir)
        os.chdir(albumfulldir)
        # download cover
        m_cover = albumdir + '.png'
        l.debug(m_cover)
        if os.path.isfile(m_cover):
            l.warning('---- Small cover download already !')
        else:
            l.info('Download small cover')
            myget.dl(aDict['scover'], out=m_cover)
            # print('\n')
        cover = albumdir + '.jpg'
        if os.path.isfile(cover):
            l.warning('---- Big Cover download already !')
        else:
            l.info('Download big cover')
            myget.dl(aDict['bcover'], out=cover)
            # print('\n')

        for i in range(aDict['Discs']):
            CD = str(i + 1)
            tracknum = aDict[CD]
            for t in range(tracknum):
                if t in [30, 60, 90]: mywait(180)
                t += 1
                if t < 10:
                    t = '0' + str(t)
                else:
                    t = str(t)
                songid = aDict[CD, t]
                l.debug('Download Disc ' + str(CD) + ' track ' + str(t) +
                        ' id ' + songid)
                SongDic = get_loc_cd(songid)
                if SongDic == {}:
                    l.error('Disc ' + str(CD) + ' track ' + str(t) +
                            ' not published')
                else:
                    songname = SongDic['singer'] + ' - ' + SongDic['song']
                    l.info(str(CD) + '.' + str(t) + '.' + songname)
                    mp3 = songname + '.mp3'
                    l.debug(mp3)
                    if os.path.isfile(mp3):
                        l.warning('---- Track download already !')
                    else:
                        try:
                            myget.dl(SongDic['location'], out=mp3)
                            # print('\n')
                        except Exception as e:
                            l.error(e)
                            l.error("Content incomplete -> retry")
                            myget.dl(SongDic['location'], out=mp3)
                            # print('\n')
                    fname = os.path.join(albumfulldir, mp3)
                    # fname = albumfulldir+'\\'+mp3
                    m_song = SongDic['song']
                    m_singer = SongDic['singer']
                    m_album = aDict['album']
                    m_artist = aDict['artist']
                    m_year = aDict['year']
                    m_cd = str(CD)
                    m_trackid = str(t)
                    addtag(fname,m_song,m_album,m_artist,m_singer,m_cover,\
                            m_year,m_trackid,m_cd)
            c = count_f(albumfulldir)
            if c == int(tracknum):
                l.info('Disc ' + CD + ' Download complete')
                try:
                    os.remove(m_cover)
                except FileNotFoundError:
                    pass
            else:
                l.error('Some track download fail')

        clean_f(albumfulldir)
        with open(albumlist, 'r') as f:
            f.write(aDict['fullname'] + '\n')
        l.info('Download Complete:  ' + albumdir)
    return True
Esempio n. 7
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