How to export downloaded music files from ios music box (using Java programming)
How to export downloaded music files from ios music box
The content involved in this article is used for technical learning. Do not use it for improper purposes. Otherwise, you are solely responsible for the consequences.
When viewing the music files downloaded by cool music ios edition through software such as the synchronization assistant, it is found that the music files are named by a string of numbers. By searching online and trying it by yourself, we found that all those files were audio files and changed their file names. You only need to modify the file name to play the video like normal music.
Reference: http://blog.sina.com.cn/s/blog_4d5428240101enzu.html
I found a software on the Internet, that is, the software in the above reference website, but there was a problem in use, prompting subscript out of range, the program cannot continue to be executed. So I decided to write one in Java for processing.
First, copy the cloud. db database file from the mobile phone, which is the SQLite database file. Open it with SQLite Database Browser and you can see that there are three tables closely related to music in it. playlistsInfo stores the playlist information. The field title is the list name and the field id is the list id. PlaylistMusics stores the correspondence between music and the playlist. The title and artist fields are music information, the rid field is the Music Resource id, and the playlist_id field corresponds to the playlist id. MusicResource is the correspondence between music information and files. The field file is the corresponding file name, format is the file format, and rid is the Music Resource id.
The workflow of the program is as follows: 1. First, read the rid of each music one by one from musicResource; 2. Find playlist_id in playlistMusics through the rid, which may not be found, there may be more than one, because the same music may be in multiple lists. Here, we simply take the largest playlist_id, which is usually a relatively new playlist; 3. Find the playlist name corresponding to playlist_id in playlistsInfo as a sub-folder of the target music. 4. Rename the source file as "artist name-song name. and move it to the target folder.
For convenience of communication and learning, the source code of this program is provided here.
Import java. io. file; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. resultSet; import java. SQL. statement; import java. util. arrayList; import java. util. list; public class Test {/*** stores the data structure of the PlayList ** @ author jzj */static class PlayList {int id; String name; public PlayList (String name, int id) {this. name = name; this. id = id ;}/// full database path static final String db_path = "G: \ IOS \ cloud. db "; // source folder static final String src_dir =" G: \ IOS \ Music \ "; // target folder static final String dst_dir =" G: \ IOS \ Music1 \ "; public static void main (String [] args) throws Exception {Class. forName ("org. sqlite. JDBC "); Connection conn = DriverManager. getConnection ("jdbc: sqlite:" + db_path); Statement stat1 = conn. createStatement (); Statement stat2 = conn. createStatement (); // read the playlist List
Lists = new ArrayList
(); ResultSet rs_list = stat1.executeQuery ("select * from playlistsInfo;"); while (rs_list.next () {final int id = rs_list.getInt ("id "); final String name = rs_list.getString ("title"); switch (name) {// ignore these lists case "local songs": case "default list": case "Recent playback ": case "my radio station": break; case "I like": default: lists. add (new PlayList (name, id) ;}// read the music information ResultSet rs_res = stat1.executeQuery ("select * from musicResource;"); while (Rs_res.next () {// source file path String fname = rs_res.getString ("file"); if (fname = null | fname. length () = 0) // if the file field is null, skip continue; String src_path = src_dir + fname; File src = new File (src_path); if (! Src. exists () // if the source file does not exist, skip continue; // obtain the music ridint rid = rs_res.getInt ("rid"); // find the playlist id of the music, -1 ResultSet rs_pl = stat2.executeQuery (new StringBuilder ("select playlist_id from playlistMusics where rid = "). append (rid ). append (';'). toString (); int playlist_id =-1; while (rs_pl.next () {// by default, a song is placed in the largest playlist (that is, the latest list) int p_id = rs_pl.getInt ("playlist_id"); if (p_id> playlist_id) playlist_id = P_id;} rs_pl.close (); // target folder path StringBuilder b2 = new StringBuilder (dst_dir); if (playlist_id> = 0) {String playlist_name = getPlaylist (lists, playlist_id ); if (playlist_name! = Null) {b2.append (playlist_name ). append ('\') ;}} String dir = b2.toString (); new File (dir ). mkdirs (); // target file name: "artist-song name. extension "StringBuilder b3 = new StringBuilder (); b3.append (rs_res.getString (" artist ")). append ("-"). append (rs_res.getString ("title ")). append ('. '). append (rs_res.getString ("format"); String dst_path = dir + b3.toString (); // move and rename File dst = new File (dst_path); src. renameTo (dst); // output information System. out. println (new StringBuilder (src_path ). append ("---> "). append (dst_path);} rs_res.close (); conn. close ();} static String getPlaylist (List
Lists, int playlist_id) {for (PlayList pl: lists) {if (pl. id = playlist_id) return pl. name;} return null ;}}
Because database operations are involved, you need to add a database support package in the Java project. For details, refer
Copy all audio files and place them to the directory specified by src_dir in the program. The database file is cloud. db is saved at the location specified by db_path. After setting the destination folder dst_dir, You can execute the program to refresh the exported audio file. More than 700 pieces of music are tested, and the renaming and moving work can be completed in less than one minute.
The complete project can be downloaded here: http://pan.baidu.com/s/1hGNT0