A Bash script to rip music off CUE/BIN files

I thought I’d take the opportunity to share a Bash script I made to automate ripping music off CUE/BIN files. It splits BINs into separate files, so it’s 1 file per track, and strips pregap data, encodes audio tracks to FLAC or Ogg Vorbis, and it also generates new CUE sheets.

Link to the script:

<a href="">https://github.com/linux4ever07/scripts/blob/main/cuebin_extract.sh</a>

The idea came to me some years ago when I noticed that GOG packaged some of their games in a dumb way. It was specifically DOS games (bundled with DOSBox) that had CD audio. They would include the original BIN file, but with a modified CUE sheet that would not let you access the high quality CD audio. On top of that, they included Ogg Vorbis tracks, wasting HDD space for no reason by effectively storing the music twice, but only letting you access the lower quality Vorbis tracks. So, I thought, why not just split the BIN, encode the audio tracks to FLAC, and that way you both get better audio quality and also use less HDD space. DOSBox supports CUE sheets that list FLAC, Ogg Vorbis and even Opus tracks.

I took inspiration from ‘bchunk’, which is a program that does something similar. However, bchunk converts data tracks to ISO files, which is not what I wanted. I wanted to keep the original tracks completely untouched, so my script will copy data tracks as normal BIN files. bchunk also can’t encode audio tracks to FLAC or Ogg Vorbis, but it will produce uncompressed WAV files. And bchunk doesn’t produce new CUE sheets for the created files.

I also use the script to extract the OST from random games. I put together a playlist with some of my favorite retro video game music that I extracted using the script:

<a href="">https://www.youtube.com/watch?v=nHI7ghR6XX4</a>

There’s other uses for the script, such as splitting BINs in general. For example, many BeOS / ZETA disc images contain boot floppies as the first track, and once you split the BIN you can access the boot floppy image. And you can create frankenstein disc images by exchanging tracks between different disc images.

The script is made for Linux, but should work on macOS / FreeBSD as well if you have a recent version of Bash installed, as well as ffmpeg, flac and oggenc.

linux4ever07,

I just checked the macOS / FreeBSD man page for ‘stat’, and noticed the syntax differs from the version in GNU coreutils (which is what’s used in Linux). That’s probably the only thing that would need to be changed to make the script work on those other systems. It’s on line 530.

possiblylinux127,

Well pretty much no one is using BSD

linux4ever07,

Fair enough. But macOS has more users than Linux, and is partly based on FreeBSD. The shell and the userland tools are from FreeBSD. I prefer Linux of course and haven’t used a Mac in years, but I still think it’s nice making scripts compatible with all *nix systems.

possiblylinux127,

Fair enough, I just don’t pester the developer if you can avoid it. (Foss devs often receive demands)

linux4ever07,

For sure. If you get something for free then it is what it is. Some of my scripts probably won’t work outside of Linux but I still make an effort to not use external commands if there’s no need to. I try to use the internal features of Bash as much as possible, mostly cause it’s just faster that way. A consequence of that is that the scripts are at least more likely to work on other systems (that have Bash).

xmanmonk,

Looks good! Thanks for sharing!

linux4ever07,

Thank you! I’m happy if more people besides just myself have use for it. It’s a niche some people might not be aware of. Especially for younger people who aren’t familiar with the CD format, and how music is stored in those games. It might help people get more direct access to the OST of their favorite retro games. Instead of having to search around the web for high quality audio, they can just extract it themselves.

rjek,

Why not just use cdparanoia with the original CD?

linux4ever07,

If you have the original disc, then yeah. The script is more meant for when you get CUE/BINs online, such as Redump disc images for example.

rjek,

Then then why not buy the CD?

blashork,
@blashork@hexbear.net avatar
MigratingtoLemmy,

Let’s say the OP was given the CUE rip by his friend

rjek,

I ask because that repo says “The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.” and yet it exists only to abuse other people’s creative rights.

linux4ever07,

Another thing to think about is that CD is a dying format, and the way those old CD-based games are going to be preserved long-term is in the form of disc images stored on HDDs.

fenndev,
@fenndev@leminal.space avatar

It is not an abuse of anyone’s creative rights to the convert music from a game you legally own to a different format.

gaylord_fartmaster,

I’m sure the artists behind the music for the 20+ year old games this could be used for are really feeling the pain of their creative rights being abused from people trying to still enjoy their art after all this time, you wet blanket.

linux4ever07,

Many older games are not sold physically anymore, and getting them on the second hand market can be pretty expensive depending on how rare they are.

Ohh,

I am not sure this script will help. But I actually have a lot of cue/bin files from back when I ripped my cd collection. If I remember correctly, I played them through mediamonkey (ape files) or foobar. Windows user then… Most CD’s are either lost or in the back of the attic somewhere. I consider the files dead, but havent deleted them yet. I use plex which can’t play cue/bin files. This script might make my old cd collection come alive again…

linux4ever07,

If they are CUE/BIN files the script will be able to handle them all without a problem. My advice is to use the ‘-flac’ argument when running the script, so you get lossless copies. But you should double-check the resulting CUE sheet, after processing each album. See if any of the pregaps are longer than a few seconds, cause in rare cases there’s hidden bonus tracks in the pregaps. If that’s the case, you can extract the pregaps separately with the ‘-pregaps’ argument. Good luck!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • DreamBathrooms
  • magazineikmin
  • InstantRegret
  • hgfsjryuu7
  • vwfavf
  • Youngstown
  • slotface
  • thenastyranch
  • ngwrru68w68
  • rosin
  • kavyap
  • PowerRangers
  • Durango
  • khanakhh
  • anitta
  • mdbf
  • tacticalgear
  • ethstaker
  • modclub
  • osvaldo12
  • everett
  • tester
  • cubers
  • GTA5RPClips
  • normalnudes
  • Leos
  • cisconetworking
  • provamag3
  • All magazines