Commit d5f55e56 authored by Thomas Guillem's avatar Thomas Guillem
Browse files

libvlc: move ext regex and folder blacklist outside libvlc

parent b84c8e38
......@@ -32,11 +32,9 @@ public class Media implements Comparable<Media> {
public final static HashSet<String> VIDEO_EXTENSIONS;
public final static HashSet<String> AUDIO_EXTENSIONS;
public final static String EXTENSIONS_REGEX;
public final static HashSet<String> FOLDER_BLACKLIST;
static {
String[] video_extensions = {
final String[] video_extensions = {
".3g2", ".3gp", ".3gp2", ".3gpp", ".amv", ".asf", ".avi", ".divx", ".drc", ".dv",
".f4v", ".flv", ".gvi", ".gxf", ".ismv", ".iso", ".m1v", ".m2v", ".m2t", ".m2ts",
".m4v", ".mkv", ".mov", ".mp2", ".mp2v", ".mp4", ".mp4v", ".mpe", ".mpeg",
......@@ -44,48 +42,19 @@ public class Media implements Comparable<Media> {
".nsv", ".nut", ".nuv", ".ogm", ".ogv", ".ogx", ".ps", ".rec", ".rm", ".rmvb",
".tod", ".ts", ".tts", ".vob", ".vro", ".webm", ".wm", ".wmv", ".wtv", ".xesc" };
String[] audio_extensions = {
final String[] audio_extensions = {
".3ga", ".a52", ".aac", ".ac3", ".adt", ".adts", ".aif", ".aifc", ".aiff", ".amr",
".aob", ".ape", ".awb", ".caf", ".dts", ".flac", ".it", ".m4a", ".m4b", ".m4p",
".mid", ".mka", ".mlp", ".mod", ".mpa", ".mp1", ".mp2", ".mp3", ".mpc", ".mpga",
".oga", ".ogg", ".oma", ".opus", ".ra", ".ram", ".rmi", ".s3m", ".spx", ".tta",
".voc", ".vqf", ".w64", ".wav", ".wma", ".wv", ".xa", ".xm" };
String[] folder_blacklist = {
"/alarms",
"/notifications",
"/ringtones",
"/media/alarms",
"/media/notifications",
"/media/ringtones",
"/media/audio/alarms",
"/media/audio/notifications",
"/media/audio/ringtones",
"/Android/data/" };
VIDEO_EXTENSIONS = new HashSet<String>();
for (String item : video_extensions)
VIDEO_EXTENSIONS.add(item);
AUDIO_EXTENSIONS = new HashSet<String>();
for (String item : audio_extensions)
AUDIO_EXTENSIONS.add(item);
StringBuilder sb = new StringBuilder(115);
sb.append(".+(\\.)((?i)(");
sb.append(video_extensions[0].substring(1));
for(int i = 1; i < video_extensions.length; i++) {
sb.append('|');
sb.append(video_extensions[i].substring(1));
}
for(int i = 0; i < audio_extensions.length; i++) {
sb.append('|');
sb.append(audio_extensions[i].substring(1));
}
sb.append("))");
EXTENSIONS_REGEX = sb.toString();
FOLDER_BLACKLIST = new HashSet<String>();
for (String item : folder_blacklist)
FOLDER_BLACKLIST.add(android.os.Environment.getExternalStorageDirectory().getPath() + item);
}
public final static int TYPE_ALL = -1;
......
......@@ -61,6 +61,25 @@ public class MediaLibrary {
private boolean mRestart = false;
protected Thread mLoadingThread;
public final static HashSet<String> FOLDER_BLACKLIST;
static {
final String[] folder_blacklist = {
"/alarms",
"/notifications",
"/ringtones",
"/media/alarms",
"/media/notifications",
"/media/ringtones",
"/media/audio/alarms",
"/media/audio/notifications",
"/media/audio/ringtones",
"/Android/data/" };
FOLDER_BLACKLIST = new HashSet<String>();
for (String item : folder_blacklist)
FOLDER_BLACKLIST.add(android.os.Environment.getExternalStorageDirectory().getPath() + item);
}
private MediaLibrary() {
mInstance = this;
mItemList = new ArrayList<Media>();
......@@ -370,7 +389,7 @@ public class MediaLibrary {
public boolean accept(File f) {
boolean accepted = false;
if (!f.isHidden()) {
if (f.isDirectory() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH))) {
if (f.isDirectory() && !FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH))) {
accepted = true;
} else {
String fileName = f.getName().toLowerCase(Locale.ENGLISH);
......
......@@ -27,8 +27,8 @@ import java.util.Arrays;
import java.util.Locale;
import java.util.Stack;
import org.videolan.libvlc.Media;
import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.CustomDirectories;
......@@ -284,7 +284,7 @@ public class BrowserActivity extends ListActivity {
@Override
public boolean accept(File f) {
return f.isDirectory() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH));
return f.isDirectory() && !MediaLibrary.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH));
}
}
......
......@@ -56,7 +56,23 @@ public class DirectoryAdapter extends BaseAdapter {
private ContextPopupMenuListener mContextPopupMenuListener;
public static boolean acceptedPath(String f) {
return Pattern.compile(Media.EXTENSIONS_REGEX, Pattern.CASE_INSENSITIVE).matcher(f).matches();
final StringBuilder sb = new StringBuilder();
sb.append(".+(\\.)((?i)(");
boolean first = true;
for (String ext : Media.VIDEO_EXTENSIONS) {
if (!first)
sb.append('|');
else
first = false;
sb.append(ext.substring(1));
}
for (String ext : Media.AUDIO_EXTENSIONS) {
sb.append('|');
sb.append(ext.substring(1));
}
sb.append("))");
return Pattern.compile(sb.toString(), Pattern.CASE_INSENSITIVE).matcher(f).matches();
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment