[SOLVED] Program to recursively find images and rename to "cover.jpg"
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Program to recursively find images and rename to "cover.jpg"
As the title suggests, I'm looking for a simple way to rename all the album art that has accumulated in my music folders over the years. I've used multiple music players in a never ending quest to find the perfect audio player, consequently ending up with a bazillion different jpg's and png's in my music sub-folders (due to stupid automatic cover downloading plugins) with ridiculously long names, such as:
Code:
Accept_-_Metal_Masters-front.jpg
rather than just "cover" or "folder".
What I want to do here is
Search my music folder recursively and find all jpg's and png's
either just completely remove them or change the name to "cover.jpg" or "cover.png" somehow
Ideally I envision a graphical interface that will find the files and display them to me, allowing me to then perform one of the actions I listed above. Does such a program exist? The closest thing that I've ever seen to this is a program written for Windows called Album Art Downloader. It is an awesome program and runs in wine, but sometimes gives me weird results. Is there a native Linux program similar? Many thanks.
**A caveat here is now I'm using xmms2 with xmms2tray, which uses dbus to display album art in the pop-ups. Every one of my albums has art, yet for some reason hardly any of it displays in the pop-up. Anyone know what the filename is that xmms2tray is looking for?
I have no idea about a GUI application. But from the command line it is quite easy, with "find".
Code:
# find . -name ".jpg" -exec mv {} cover.jpg \;
This would move them all to the . directory and rename them, you would need to specify the full path to the results directory, I'm not sure how to do this.
Alternatively you could replace "-exec mv {} cover.jpg \;" with -delete, to remove them completely.
That sounds like it will work. Do you know if I could use the rename command rather than delete? I'll probably just use delete and start from scratch as it will less painful, but for future reference?
Beware! That would effectively delete them all except the last found because each successive mv would overwrite the previous ./cover.jpg
Good catch! Moving/deleting/renaming commands should be given carefully. Furthermore, the command above will not find anything but a hidden file named .jpg (it misses the wildcard). Try this instead:
Here the echo statement before mv just shows the commands to be executed, without actually execute them. In this way you can review the results and if all appears right, run again without echo. Notice the -execdir action addresses the problem raised by catkin: the command will be executed inside each directory where the JPG files are found! Hope this helps.
Thanks for the tip about -execdir and echo. I wasn't familiar with that. I've got so much multiple art though I think I'm just going to delete it and start fresh. What a pain. How would I use echo with delete?
I can understand wanting to remove 'excess' artwork......but why would you want them named 'folder.***' or 'cover.***'? Seems a bad idea to have 10s, 100s or 1000s or files with the same name, even if they are in different folders. I know some media players require 'cover.***' or 'folder.***' but that has always struck me as silly....and the media players I use with album art display dont have requirements like that.
I have no idea why xmms2tray wont display most of your album art. Try checking the art it will display, there are a few possibilities (like it gets the 1st pic file it finds, and tries to display it, but wont display images over 200x200, or wont display images that arent .jpeg, etc..). It might even be that it is only displaying artwork embedded into the tags....
I have no idea why xmms2tray wont display most of your album art. Try checking the art it will display, there are a few possibilities (like it gets the 1st pic file it finds, and tries to display it, but wont display images over 200x200, or wont display images that arent .jpeg, etc..). It might even be that it is only displaying artwork embedded into the tags....
In all likelihood that's the real problem. I hardly have any art embedded in my ID3 tags, which probably correlates to the small percentage of songs which actually display art. The documentation on xmms2tray is slim to none. I emailed the developer to ask what type of file it is looking for but got absolutely no response. I guess I could browse the source code. Can't be too many lines of code. The only reason I would want to rename them all to "folder" or "cover" is simply to take a shot in the dark to see if it picks them up afterward. I guess I could use easytag to embed all the artwork, but 10,000+ songs is a lot when it won't allow me to do more than one song at a time. *sigh*
Anyone know if exfalso do batch art embedding? (or any other program for that matter)
Well, I'm not too familiar with python, but i think I've found the relevant portion of code handling album art. Can anyone clarify what I'm looking at here? (HAVE_IMAGING is set to true as long as python imaging library is found, which it is in this case) Looks to me like it wants a 64x64 image and will resize to this if the original image is larger. This could be my problem because all my art is MINIMUM 500x500. Any thoughts?
Code:
def newsong(self,res):
v = res.value()
if isinstance(v, numbers.Integral):
# this is the ID. I want the whole info.
self.xmms.medialib_get_info(res.value(),self.newsong)
else:
if isinstance(v, basestring): # coverart
info = self.curinfo
coverimg = StringIO(v)
elif v is None: # what?
return
else:
info = v
coverimg = None
self.curinfo = info
img = os.getcwd() + '/data/xmms2_64.png'
if HAVE_IMAGING and 'picture_front' in info:
if info['picture_front'] == self.lastimg[0]:
#same image, just use last.
img = self.lastimg[1]
else:
if self.lastimg[1]:
#there is an old image to delete.
os.remove(self.lastimg[1])
self.lastimg = ('', '')
if coverimg:
orig_pic = Image.open(coverimg)
if orig_pic.size[1] <= 64:
sm_pic = orig_pic
else:
sm_pic = orig_pic.resize((64,64), Image.BICUBIC)
fname = '/tmp/xmms2tray_cover%08X.png' \
% random.randint(0, 2**32-1)
sm_pic.save(fname)
self.lastimg = (info['picture_front'], fname)
img = fname
else:
self.xmms.bindata_retrieve(info['picture_front'],
self.newsong)
return
Well I did some more digging and found that it is only reading embedded art from the ID3 tags. That really blows. Guess I'll get started embedding one song at a time....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.