Created
March 29, 2015 06:08
-
-
Save zhaofengli/4374225542fb3d340629 to your computer and use it in GitHub Desktop.
Moves MP3 files downloaded via Baidu Music
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Moves MP3 files downloaded via Baidu Music | |
// By Zhaofeng Li - Public domain | |
$pattern = "/(?'artist'[^-]+)-(?'album'[^-]+)-(?'title'[^-]+)-/"; | |
$dir = "/sdcard/Baidu_music/download"; | |
$dest = "/sdcard/Music"; | |
$files = scandir( $dir ); | |
foreach ( $files as $file ) { | |
if ( preg_match( $pattern, $file, $m ) ) { | |
if ( strpos( $m['artist'], "," ) ) continue; | |
$destdir = $dest . "/{$m['artist']}/{$m['album']}"; | |
if ( !is_dir( $destdir ) ) { | |
echo "Creating $destdir\n"; | |
mkdir( $destdir, 0777, true ); | |
} | |
$target = $destdir . "/{$m['title']}.mp3"; | |
rename( "$dir/$file", $target ); | |
echo "Moved $dir/$file to $target\n"; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment