385 lines
24 KiB
Python
385 lines
24 KiB
Python
# -*- coding: utf-8 -*-
|
|
########################################################################################### SOF
|
|
__doc__ = '''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::.
|
|
/mMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNd-
|
|
-MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMN.
|
|
/MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM-
|
|
/MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMmNMMMMMMMMMMMmMMMMMMMMMMMMMMMMMMMMMMMMMMMMM-
|
|
/MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh:NMMMMMMMMMMoyMMMMMMMMMMMMMMMMMMMMMMMMMMMM-
|
|
/MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMm -NMMMMMMMMMs.NMMMMMMMMMMMMMMMMMMMMMMMMMMM-
|
|
/MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMy -hmmmmmNNm- sMMMMMMMMMMMMMMMMMMMMMMMMMMM-
|
|
/MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMmdyo+:. ......... .NMMMymMMMMMMMMMMMMMMMMMMMMM-
|
|
/MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMmy+-.. -hNm-+MMMMMMMMMMMMMMMMMMMMM-
|
|
/MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMms:. ... /MM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MMMMMNmh: .dMM-
|
|
/MMMMMMMMMMMMMMMNy:. +MMMMMMMMMMMMMMMMMMMMMMMMMMNh+::/+sdNMMM-
|
|
/MMMMMMMMMMMMMMMMMNdo- .dMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNMMMMMMMM-
|
|
/MMMMMMMMMMMMMMMMMMMMNd+-. -NMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM-
|
|
-NMMMMMMMMMMMMMMMMMMMMMMNdo:. /NMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMd.
|
|
-ymNNNNNNNNNNNNNNNNNNNNNNNNdo-. +NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNmy.
|
|
............................ .-................................
|
|
...... ......... .............. .......... ...'''
|
|
###############################################################################################
|
|
import os,sys,shutil,eyed3
|
|
from eyed3.id3 import ID3_V1_1, ID3_V2_3, ID3_V2_4
|
|
from eyed3.id3.frames import ImageFrame
|
|
from datetime import datetime
|
|
from glob import glob
|
|
###############################################################################################
|
|
eyed3.log.setLevel("ERROR")
|
|
###############################################################################################
|
|
if __name__=='__main__':
|
|
###########################################################################################
|
|
try:
|
|
song_album=str(sys.argv[1])
|
|
except:
|
|
print('no album specified')
|
|
sys.exit(1)
|
|
###########################################################################################
|
|
try:
|
|
song_genre=str(sys.argv[2])
|
|
except:
|
|
print('no genre specified')
|
|
sys.exit(1)
|
|
###########################################################################################
|
|
try:
|
|
path_to_image=str(sys.argv[3])
|
|
except:
|
|
print("no path to 'cover.jpg' specified")
|
|
sys.exit(1)
|
|
###########################################################################################
|
|
shutil.copy(path_to_image,song_album)
|
|
os.chdir(song_album)
|
|
###########################################################################################
|
|
export_time=datetime.now().strftime('%m%d%Y.%H%M%S')
|
|
export_time[:4]+export_time[6:]
|
|
export_directory=f"dr1p__{song_album}"
|
|
try:
|
|
shutil.rmtree(export_directory)
|
|
except:
|
|
pass
|
|
os.mkdir(export_directory)
|
|
print(f"[ export directory: {export_directory} ]")
|
|
###########################################################################################
|
|
filelist=glob('*.mp3')
|
|
track_count=len(filelist)
|
|
print(f"[ {track_count} songs discovered ]")
|
|
###########################################################################################
|
|
playlist="_playlist.m3u"
|
|
playlist_path2file=f'{export_directory}/{playlist}'
|
|
f=open(playlist_path2file,'w')
|
|
f.write("#EXTM3U\n")
|
|
f.close()
|
|
print(f"[ playlist created: {playlist} ]")
|
|
###########################################################################################
|
|
try:
|
|
for track_index,themp3 in enumerate(filelist):
|
|
###################################################################################
|
|
track_pad=len(str(track_count))
|
|
###################################################################################
|
|
print(f"[ processing song {str(track_index+1).zfill(track_pad)}/{str(track_count).zfill(track_pad)} ]")
|
|
print(f"\tfilename: {themp3}")
|
|
###################################################################################
|
|
shutil.copy(themp3,f'{export_directory}')
|
|
song=eyed3.load(f'{export_directory}/{themp3}')
|
|
###################################################################################
|
|
if not song.tag:
|
|
song.initTag()
|
|
###################################################################################
|
|
song_filename=themp3
|
|
song_extension=song_filename[-3:]
|
|
###################################################################################
|
|
if song_filename.find('PREMIERE - ')>-1:
|
|
song_filename=song_filename.replace('PREMIERE - ','')
|
|
###################################################################################
|
|
if song_filename.find('PREMIERE _ ')>-1:
|
|
song_filename=song_filename.replace('PREMIERE _ ','')
|
|
################################################################################### <<< YOUTUBE <<< YOUTUBE
|
|
if song_filename.startswith('youtube_'):
|
|
###############################################################################
|
|
song_videoid=song_filename[-15:-4]
|
|
song_artist=song_filename[:-16].split(' - ')[0].strip()[len('youtube_'):]
|
|
###############################################################################
|
|
try:
|
|
song_title=song_filename[:-16].split(' - ')[1].strip()
|
|
except:
|
|
song_title=''
|
|
#print(f'\t\tsong_artist: {song_artist}\n\t\tsong_title: {song_title}')
|
|
###############################################################################
|
|
url=f"http://youtu.be/{song_videoid}"
|
|
###############################################################################
|
|
################################################################################### <<< BANDCAMP <<< BANDCAMP
|
|
if song_filename.startswith('bandcamp_'):
|
|
###############################################################################
|
|
song_videoid=song_filename.split('-')[-1][:-4]
|
|
buffer=song_filename.replace("-"+song_filename.split('-')[-1],'')[len('bandcamp_'):].split(' - ')
|
|
###############################################################################
|
|
if len(buffer)==3:
|
|
if buffer[0] == buffer[1]:
|
|
song_artist=buffer[1]
|
|
song_title=buffer[2]
|
|
###############################################################################
|
|
if len(buffer)==2:
|
|
song_artist=buffer[0]
|
|
song_title=buffer[1]
|
|
#print(f'\t\tsong_artist: {song_artist}\n\t\tsong_title: {song_title}')
|
|
###############################################################################
|
|
url=f"https://bandcamp.com/EmbeddedPlayer/v=2/track={song_videoid}"
|
|
###############################################################################
|
|
################################################################################### <<< SOUNDCLOUD <<< SOUNDCLOUD
|
|
if song_filename.startswith('soundcloud_'):
|
|
###############################################################################
|
|
song_videoid=song_filename.split('-')[-1][:-4]
|
|
buffer=song_filename[len('soundcloud_'):-len(song_filename.split('-')[-1])-1]
|
|
unclosed_count=0
|
|
if buffer.find('(')>-1: unclosed_count+=1
|
|
if buffer.find(')')>-1: unclosed_count+=1
|
|
if unclosed_count==1: buffer=buffer.replace('(',' - ').replace(')',' - ')
|
|
if (unclosed_count % 2) == 0:
|
|
buffer=song_filename[:-len(song_videoid)-len(song_extension)-len('.')-len('-')].replace('( ','').replace(' )','').lower().replace('soundcloud_','').split('-')
|
|
buffer
|
|
if len(buffer)==3:
|
|
if buffer[0]==buffer[1]:
|
|
song_artist=buffer[1].strip()
|
|
song_title=buffer[2].strip()
|
|
else:
|
|
song_artist=buffer[0].strip()+buffer[1].strip()
|
|
song_title=buffer[2].strip()
|
|
elif len(buffer)==2:
|
|
song_artist=buffer[0].strip()
|
|
song_title=buffer[1].strip()
|
|
elif len(buffer)>=4:
|
|
song_artist=buffer.split('-')[0].strip()
|
|
song_title=buffer.split('-')[1].strip().replace('_','.')
|
|
song_title+="__"+''.join(buffer.split('-')[2:]).strip().replace(' ','.')
|
|
###############################################################################
|
|
if song_artist.find('free dl') > -1:
|
|
song_artist=song_artist.replace('free dl','')
|
|
if song_title.find('free dl') > -1:
|
|
song_title=song_title.replace('free dl','')
|
|
###############################################################################
|
|
#print(f'\t\tsong_artist: {song_artist}\n\t\tsong_title: {song_title}')
|
|
###############################################################################
|
|
url=f"https://w.soundcloud.com/player/?url=https://api.soundcloud.com/tracks/{song_videoid}"
|
|
###############################################################################
|
|
###################################################################################
|
|
if song_artist.find('[') > -1:
|
|
###############################################################################
|
|
sx=song_artist.find('[')
|
|
sy=song_artist.find(']')+1
|
|
###############################################################################
|
|
if len(song_artist[sx:sy]) > 5:
|
|
song_artist=song_artist.replace(song_artist[sx:sy],'').strip()
|
|
###############################################################################
|
|
###################################################################################
|
|
if song_title.find('[') > -1:
|
|
###############################################################################
|
|
sx=song_title.find('[')
|
|
sy=song_title.find(']')+1
|
|
###############################################################################
|
|
if len(song_title[sx:sy]) > 5:
|
|
song_title=song_title.replace(song_title[sx:sy],'').strip()
|
|
###############################################################################
|
|
###################################################################################
|
|
if song_artist.find('(') > -1:
|
|
###############################################################################
|
|
sx=song_artist.find('(')
|
|
sy=song_artist.find(')')+1
|
|
###############################################################################
|
|
if song_artist[sx:sy].lower().find('official') > -1:
|
|
if song_artist[sx:sy].lower().find('audio') > -1 or song_artist[sx:sy].lower().find('video') > -1:
|
|
song_artist=song_artist.replace(song_artist[sx:sy],'').strip()
|
|
###############################################################################
|
|
if song_artist[sx:sy].lower().find('#') > -1:
|
|
song_artist=song_artist.replace(song_artist[sx:sy],'').strip()
|
|
###############################################################################
|
|
###################################################################################
|
|
if song_title.find('(') > -1:
|
|
###############################################################################
|
|
sx=song_title.find('(')
|
|
sy=song_title.find(')')+1
|
|
###############################################################################
|
|
if song_title[sx:sy].lower().find('official') > -1:
|
|
if song_title[sx:sy].lower().find('audio') > -1 or song_title[sx:sy].lower().find('video') > -1:
|
|
song_title=song_title.replace(song_title[sx:sy],'').strip()
|
|
###############################################################################
|
|
if song_title[sx:sy].lower().find('#') > -1:
|
|
song_title=song_title.replace(song_title[sx:sy],'').strip()
|
|
###############################################################################
|
|
if song_title[sx:sy].lower().find('exclusive') > -1:
|
|
if song_title[sx:sy].lower().find('bonus') > -1 or song_title[sx:sy].lower().find('video') > -1:
|
|
song_title=song_title.replace(song_title[sx:sy],'').strip()
|
|
###############################################################################
|
|
###################################################################################
|
|
song.tag.artist=song_artist
|
|
song.tag.album=song_album
|
|
song.tag.genre=song_genre
|
|
song.tag.track_num=(track_index+1,track_count)
|
|
song.tag.disc_num=(1,1)
|
|
song.tag.title=song_title
|
|
song.tag.comments.set(u".[d]. ircd.chat/6697#tcpdirect\n\n{} playlist".format(song_album))
|
|
song.tag.user_url_frames.set(bytes(url.encode()))
|
|
song.tag.recording_date=datetime.now().strftime('%Y-%m-%d')
|
|
song.tag.original_release_date=datetime.now().strftime('%Y')
|
|
song.tag.popularities.set(email="d@aol.com",rating=5,play_count=0)
|
|
song.tag.images.set(ImageFrame.FRONT_COVER, open(path_to_image,'rb').read(), 'image/jpeg')
|
|
###################################################################################
|
|
song.tag.save(version=ID3_V2_4)
|
|
song.tag.save(version=ID3_V2_3)
|
|
song.tag.save(version=ID3_V1_1)
|
|
###################################################################################
|
|
filerenamed=f'{song_artist}'.lower().replace(' ','.')
|
|
###################################################################################
|
|
if song_title:
|
|
filerenamed+="__"+f"{song_title}".lower().replace(' ','.')
|
|
filerenamed+=f".{song_extension}"
|
|
filerenamed=filerenamed.replace('..','.')
|
|
filerenamed=filerenamed.replace('&','and')
|
|
filerenamed=filerenamed.replace('.(','__')
|
|
filerenamed=filerenamed.replace(').','.')
|
|
filerenamed=filerenamed.replace(',.','.and.')
|
|
filerenamed=filerenamed.replace('._.','__')
|
|
###################################################################################
|
|
os.rename(f'{export_directory}/{themp3}',f'{export_directory}/{filerenamed}')
|
|
print(f'\t renamed: {filerenamed}')
|
|
###################################################################################
|
|
song_length=song.info.time_secs
|
|
duration_min,duration_sec="{:.2f}".format(565.032/60).split('.')
|
|
print(f'\tduration: {duration_min}m{duration_sec}s')
|
|
###################################################################################
|
|
f=open(playlist_path2file,'a')
|
|
f.write(f"#EXTINF:{int(song_length)},{song_artist.lower()} - {song_title.lower()}\n")
|
|
f.write(f"{filerenamed}\n ")
|
|
f.close()
|
|
###################################################################################
|
|
###########################################################################################
|
|
except Exception as e:
|
|
print(f"error: {e}")
|
|
###########################################################################################
|
|
try:
|
|
filelist=glob('*.mp3')
|
|
for _ in filelist: os.remove(_)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
try:
|
|
os.remove(path_to_image)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
try:
|
|
filelist=glob('*.log')
|
|
logfiles=[]
|
|
for _ in filelist:
|
|
f=open(_,'r')
|
|
l=f.read().splitlines()
|
|
f.close()
|
|
logfiles.append([_,l])
|
|
os.remove(_)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
try:
|
|
logkey=[]
|
|
for i,_ in enumerate(logfiles):
|
|
if _[0] == "url_batch.log":
|
|
logkey.append(i)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
try:
|
|
for i,_ in enumerate(logfiles):
|
|
if _[0] == "youtube_url_batch.log":
|
|
logkey.append(i)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
try:
|
|
for i,_ in enumerate(logfiles):
|
|
if _[0] == "youtube_downloaded.log":
|
|
logkey.append(i)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
try:
|
|
for i,_ in enumerate(logfiles):
|
|
if _[0] == "soundcloud_url_batch.log":
|
|
logkey.append(i)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
try:
|
|
for i,_ in enumerate(logfiles):
|
|
if _[0] == "soundcloud_downloaded.log":
|
|
logkey.append(i)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
try:
|
|
for i,_ in enumerate(logfiles):
|
|
if _[0] == "bandcamp_url_batch.log":
|
|
logkey.append(i)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
try:
|
|
for i,_ in enumerate(logfiles):
|
|
if _[0] == "bandcamp_downloaded.log":
|
|
logkey.append(i)
|
|
except:
|
|
pass
|
|
###########################################################################################
|
|
logcmp=[]
|
|
###########################################################################################
|
|
for d,_ in enumerate(logkey):
|
|
offset=len(f"{str(_).zfill(2)}/{str(len(logfiles)-1).zfill(2)} {logfiles[_][0]} iDr1p")
|
|
logcmp.append(f".SOF. {'#'*int(100-offset)} {logfiles[_][0]} {str(d+1).zfill(2)}/{str(len(logfiles)).zfill(2)}")
|
|
logcmp.append("")
|
|
for __ in range(len(logfiles[_][1])):
|
|
logcmp.append( f"{str(__+1).zfill(2)}/{str(len(logfiles[_][1])).zfill(2)} {logfiles[_][1][__]}" )
|
|
logcmp.append("")
|
|
logcmp.append(f"{str(d+1).zfill(2)}/{str(len(logfiles)).zfill(2)} {logfiles[_][0]} {'#'*int(100-offset)} .EOF.")
|
|
logcmp.append("")
|
|
###########################################################################################
|
|
for i,_ in enumerate(logkey): logcmp.append( f'key index: {i} = {_} = {logfiles[_][0]}' )
|
|
###########################################################################################
|
|
f=open(f'{export_directory}/_processed_batch.log','w')
|
|
for _ in logcmp:
|
|
print(_)
|
|
f.write(f'{_}\n')
|
|
f.close()
|
|
###########################################################################################
|
|
print('finished')
|
|
########################################################################################### EOF
|