diff options
| author | Donald Shan <xxpinapelzxx@gmail.com> | 2022-08-18 19:23:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-18 19:23:41 -0700 |
| commit | cf0a33531dec34969502ef1ffe87be49f70abccd (patch) | |
| tree | e3becc1223592c0b8e6780b19752c74c1cf82450 /src | |
| parent | 070744961e24beb1acd128a88058971b9ef59b55 (diff) | |
append videoID to saved file names
Appended videoID to saved file names because some characters in titles may be illegal when attempting to move files from the download directory to the competed directory. When removing alphanumeric characters, videos in another language may contain the same words which leads to files being overwritten. Appending videoID to the end will result in a unique name for each video downloaded
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/org/example/Main.java | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index ee8bd2a..6d87057 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -30,7 +30,7 @@ public class Main { Artwork cover = Artwork.createArtworkFromFile(new File("img.jpg"));
tag.addField(cover);
f.commit();
- moveFile(findMP3File("downloaded").getAbsolutePath(), "completed/" + info[0] + ".mp3");
+ moveFile(findMP3File("downloaded").getAbsolutePath(), "completed/" + removeNonAlphaNumeric(info[0]) + " ["+info[2]+ "].mp3");
} catch (Exception e) {
e.printStackTrace();
@@ -51,12 +51,15 @@ public class Main { fos.close();
is.close();
}
-
+//remove all non alphanumeric characters from string
+ public static String removeNonAlphaNumeric(String str) {
+ return str.replaceAll("[^a-zA-Z0-9]", "");
+ }
public static void moveFile(String source, String destination) {
File sourceFile = new File(source);
File destinationFile = new File(destination);
sourceFile.renameTo(destinationFile);
- System.out.println("Moving file to Completed Folder");
+ System.out.println("Moved file to Completed Folder");
}
public static File findMP3File(String directory){
|
