Advertisement
Guest User

Joao Rodrigues

a guest
Sep 23rd, 2008
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2. # Script made by João Rodrigues
  3. # Gets Album Covers from http://albumart.org and saves them in the album folder.
  4. # WARNING: THE COVERS MAY NOT BE THE BEST ONES! NOR THE CORRECT ONES (though they were in my tests..)!
  5. # 23.09.2008 @ Utrecht
  6. # Rant to: anaryin@gmail.com
  7.  
  8. import os
  9. import urllib2
  10. import re
  11. from mutagen.mp3 import MP3
  12. import urllib
  13.  
  14. # Accessing the music folder
  15.  
  16. userName = os.path.expanduser('~').split('\\')[-1]
  17. musicPath = r'C:\Users\%s\Music' %userName
  18.  
  19. allNames = []
  20.  
  21. for root, dirs, files in os.walk(musicPath):
  22.     for fileName in files:
  23.         if fileName.split('.')[-1] == 'mp3':
  24.             # Get audio file info
  25.             audioFile = MP3(os.path.join(root, fileName))
  26.             bandName = audioFile["TPE1"]
  27.             albumName = audioFile["TALB"]
  28.  
  29.             if albumName not in allNames:
  30.                 allNames.append(str(albumName))
  31.                 # Get cover and save it
  32.                 print bandName, '-', albumName
  33.                 baseUrl = 'http://albumart.org/index.php?srchkey=%s&itempage=1&newsearch=1&searchindex=Music' %((str(bandName)+' '+str(albumName)).replace(' ', '+'))
  34.                 jpegReGex = '.(http://ecx.images-amazon.com/[\w / -]+.jpg).'
  35.                 matches = re.findall(jpegReGex, urllib2.urlopen(baseUrl).read())
  36.                 if matches:
  37.                     probableCandidate = matches[0]
  38.                     urllib.urlretrieve(probableCandidate, os.path.join(root, '%s - %s.jpg' %(bandName, albumName)))
  39. print "Finished"
  40. print "Press any key to exit.."
  41. raw_input()
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement