Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # basic_mp3_renamer.py
- import re
- import os
- tk=0
- try:
- from Tkinter import Tk
- root=Tk()
- tk=1
- except: print "Tkinter not found...\n\n"
- aaa=u'''
- DJ 99___ - It'll be The Music___ Ft The A.B.C. and Artisté___ ..mp3
- 05-dj_99-it'll_be_the_music...._ft_the_a.b.c._&_artisté-no.ix_rmx.mp3
- 05 dj 99 Ft. The A-B-C & Artisté ---- it'll be the music - remix 1.mp3
- 5.) dj 99 featuring The A.B.C. and Artisté - it'll be the music - rmx 2.mp3
- #5 - dj 99 (Feat. The A.B.C. and L-Artisté)(No.Space Remix) - it'll be the music (~playin' loud).mp3
- [5] dj 99 presents The A.B.C. and Lil' L-Artisté - it'll be the music - instrumental.mp3
- {5} DJ JR. 99 - ITLL BE THE MUSIC - REMIX [ALL_VOCALS.COM].MP3.MP3
- [05] dj Jr. 99 - itll be the music(~playin' loud) - remix - (((allvocals.org))).mp3
- 05: dj 99 - itll be the music - uk remix email@allvocals.uk ..mp3
- 100 - dj 99 - it'll be the music - - - (((year 2000 remix))) (free download).mp3
- dj 99 - 05 - it'll be the music - original remix (lyrics in description).mp3
- dj 99 - 05 - it'll be the music (the original mix) produced by kapytulz .mp3
- 【RnB】 dj 99 - 09 - Åññõýâñçë !!! - no.ix remix prod. by KAPYTULZ.mp3
- 【RnB】 dj 99 - 09 - Åññõýâñçë !!! - no.ix remix prod. by KAPYTULZ(1).mp3
- dj%2099%20-%2009%20-%20Åññõýâñçë%20!!!%20【Year%202000%20RNB%20Remix】.mp3
- '''
- aaa=aaa.split('\n')
- symbols=(
- u"абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯÀÁÂÃÄÅÇÈÉÊËḔÌÍÎÏÏÑǸÒÓÔÕÖØŠÙÚÛÜÝàáâãäåçèéêëƒìíîïðñǹòóóôõöøšùúûüýÿı–|`【】[]{}",
- u"abvgdeejzijklmnoprstufhzcss_y_euaABVGDEEJZIJKLMNOPRSTUFHZCSS_Y_EUAAAAAAACEEEEEIIIIINNOOOOOOSUUUUYaaaaaaceeeefiiiionnooooooosuuuuyy_--'()()()")
- tr={ord(a):ord(b) for a, b in zip(*symbols)}
- br="[0-9a-zA-Z, '~#.$-]*"
- # basic corrections
- corr='''
- aint=Ain't
- arent=Aren't
- cant=Can't
- couldve=Could've
- couldnt=Couldn't
- couldntve=Couldn't've
- didnt=Didn't
- doesnt=Doesn't
- dont=Don't
- hadnt=Hadn't
- hadntve=Hadn't've
- hasnt=Hasn't
- havent=Haven't
- hed=He'd
- hedve=He'd've
- hes=He's
- Id=I'd
- Idve=I'd've
- Im=I'm
- Ive=I've
- isnt=Isn't
- itd=It'd
- itdve=It'd've
- itll=It'll
- maam=Ma'am
- mightve=Might've
- mightnt=Mightn't
- mightntve=Mightn't've
- mustve=Must've
- mustnt=Mustn't
- mustntve=Mustn't've
- oclock=O'clock
- oughtnt=Oughtn't
- oughtntve=Oughtn't've
- shedve=She'd've
- shellve=She'll've
- shes=She's
- shouldve=Should've
- shouldnt=Shouldn't
- shouldntve=Shouldn't've
- thats=That's
- thered=There'd
- theres=There's
- theyd=They'd
- theyll=They'll
- theyllve=They'll've
- theyre=They're
- theyve=They've
- wasnt=Wasn't
- wellve=We'll've
- weve=We've
- werent=Weren't
- whatll=What'll
- whatllve=What'll've
- whatre=What're
- whats=What's
- whatve=What've
- whens=When's
- whenve=When've
- whered=Where'd
- wheres=Where's
- whereve=Where've
- wholl=Who'll
- whollve=Who'll've
- whos=Who's
- whove=Who've
- willve=Will've
- wont=Won't
- wontve=Won't've
- wouldve=Would've
- wouldnt=Wouldn't
- wouldntve=Wouldn't've
- yall=Y'all
- yalldve=Y'all'd've
- yallre=Y'all're
- yallve=Y'all've
- youd=You'd
- youdve=You'd've
- youll=You'll
- youllve=You'll've
- youre=You're
- youve=You've
- RMX=Remix
- randb=RnB
- r&b=R&B
- Original Remix=Remix
- Original Mix=Mix
- produced=Prod.
- Instrum\w+=(Instr)
- Jr\.=Jr
- Sr\.=Sr
- Mr\.=Mr
- Mrs\.=Mrs
- Ms\.=Ms
- Dr\.=Dr
- Lil'=Li'l
- vs\.=vs
- &=and
- featuring=(feat.
- ft=(feat.
- pres=(feat.
- presenting=(feat.
- presents=(feat.
- '''
- corr=corr.split('\n')
- corr=[i.split('=') for i in corr if i]
- # to reconfirm
- corr2='''
- cuz='Cuz
- hell=He'll
- hows=How's
- Ill=I'll
- its=It's
- lets=Let's
- shed=She'd
- shell=She'll
- whys=Why's
- were=We're
- wed=We'd
- well=We'll
- verses=vs
- a\.k\.a.=aka
- '''
- corr2=corr2.split('\n')
- corr2=[i.split('=') for i in corr2 if i]
- # exclude from title formatting
- excl=u'''
- 3D
- DJ
- TV
- and
- USA
- UK
- vs
- RnB
- (of
- (aka.
- (feat.
- II
- III
- IV
- VI
- VII
- VIII
- IX
- XI
- XII
- XIII
- XIV
- XV
- XVI
- XVII
- XVIII
- XIX
- XX
- XXI
- XXII
- XXIII
- XXIV
- XXV
- XXX
- '''
- for z in '().':
- excl=excl.replace(z,'\\'+z)
- excl=excl.split('\n')[1:-1]
- years='(?: |\()?(?:19|20)\d\d(?:\)| |.)'
- wo='''
- free
- download
- official|original
- karaoke
- version
- hd|hq
- high
- definition|quality
- music
- lyrics
- audio|video
- click
- the
- link
- below
- in desc(\.|ription)?
- no (tags?|shouts?)?
- '''.split('\n')
- wo=')? ('.join(wo[1:-1])
- wo='('+wo+')'
- ahead,behind='(?i)(?<=\W)','(?=\W)'
- bbb=[]
- rootDir=r'C:\download\MP3s2chk'
- #aaa=[f for f in os.listdir(rootDir) if f.lower().endswith('.mp3')]
- tk=0
- if tk:
- aaa=root.selection_get(selection="CLIPBOARD").split('\n')
- #
- fix = "&:&,%20: ,_: ,\(+:(,\)+:),-+:-,'\(\d+\):,([\(\)-])\1+':'\1"
- fix = [z.split(':') for z in fix.split(',')]
- www = "com|net|tv|fm|ly|ws|me|cc|co|org|biz|mobi|name|int|tel|info|edu|uk|nl|eu|ru|asia|coop|de|cn"
- v='[#|\(]?\d{1,2}[\.|:|\]|\)|\}| -]+'
- version = 'Remix Mix Remake Dub (Instr) Remastered'.split()
- def self():
- a=''
- print "Processing data -- Might take a very long while to complete...\n\n"
- def fixmp3s():
- def fmb(c1,c2=None):
- if not c2: c2=c1
- a=self.a
- r=re.findall(r'(?i)[\W]{1}'+c1+'[\W]{1}', a)
- if r:
- r=r[0]
- try: self.a=a.replace(r,r[0]+c2+r[-1])
- except: pass
- for a in aaa:
- if a:
- prev=a
- a, ext=os.path.splitext(a)
- a=a.translate(tr)
- print a
- a=re.sub(r'(?i)[ \(]+\S+\.(?:'+www+').+', '', a)
- for zzz,z in fix:
- a=re.sub(zzz,z,a)
- a=re.sub('''[^0-9a-zA-Z, '()-~#&.$@]''', '', a)
- if ' - ' not in a: a=a.replace('-',' - ')
- a=re.sub('^.?'+v+'[ ]?', '', a)
- a=re.sub(' - '+v, ' - ', a)
- ### To include first and last index for the following --
- a='$'+a+'$'
- ### To have both [ A.B.C. ] and [ It'll ]
- if a in [a.lower(),a.upper()]:
- a=a.title()
- else:
- for z in a.split():
- if z is not z.upper(): a=a.replace(z,z.title())
- a="'".join([z[0].lower()+z[1:] for z in a.split("'")])
- self.a=a
- for c1,c2 in corr: fmb(c1,c2)
- for z in excl: fmb(z)
- a=self.a
- x=[]
- b=a.replace(' - ',':').replace('$','').replace('(',':(').replace(')','):').split(":")
- for z in ['(~','(-','feat']+version:
- for zzz in b:
- if z in zzz:
- b.remove(zzz)
- if z in version:
- zzz=zzz.replace(z,z+':').split(':')[0]
- x.append('('+zzz+')')
- break
- bbb=b[:]
- for z in bbb:
- if '(' in z:
- x.append('('+z+')')
- b.remove(z)
- b=' - '.join([z for z in b if len(z)>1][:2])
- x=' '.join(x)
- a=('$'+b+' '+x+'$').replace('\\','')
- for z in '()&-': a=a.replace(z*2,z)
- a=' '.join(a.split())
- a=a.replace('-)',')')
- a=a.replace('( ','(')
- a=a.replace(' )',')')
- a=a.replace(') (',')(')
- a=a.replace('$ -','')
- a=a.replace('- $','')
- a=a.replace('$','')
- a=a.replace(' .','')
- while '- -' in a: a=a.replace('- -','-')
- while '....' in a: a=a.replace('....','...')
- a=a.replace('- (',' (')
- for zzz,z in fix: # twice
- a=re.sub(zzz,z,a)
- a=' '.join(a.split())
- print a
- print
- a=a.strip()+ext.lower()
- z=''
- i=1
- while 1:
- if z+a+'\n' not in bbb:
- bbb.append(z+a+'\n')
- #bbb.append(prev+'\n\n')
- break
- z='(%s) ' % i
- i+=1
- #
- web="""<!DOCTYPE html>
- <html>
- <head></head>
- <body><p>@</p></body>
- </html>"""
- fixmp3s()
- ccc='<br>'.join(bbb)
- bbb=''.join(bbb)
- #print bbb
- import tempfile
- import webbrowser
- srcfilename=tempfile.mktemp(".html", "demo_")
- temp=open(srcfilename, 'w')
- temp.write(web.replace('@',ccc))
- ### webbrowser.open_new_tab(srcfilename)
- ### temp.write(bbb)
- ### os.system("notepad.exe "+srcfilename) ### char io.write limit ???
- temp.close()
- #print srcfilename
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement