Open-source News

Clean up unwanted files in your music directory using Groovy

opensource.com - Mon, 08/29/2022 - 15:00
Clean up unwanted files in your music directory using Groovy Chris Hermansen Mon, 08/29/2022 - 03:00 Register or Login to like Register or Login to like

In this series, I'm developing several scripts to help in cleaning up my music collection. In the last article, we used the framework created for analyzing the directory and sub-directories of music files, checking to make sure each album has a cover.jpg file and recording any other files that aren't FLAC, MP3, or OGG.

I uncovered a few files that can obviously be deleted—I see the odd foo lying around—and a bunch of PDFs, PNGs, and JPGs that are album art. With that in mind, and thinking about the cruft removal task, I offer an improved script that uses a Groovy map to record file names and counts of their occurrences and print that in CSV format.

More on Java What is enterprise Java programming? Red Hat build of OpenJDK Java cheat sheet Free online course: Developing cloud-native applications with microservices Fresh Java articles Get started analyzing with Groovy

If you haven't already, read the first three articles of this series before continuing:

They'll ensure you understand the intended structure of my music directory, the framework created in that article, and how to pick up FLAC, MP3, and OGG files. In this article, I facilitate removing unwanted files in the album directories.

The framework and the album files analysis bits

Start with the code. As before, I've incorporated comments in the script that reflect the (relatively abbreviated) "comment notes" that I typically leave for myself:

1        // Define the music libary directory
2        // def musicLibraryDirName = '/var/lib/mpd/music'
3        // Define the file name accumulation map
4        def fileNameCounts = [:]
5        // Print the CSV file header
6        println "filename|count"
7        // Iterate over each directory in the music libary directory
8        // These are assumed to be artist directories
9        new File(musicLibraryDirName).eachDir { artistDir ->
10            // Iterate over each directory in the artist directory
11            // These are assumed to be album directories
12            artistDir.eachDir { albumDir ->
13                // Iterate over each file in the album directory
14                // These are assumed to be content or related
15                // (cover.jpg, PDFs with liner notes etc)
16                albumDir.eachFile { contentFile ->
17                    // Analyze the file
18                    if (contentFile.name ==~ /.*\.(flac|mp3|ogg)/) {
19                        // nothing to do here
20                    } else if (contentFile.name == 'cover.jpg') {
21                        // don't need to do anything with cover.jpg
22                    } else {
23                        def fn = contentFile.name
24                        if (contentFile.isDirectory())
25                            fn += '/'
26                        fileNameCounts[fn] = fileNameCounts.containsKey(fn) ?  fileNameCounts[fn] + 1 : 1
27                    }
28                }
29            }
30        }
31        // Print the file name counts
32        fileNameCounts.each { key, value ->
33            println "$key|$value"
34        }

This is a pretty straightforward set of modifications to the original framework.

Lines 3-4 define fileNameCount, a map for recording file name counts.

Lines 17-27 analyze the file names. I avoid any files ending in .flac, .mp3 or .ogg as well as cover.jpg files.

Lines 23-26 record file names (as keys to fileNameCounts) and counts (as values). If the file is actually a directory, I append a / to help deal with it in the removal process. Note in line 26 that Groovy maps, like Java maps, need to be checked for the presence of the key before incrementing the value, unlike for example the awk programming language.

That's it!

I run this as follows:

$ groovy TagAnalyzer4.groovy > tagAnalysis4.csv

Then I load the resulting CSV into a LibreOffice spreadsheet by navigating to the Sheet menu and selecting Insert sheet from file. I set the delimiter character to &$124;.

Image by:

(Chris Hermansen, CC BY-SA 4.0)

I've sorted this in decreasing order of the column count to emphasize repeat offenders. Note as well on lines 17-20 a bunch of M3U files that refer to the name of the album, probably created by some well-intentioned ripping program. I also see, further down (not shown), files like fix and fixtags.sh, evidence of prior efforts to clean up some problem and leaving other cruft lying around in the process. I use the find command line utility to get rid of some of these files, along the lines of:

$ find . \( -name \*.m3u -o -name tags.txt -o -name foo -o -name .DS_Store \
-o -name fix -o -name fixtags.sh \) -exec rm {} \;

I suppose I could have used another Groovy script to do that as well. Maybe next time.

In this demonstration, I facilitate removing unwanted files in the album directories.

Image by:

Opensource.com

Java Audio and music What to read next How I analyze my music directory with Groovy My favorite open source library for analyzing music files How I use Groovy to analyze album art in my music directory This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

4 ways to use the Linux tar command

opensource.com - Mon, 08/29/2022 - 15:00
4 ways to use the Linux tar command AmyJune Hineline Mon, 08/29/2022 - 03:00 Register or Login to like Register or Login to like

When you have a lot of related files, it's sometimes easier to treat them as a single object rather than 3 or 20 or 100 unique files. There are fewer clicks involved, for instance, when you email one file compared to the mouse work required to email 30 separate files. This quandary was solved decades ago when programmers invented a way to create an archive, and so the tar command was born (the name stands for tape archive because back then, files were saved to magnetic tape.) Today tar remains a useful way to bundle files together, whether it's to compress them so they take up less space on your drive, to make it easier to deal with lots of files, or to logically group files together as a convenience.

I asked Opensource.com authors how they used tar, and related tools like zip and gzip, in their daily work. Here's what they said.

More Linux resources Linux commands cheat sheet Advanced Linux commands cheat sheet Free online course: RHEL technical overview Linux networking cheat sheet SELinux cheat sheet Linux common commands cheat sheet What are Linux containers? Our latest Linux articles Backups and logs

I use tar and zip whenever I need to make a backup or archive of an entire directory tree. For example, delivering a set of files to a client, or just making a quick backup of my web root directory before I make a major change on the website. If I need to share with others, I create a ZIP archive with zip -9r, where -9 uses best possible compression, and -r will recurse into subdirectories. For example, zip -9r client-delivery.zip client-dir makes a zip file of my work, which I can send to a client.

If the backup is just for me, I probably use tar instead. When I use tar, I usually use gzip to compress, and I do it all on one command line with tar czf, where c will create a new archive file, z compresses it with gzip, and f sets the archive filename. For example, tar czf web-backup.tar.gz html creates a compressed backup of my html directory.

I also have web applications that create log files. And to keep them from taking up too much space, I compress them using gzip. The gzip command is a great way to compress a single file. This can be a TAR archive file, or just any regular file like a log file. To make the gzipped file as small as possible, I compress the file with gzip -9, where -9 uses the best possible compression.

The great thing about using gzip to compress files is that I can use commands like zcat and zless to view them later, without having to uncompress them on the disk. So if I want to look at my log file from yesterday, I can use zless yesterday.log.gz and the zless command automatically uncompresses the data with gunzip and send it to the less viewer. Recently, I wanted to look at how many log entries I had per day, and I ran that with a zcat command like:

for f in *.log.gz; do echo -n "$f,"; zcat $f | wc -l; done

This generates a comma-separated list of log files and a line count, which I can easily import to a spreadsheet for analysis.

Jim Hall

Zcat

I introduced the zcat command in my article Getting started with the cat command. Maybe this can act as a stimulus for further discussion of "in-place" compressed data analysis.

Alan Formy-Duval

Zless and lzop

I love having zless to browse log files and archives. It really helps reduce the risk of leaving random old log files around that I haven't cleaned up.

When dealing with compressed archives, tar -zxf and tar -zcf are awesome, but don't forget about tar -j for those bzip2 files, or even tar -J for the highly compressed xz files.

If you're dealing with a platform with limited CPU resources, you could even consider a lower overhead solution like lzop. For example, on the source computer:

tar --lzop -cf - source_directory | nc destination-host 9999

On the destination computer:

nc -l 9999 | tar --lzop -xf -

I've often used that to compress data between systems where we have bandwidth limitations and need a low resource option.

Steven Ellis

Ark

I've found myself using the KDE application Ark lately. It's a GUI application, but it integrates so well with the Dolphin file manager that I've gotten into the habit of just updating files straight into an archive without even bothering to unarchive the whole thing. Of course, you can do the same thing with the tar command, but if you're browsing through files in Dolphin anyway, Ark makes it quick and easy to interact with an archive without interrupting your current workflow.

Image by:

(Seth Kenlon, CC BY-SA 4.0)

Archives used to feel a little like a forbidden vault to me. Once I put files into an archive, they were as good as forgotten because it just isn't always convenient to interact with an archive. But Ark lets you preview files without uncompressing them (technically they're being uncompressed, but it doesn't "feel" like they are because it all happens in place), remove a file from an archive, update files, rename files, and a lot more. It's a really nice and dynamic way to interact with archives, which encourages me to use them more often.

Seth Kenlon

How do you use the tar command? That's what I recently asked our community of writers. Here are some of their answers.

Image by:

WOCinTech Chat. Modified by Opensource.com. CC BY-SA 4.0

Command line Opensource.com community Linux What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. 174 points Auckland NZ

Steven is an Open Source Advocate and Technologist working for Red Hat since they opened their New Zealand office in May 2011. Over the last 20+ year's he's helped numerous business see the benefit in adopting a wide range of Open Source technologies, and  has spoken at a number of regional and international conferences including OSDC, linux.conf.au, OpenStack Summit, Linux World and OSCON.

In his spare time he still hacks on MythTV, and debugging random new bits of hardware that really should know better.

Follow him on Twitter at @StevensHat.

| Follow StevensHat Open Minded Linux OpenStack SysAdmin CentOS Fedora Geek Ubuntu Author 4906 points (Correspondent) Minnesota

Jim Hall is an open source software advocate and developer, best known for usability testing in GNOME and as the founder + project coordinator of FreeDOS. At work, Jim is CEO of Hallmentum, an IT executive consulting company that provides hands-on IT Leadership training, workshops, and coaching.

| Follow jimfhall Open Source Sensei People's Choice Award People's Choice Award 2018 Correspondent Contributor Club Author 4455 points (Correspondent) United States

Alan has 20 years of IT experience, mostly in the Government and Financial sectors. He started as a Value Added Reseller before moving into Systems Engineering. Alan's background is in high-availability clustered apps. He wrote the 'Users and Groups' and 'Apache and the Web Stack' chapters in the Oracle Press/McGraw Hill 'Oracle Solaris 11 System Administration' book. He earned his Master of Science in Information Systems from George Mason University. Alan is a long-time proponent of Open Source Software.

| Follow AlanFormy_Duval Open Source Sensei People's Choice Award Apache DevOps Gamer Linux SysAdmin Geek Java Contributor Club Author Comment Gardener Correspondent 27105 points (Team, Red Hat) New Zealand (South Island)

Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time. He is one of the maintainers of the Slackware-based multimedia production project Slackermedia.

Open Source Super Star Moderator's Choice Award 2011 100+ Contributions Club Best Interview Award 2017 Author Columnist Contributor Club Register or Login to post a comment.

3 Ways to Install Skype in Fedora Linux

Tecmint - Mon, 08/29/2022 - 13:26
The post 3 Ways to Install Skype in Fedora Linux first appeared on Tecmint: Linux Howtos, Tutorials & Guides .

Skype is a popular proprietary communication application well known for its voice calls, chats, VoIP-based video telephony, and video conferencing functionalities. It helps people stay connected regardless of their geographical location; from colleagues within

The post 3 Ways to Install Skype in Fedora Linux first appeared on Tecmint: Linux Howtos, Tutorials & Guides.

Linux 6.0-rc3 Released In Marking 31 Years Since Linus Torvalds Announced It

Phoronix - Mon, 08/29/2022 - 06:39
Linus Torvalds just released the third weekly release candidate of the upcoming Linux 6.0 kernel...

Intel Arc Graphics A380: Compelling For Open-Source Enthusiasts & Developers At ~$139

Phoronix - Sun, 08/28/2022 - 21:00
Last week I outlined getting Intel Arc Graphics running on a open-source Linux graphics driver when using Linux 6.0 and later (along with a currently-experimental module option override) and then Mesa 22.2+. Now that I've had more days with the Intel Arc Graphics A380 as the company's budget discrete GPU, here are more of my thoughts on this graphics card that has begun retailing in the US for $139.

Wine 7.16 Released With WoW64 X11 Driver Support, 20 Bug Fixes

Phoronix - Sun, 08/28/2022 - 20:47
Wine 7.16 fell slightly off its Friday bi-weekly release train and arrived this morning...

Ubuntu Isn't Yet Onboard With GNOME's "Device Security" Screen

Phoronix - Sun, 08/28/2022 - 18:47
Coming with GNOME 43 is a "Device Security" panel within the GNOME Control Center. While intended to help ensure their system is protected, Ubuntu isn't onboard with this Device Security functionality yet and has stripped it out from their GNOME build for Ubuntu 22.10...

Ubuntu 22.10 To Ship With WebP Image Support Out-Of-The-Box

Phoronix - Sun, 08/28/2022 - 17:39
Prior to this past week's Ubuntu 22.10 feature freeze, webp-pixbuf-loader was promoted to the main archive for allowing WebP images to have thumbnail support within the GNOME desktop on this next Ubuntu release and being able to open up WebP image files within the GNOME image viewer and the like...

AMD Radeon Linux OpenGL Driver Makes More Optimizations, Eyes GL Threading By Default

Phoronix - Sun, 08/28/2022 - 17:23
Longtime AMD open-source Linux graphics developer Marek Olšák is at it again with some interesting optimizations for RadeonSI Gallium3D and is eyeing at enabling OpenGL threading by default...

Pages