I’ve been using a software called BetterSleep, which has excellent resources, mixed playback and excellent performance. It supports the Web version and I was particularly interested in how it works, so I did some serious research and discovered The New world.

Make writing a habit together! This is the second day of my participation in the “Gold Digging Day New Plan · April More text challenge”. Click here for more details.

First of all, we should respect intellectual copyright, especially the production of music is not easy, if conditions must buy legitimate software.

Analyze resource loading and decryption

Open theWeb sitePlay one of the audio:

It can be seen that there is a corresponding OGG resource request in the network TAB bar, and the response content is a string similar to base64 format:

As for this string of data, I think it may have been encrypted, there is no use taking it directly, you have to find the corresponding decryption method in the main code.

After analysis, the main code file is presumed to bemainjs:

Open the retrievalogg, finally located the following code and broke the breakpoint:

Enter the next function stack:

onDataDownloaded(data) {
  this.encryptedData = data; // ready for decryption

  this.changeState(SoundTrackState.DECRYPTING);
}
Copy the code

After some analysis to locate the decryption method:

// Comments are a good thing, but the production environment needs to be removed
decrypt() {
  // for now bypass deciphering, we received the sound in base64 directly
  // The previous decryption method is now annotated, that is, no decryption is required !!!!
  //this.cipher.decrypt(this.encryptedData, (decryptedData) => { this.onDataDecrypted(decryptedData); });
  // Base64 data is passed directly to onData Adecrypted
  this.onDataDecrypted(this.encryptedData);
}

onDataDecrypted(decryptedData) {
  this.decryptedData = decryptedData;
  this.changeState(SoundTrackState.LOADING);
}
Copy the code

To continue positioning, we come to the loadSound method:

loadSound() { //var audioExtension = this.soundData.isBrainwave ? 'wav' : this.utils.getBestAudioFormatMimeType(); var audioExtension = this.utils.getBestAudioFormatMimeType(); Var howlSource = ['data:audio/' + audioExtension + ';base64,' + this.decryptedData]; / /... }Copy the code

The DataUrl of an audio called Birds is: data:audio/ogg; Base64,${return base64 string}. Splicing with browser to open, sure enough can play:

Of course, downloads are also available:

Ok, basically understand, in theory, as long as we know the name of the audio, we can directly download the audio.

Gets all audio names

Let’s go to the main code, mainjs, and look for an audio name like Birds:

Suddenly found a lot of audio names, there are free, there are paid. Let’s just copy it.

Ok, audio name done.

Write a download script

Manually downloading them one by one is definitely not possible because there are so many files (hundreds of them) that you still have to write a script that reads the file name, splices it together and saves it to MP3 format.

Here’s the script

The last

This article is for study and research only, please do not steal, spread, sell paid resources.