def dl_one(weburl, workfolder): l = mylogger(logfile, get_funcname()) songid = str(weburl.split('/')[-1]) songid = songid.split('?')[0] l.debug(songid) os.chdir(workfolder) SongDic = get_loc_one(songid) songname = SongDic['artist'] + ' - ' + SongDic['song'] l.info(songname) mp3 = songname + '.mp3' m_cover = songname + '.png' if os.path.isfile(mp3): l.warning("Track download already") else: myget.dl(SongDic['location'], out=mp3) if os.path.isfile(m_cover): pass else: myget.dl(SongDic['cover'], out=m_cover) fname = mp3 m_song = SongDic['song'] m_album = SongDic['album'] m_artist = SongDic['artist'] m_singer = SongDic['singer'] addtag(fname, m_song, m_album, m_artist, m_singer, m_cover) os.remove(m_cover)
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
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')
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)
def songdl(weblink): '''''' ml = mylogger(logfile,get_funcname()) sDict = ana_song(weblink) mp3 = sDict['artist']+' - '+sDict['songname']+'.mp3' if not os.path.isfile(mp3): try: coverlink = sDict['cover'] m_cover = mp3+'.png' myget.dl(coverlink,out=m_cover) myget.dl(dlurl,out=mp3) except TypeError: ml.err('Not published Track') except Exception as e : ml.err(e) ml.err("Content incomplete -> retry") myget.dl(dlurl,out=mp3) else: songname = sDict['songname'] artist = sDict['artist'] singer = sDict['artist'] addtag(mp3,songname,albumname,artist,singer,m_cover)
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
def qdl_album(weblink, q=1, dlfolder=dldir): 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_album}' albumfulldir = create_folder(dlfolder, albumdir) cover = albumdir + '.jpg' m_cover = albumdir + '.png' if os.path.isfile(cover): ml.warning('---- 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.warning('---- Track download already !') else: songmid = aDict[s][0] vkey, guid = get_vkeyguid(songmid, q) dlurl = get_dlurl(vkey, guid, songmid, q) myget.dl(dlurl, mp3) addtag(mp3, m_song, m_album, m_artist, m_singer, m_cover, m_year, m_trackid) # if SongDic == {}: # l.error('Track '+str(s)+' not published') # else: # songname = SongDic['singer']+' - '+SongDic['song'] # l.info(str(s)+'.'+songname) # mp3 = songname+'.mp3' # l.debug(mp3) # if os.path.isfile(mp3): # l.error('---- Track download already !') # else: # myget.dl(SongDic['location'],out=mp3) # print('\n') # fname = albumfulldir+'\\'+mp3 # m_song = SongDic['song'] # m_singer = SongDic['singer'] # m_album = aDict['album'] # m_artist = aDict['artist'] # m_year = aDict['year'] # m_trackid = str(s) 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)
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