mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-22 21:43:06 +02:00
reorder and comment code to find filename
This commit is contained in:
@@ -395,10 +395,17 @@ public abstract class AbstractRipper
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getFileName(URL url, String fileName, String extension) {
|
public static String getFileName(URL url, String fileName, String extension) {
|
||||||
|
// retrieve filename from URL if not passed
|
||||||
if (fileName == null || fileName.trim().isEmpty()) {
|
if (fileName == null || fileName.trim().isEmpty()) {
|
||||||
fileName = url.toExternalForm();
|
fileName = url.toExternalForm();
|
||||||
fileName = fileName.substring(fileName.lastIndexOf('/')+1);
|
fileName = fileName.substring(fileName.lastIndexOf('/')+1);
|
||||||
}
|
}
|
||||||
|
if (fileName.indexOf('?') >= 0) { fileName = fileName.substring(0, fileName.indexOf('?')); }
|
||||||
|
if (fileName.indexOf('#') >= 0) { fileName = fileName.substring(0, fileName.indexOf('#')); }
|
||||||
|
if (fileName.indexOf('&') >= 0) { fileName = fileName.substring(0, fileName.indexOf('&')); }
|
||||||
|
if (fileName.indexOf(':') >= 0) { fileName = fileName.substring(0, fileName.indexOf(':')); }
|
||||||
|
|
||||||
|
// retrieve extension from URL if not passed, no extension if nothing found
|
||||||
if (extension == null || extension.trim().isEmpty()) {
|
if (extension == null || extension.trim().isEmpty()) {
|
||||||
// Get the extension of the file
|
// Get the extension of the file
|
||||||
String[] lastBitOfURL = url.toExternalForm().split("/");
|
String[] lastBitOfURL = url.toExternalForm().split("/");
|
||||||
@@ -408,14 +415,11 @@ public abstract class AbstractRipper
|
|||||||
extension = lastBit[lastBit.length - 1];
|
extension = lastBit[lastBit.length - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if extension is passed or found, add it
|
||||||
if (fileName.indexOf('?') >= 0) { fileName = fileName.substring(0, fileName.indexOf('?')); }
|
|
||||||
if (fileName.indexOf('#') >= 0) { fileName = fileName.substring(0, fileName.indexOf('#')); }
|
|
||||||
if (fileName.indexOf('&') >= 0) { fileName = fileName.substring(0, fileName.indexOf('&')); }
|
|
||||||
if (fileName.indexOf(':') >= 0) { fileName = fileName.substring(0, fileName.indexOf(':')); }
|
|
||||||
if (extension != null) {
|
if (extension != null) {
|
||||||
fileName = fileName + "." + extension;
|
fileName = fileName + "." + extension;
|
||||||
}
|
}
|
||||||
|
// make sure filename is not too long and has no unsupported chars
|
||||||
return Utils.sanitizeSaveAs(fileName);
|
return Utils.sanitizeSaveAs(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user