Advertisement
here2share

# basic_mp3_renamer.py ^ 2016.01

Dec 10th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.60 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # basic_mp3_renamer.py
  3.  
  4. import re
  5. import os
  6.  
  7. tk=0
  8. try:
  9.     from Tkinter import Tk
  10.     root=Tk()
  11.     tk=1
  12. except: print "Tkinter not found...\n\n"
  13.  
  14.  
  15.  
  16. aaa=u'''
  17. DJ 99___ - It'll be The Music___ Ft The A.B.C. and Artisté___ ..mp3
  18. 05-dj_99-it'll_be_the_music...._ft_the_a.b.c._&_artisté-no.ix_rmx.mp3
  19. 05  dj 99 Ft. The A-B-C & Artisté ---- it'll be the music - remix 1.mp3
  20. 5.) dj 99 featuring The A.B.C. and Artisté - it'll be the music - rmx 2.mp3
  21. #5 - dj 99 (Feat. The A.B.C. and L-Artisté)(No.Space Remix) - it'll be the music (~playin' loud).mp3
  22. [5] dj 99 presents The A.B.C. and Lil' L-Artisté - it'll be the music - instrumental.mp3
  23. {5} DJ JR. 99 - ITLL BE THE MUSIC - REMIX [ALL_VOCALS.COM].MP3.MP3
  24. [05] dj Jr. 99 - itll be the music(~playin' loud) - remix - (((allvocals.org))).mp3
  25. 05: dj 99 - itll be the music - uk remix email@allvocals.uk ..mp3
  26. 100 - dj 99 - it'll be the music - - - (((year 2000 remix))) (free download).mp3
  27. dj 99 - 05 - it'll be the music - original remix (lyrics in description).mp3
  28. dj 99 - 05 - it'll be the music (the original mix) produced by kapytulz .mp3
  29. 【RnB】 dj 99 - 09 - Åññõýâñçë !!! - no.ix remix prod. by KAPYTULZ.mp3
  30. 【RnB】 dj 99 - 09 - Åññõýâñçë !!! - no.ix remix prod. by KAPYTULZ(1).mp3
  31. dj%2099%20-%2009%20-%20Åññõýâñçë%20!!!%20【Year%202000%20RNB%20Remix】.mp3
  32. '''
  33. aaa=aaa.split('\n')
  34.  
  35. symbols=(  
  36.     u"абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯÀÁÂÃÄÅÇÈÉÊËḔÌÍÎÏÏÑǸÒÓÔÕÖØŠÙÚÛÜÝàáâãäåçèéêëƒìíîïðñǹòóóôõöøšùúûüýÿı–|`【】[]{}",
  37.     u"abvgdeejzijklmnoprstufhzcss_y_euaABVGDEEJZIJKLMNOPRSTUFHZCSS_Y_EUAAAAAAACEEEEEIIIIINNOOOOOOSUUUUYaaaaaaceeeefiiiionnooooooosuuuuyy_--'()()()")
  38. tr={ord(a):ord(b) for a, b in zip(*symbols)}
  39. br="[0-9a-zA-Z, '~#.$-]*"
  40.  
  41. # basic corrections
  42. corr='''
  43. aint=Ain't
  44. arent=Aren't
  45. cant=Can't
  46. couldve=Could've
  47. couldnt=Couldn't
  48. couldntve=Couldn't've
  49. didnt=Didn't
  50. doesnt=Doesn't
  51. dont=Don't
  52. hadnt=Hadn't
  53. hadntve=Hadn't've
  54. hasnt=Hasn't
  55. havent=Haven't
  56. hed=He'd
  57. hedve=He'd've
  58. hes=He's
  59. Id=I'd
  60. Idve=I'd've
  61. Im=I'm
  62. Ive=I've
  63. isnt=Isn't
  64. itd=It'd
  65. itdve=It'd've
  66. itll=It'll
  67. maam=Ma'am
  68. mightve=Might've
  69. mightnt=Mightn't
  70. mightntve=Mightn't've
  71. mustve=Must've
  72. mustnt=Mustn't
  73. mustntve=Mustn't've
  74. oclock=O'clock
  75. oughtnt=Oughtn't
  76. oughtntve=Oughtn't've
  77. shedve=She'd've
  78. shellve=She'll've
  79. shes=She's
  80. shouldve=Should've
  81. shouldnt=Shouldn't
  82. shouldntve=Shouldn't've
  83. thats=That's
  84. thered=There'd
  85. theres=There's
  86. theyd=They'd
  87. theyll=They'll
  88. theyllve=They'll've
  89. theyre=They're
  90. theyve=They've
  91. wasnt=Wasn't
  92. wellve=We'll've
  93. weve=We've
  94. werent=Weren't
  95. whatll=What'll
  96. whatllve=What'll've
  97. whatre=What're
  98. whats=What's
  99. whatve=What've
  100. whens=When's
  101. whenve=When've
  102. whered=Where'd
  103. wheres=Where's
  104. whereve=Where've
  105. wholl=Who'll
  106. whollve=Who'll've
  107. whos=Who's
  108. whove=Who've
  109. willve=Will've
  110. wont=Won't
  111. wontve=Won't've
  112. wouldve=Would've
  113. wouldnt=Wouldn't
  114. wouldntve=Wouldn't've
  115. yall=Y'all
  116. yalldve=Y'all'd've
  117. yallre=Y'all're
  118. yallve=Y'all've
  119. youd=You'd
  120. youdve=You'd've
  121. youll=You'll
  122. youllve=You'll've
  123. youre=You're
  124. youve=You've
  125. RMX=Remix
  126. randb=RnB
  127. r&b=R&B
  128. Original Remix=Remix
  129. Original Mix=Mix
  130. produced=Prod.
  131. Instrum\w+=(Instr)
  132. Jr\.=Jr
  133. Sr\.=Sr
  134. Mr\.=Mr
  135. Mrs\.=Mrs
  136. Ms\.=Ms
  137. Dr\.=Dr
  138. Lil'=Li'l
  139. vs\.=vs
  140. &=and
  141. featuring=(feat.
  142. ft=(feat.
  143. pres=(feat.
  144. presenting=(feat.
  145. presents=(feat.
  146. '''
  147. corr=corr.split('\n')
  148. corr=[i.split('=') for i in corr if i]
  149.  
  150. # to reconfirm
  151. corr2='''
  152. cuz='Cuz
  153. hell=He'll
  154. hows=How's
  155. Ill=I'll
  156. its=It's
  157. lets=Let's
  158. shed=She'd
  159. shell=She'll
  160. whys=Why's
  161. were=We're
  162. wed=We'd
  163. well=We'll
  164. verses=vs
  165. a\.k\.a.=aka
  166. '''
  167. corr2=corr2.split('\n')
  168. corr2=[i.split('=') for i in corr2 if i]
  169.  
  170. # exclude from title formatting
  171. excl=u'''
  172. 3D
  173. DJ
  174. TV
  175. and
  176. USA
  177. UK
  178. vs
  179. RnB
  180. (of
  181. (aka.
  182. (feat.
  183. II
  184. III
  185. IV
  186. VI
  187. VII
  188. VIII
  189. IX
  190. XI
  191. XII
  192. XIII
  193. XIV
  194. XV
  195. XVI
  196. XVII
  197. XVIII
  198. XIX
  199. XX
  200. XXI
  201. XXII
  202. XXIII
  203. XXIV
  204. XXV
  205. XXX
  206. '''
  207. for z in '().':
  208.     excl=excl.replace(z,'\\'+z)
  209. excl=excl.split('\n')[1:-1]
  210.  
  211. years='(?: |\()?(?:19|20)\d\d(?:\)| |.)'
  212.  
  213. wo='''
  214. free
  215. download
  216. official|original
  217. karaoke
  218. version
  219. hd|hq
  220. high
  221. definition|quality
  222. music
  223. lyrics
  224. audio|video
  225. click
  226. the
  227. link
  228. below
  229. in desc(\.|ription)?
  230. no (tags?|shouts?)?
  231. '''.split('\n')
  232. wo=')? ('.join(wo[1:-1])
  233. wo='('+wo+')'
  234.  
  235. ahead,behind='(?i)(?<=\W)','(?=\W)'
  236. bbb=[]
  237.  
  238. rootDir=r'C:\download\MP3s2chk'
  239. #aaa=[f for f in os.listdir(rootDir) if f.lower().endswith('.mp3')]
  240. tk=0
  241. if tk:
  242.     aaa=root.selection_get(selection="CLIPBOARD").split('\n')
  243. #
  244. fix = "&amp;:&,%20: ,_: ,\(+:(,\)+:),-+:-,'\(\d+\):,([\(\)-])\1+':'\1"
  245. fix = [z.split(':') for z in fix.split(',')]
  246. 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"
  247. v='[#|\(]?\d{1,2}[\.|:|\]|\)|\}| -]+'
  248. version = 'Remix Mix Remake Dub (Instr) Remastered'.split()
  249.  
  250. def self():
  251.     a=''
  252.  
  253. print "Processing data -- Might take a very long while to complete...\n\n"
  254. def fixmp3s():
  255.     def fmb(c1,c2=None):
  256.         if not c2: c2=c1
  257.         a=self.a
  258.         r=re.findall(r'(?i)[\W]{1}'+c1+'[\W]{1}', a)
  259.         if r:
  260.             r=r[0]
  261.             try: self.a=a.replace(r,r[0]+c2+r[-1])
  262.             except: pass
  263.     for a in aaa:
  264.         if a:
  265.             prev=a
  266.             a, ext=os.path.splitext(a)
  267.             a=a.translate(tr)
  268.             print a
  269.             a=re.sub(r'(?i)[ \(]+\S+\.(?:'+www+').+', '', a)
  270.             for zzz,z in fix:
  271.                 a=re.sub(zzz,z,a)
  272.             a=re.sub('''[^0-9a-zA-Z, '()-~#&.$@]''', '', a)
  273.             if ' - ' not in a: a=a.replace('-',' - ')
  274.             a=re.sub('^.?'+v+'[ ]?', '', a)
  275.             a=re.sub(' - '+v, ' - ', a)
  276.            
  277.             ### To include first and last index for the following --
  278.             a='$'+a+'$'
  279.  
  280.             ### To have both [ A.B.C. ] and [ It'll ]
  281.             if a in [a.lower(),a.upper()]:
  282.                 a=a.title()
  283.             else:
  284.                 for z in a.split():
  285.                     if z is not z.upper(): a=a.replace(z,z.title())
  286.             a="'".join([z[0].lower()+z[1:] for z in a.split("'")])
  287.             self.a=a
  288.             for c1,c2 in corr: fmb(c1,c2)
  289.             for z in excl: fmb(z)
  290.             a=self.a
  291.             x=[]
  292.             b=a.replace(' - ',':').replace('$','').replace('(',':(').replace(')','):').split(":")
  293.             for z in ['(~','(-','feat']+version:
  294.                 for zzz in b:
  295.                     if z in zzz:
  296.                         b.remove(zzz)
  297.                         if z in version:
  298.                             zzz=zzz.replace(z,z+':').split(':')[0]
  299.                         x.append('('+zzz+')')
  300.                         break
  301.             bbb=b[:]
  302.             for z in bbb:
  303.                 if '(' in z:
  304.                     x.append('('+z+')')
  305.                     b.remove(z)
  306.             b=' - '.join([z for z in b if len(z)>1][:2])
  307.             x=' '.join(x)
  308.            
  309.             a=('$'+b+' '+x+'$').replace('\\','')
  310.             for z in '()&-': a=a.replace(z*2,z)
  311.             a=' '.join(a.split())
  312.             a=a.replace('-)',')')
  313.             a=a.replace('( ','(')
  314.             a=a.replace(' )',')')
  315.             a=a.replace(') (',')(')
  316.             a=a.replace('$ -','')
  317.             a=a.replace('- $','')
  318.             a=a.replace('$','')
  319.             a=a.replace(' .','')
  320.             while '- -' in a: a=a.replace('- -','-')
  321.             while '....' in a: a=a.replace('....','...')
  322.             a=a.replace('- (',' (')
  323.             for zzz,z in fix: # twice
  324.                 a=re.sub(zzz,z,a)
  325.             a=' '.join(a.split())
  326.             print a
  327.             print
  328.  
  329.             a=a.strip()+ext.lower()
  330.             z=''
  331.             i=1
  332.             while 1:
  333.                 if z+a+'\n' not in bbb:
  334.                     bbb.append(z+a+'\n')
  335.                     #bbb.append(prev+'\n\n')
  336.                     break
  337.                 z='(%s) ' % i
  338.                 i+=1
  339. #
  340.  
  341. web="""<!DOCTYPE html>
  342. <html>
  343. <head></head>
  344. <body><p>@</p></body>
  345. </html>"""
  346.  
  347. fixmp3s()
  348. ccc='<br>'.join(bbb)
  349. bbb=''.join(bbb)
  350. #print bbb
  351.  
  352. import tempfile
  353. import webbrowser
  354.  
  355. srcfilename=tempfile.mktemp(".html", "demo_")
  356. temp=open(srcfilename, 'w')
  357. temp.write(web.replace('@',ccc))
  358.  
  359. ### webbrowser.open_new_tab(srcfilename)
  360. ### temp.write(bbb)
  361. ### os.system("notepad.exe "+srcfilename) ### char io.write limit ???
  362.  
  363. temp.close()
  364.  
  365. #print srcfilename
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement