Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
JoaoRodrigues

[Python] Ir buscar capas para os Albuns de Musica

Recommended Posts

JoaoRodrigues

Nem sempre sai perfeito, mas, funciona para 9/10 casos (no meu pc pelo menos).

Precisa de uma biblioteca adicional: http://code.google.com/p/quodlibet/wiki/Development/Mutagen

# -*- coding: cp1252 -*-
# Script made by João Rodrigues
# Gets Album Covers from http://albumart.org and saves them in the album folder.
# WARNING: THE COVERS MAY NOT BE THE BEST ONES! NOR THE CORRECT ONES (though they were in my tests..)!
# 23.09.2008 @ Utrecht
# Rant to: anaryin@gmail.com

import os
import urllib2
import re
from mutagen.mp3 import MP3
import urllib

# Accessing the music folder

userName = os.path.expanduser('~').split('\\')[-1]
musicPath = r'C:\Users\%s\Music' %userName

allNames = []

for root, dirs, files in os.walk(musicPath):
    for fileName in files:
        if fileName.split('.')[-1] == 'mp3':
            # Get audio file info
            audioFile = MP3(os.path.join(root, fileName))
            bandName = audioFile["TPE1"]
            albumName = audioFile["TALB"]

            if albumName not in allNames:
                allNames.append(str(albumName))
                # Get cover and save it
                print bandName, '-', albumName
                baseUrl = 'http://albumart.org/index.php?srchkey=%s&itempage=1&newsearch=1&searchindex=Music' %((str(bandName)+' '+str(albumName)).replace(' ', '+'))
                jpegReGex = '.(http://ecx.images-amazon.com/[\w / -]+.jpg).'
                matches = re.findall(jpegReGex, urllib2.urlopen(baseUrl).read())
                if matches:
                    probableCandidate = matches[0]
                    urllib.urlretrieve(probableCandidate, os.path.join(root, '%s - %s.jpg' %(bandName, albumName)))
print "Finished"
print "Press any key to exit.."
raw_input()

Se vos apetecer testar e dar ideias, força :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.