Advertisement
here2share

# rem_trk99.py

Jun 16th, 2016
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. # -*- coding: utf-8 -*- ### <<< required @ first line
  2. # rem_trk99.py + proper titlecasing
  3.  
  4. import os, re
  5.  
  6. def solve(s):
  7.     name, ext = os.path.splitext(s)
  8.     name = name.replace('_',' ')
  9.     if ' - ' not in name: name = name.replace('-',' - ')
  10.     v='[\[|\(|\{|+|#]?\d{1,2}[\.|:|\]|\)|\}| -]+'
  11.     name = re.sub('^.?'+v+'[ ]?', '', name)
  12.     name = re.sub(' - '+v, ' - ', name)
  13.    
  14.     ### To have both [ A.B.C. ] and [ It'll ]
  15.     return re.sub(r"[A-Za-z]+('[A-Za-z]+)?",
  16.             lambda mo: mo.group(0)[0].upper() +
  17.             mo.group(0)[1:].lower(), name)
  18.  
  19. print solve("DJ 99 - It'll be The Music_ Ft_ The A.B.C. and Artiste.mp3")
  20. print solve("05-dj_99-it'll_be_the_music-remix.mp3")
  21. print solve("05 - dj 99 - it'll be the music - remix.mp3")
  22. print solve("#5 - dj 99 - it'll be the music - remix.mp3")
  23. print solve("5.) dj 99 - it'll be the music - remix.mp3")
  24. print solve(" [5] dj 99 - it'll be the music - remix.mp3")
  25. print solve("{5} dj 99 - it'll be the music - remix.mp3")
  26. print solve("[05] dj 99 - it'll be the music - remix.mp3")
  27. print solve("05: dj 99 - it'll be the music - remix.mp3")
  28. print solve("100 - dj 99 - it'll be the music - remix.mp3")
  29. print solve("dj 99 - 05 - it'll be the music - remix.mp3")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement