[Android] Match subtitles with file name, not path
Geoffrey Métais
git at videolan.org
Wed May 25 17:24:19 CEST 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed May 25 11:50:27 2016 +0200| [470e289437e6bbe097f67b415294af33c0bbd5ce] | committer: Geoffrey Métais
Match subtitles with file name, not path
> https://code.videolan.org/videolan/vlc-android/commit/470e289437e6bbe097f67b415294af33c0bbd5ce
---
.../vlc/gui/video/VideoPlayerActivity.java | 2 +-
.../src/org/videolan/vlc/media/MediaDatabase.java | 24 +++++++++++-----------
.../org/videolan/vlc/util/SubtitlesDownloader.java | 5 +++--
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 8dd9972..7061cca 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2974,7 +2974,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
catch (StreamCorruptedException e) {}
catch (IOException e) {}
}
- prefsList.addAll(MediaDatabase.getInstance().getSubtitles(mUri.getPath()));
+ prefsList.addAll(MediaDatabase.getInstance().getSubtitles(mUri.getLastPathSegment()));
for(String x : prefsList){
if(!mSubtitleSelectedFiles.contains(x))
mSubtitleSelectedFiles.add(x);
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaDatabase.java b/vlc-android/src/org/videolan/vlc/media/MediaDatabase.java
index 7fb99c1..887de2b 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaDatabase.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaDatabase.java
@@ -101,7 +101,7 @@ public class MediaDatabase {
private static final String MRL_TABLE_SIZE = "100";
private static final String EXTERNAL_SUBTITLES_TABLE_NAME = "external_subtitles_table";
- private static final String EXTERNAL_SUBTITLES_MEDIA_URI = "media_uri";
+ private static final String EXTERNAL_SUBTITLES_MEDIA_NAME = "media_name";
private static final String EXTERNAL_SUBTITLES_URI = "uri";
private static final String HISTORY_TABLE_NAME = "history_table";
@@ -345,7 +345,7 @@ public class MediaDatabase {
String createMrlTableQuery = "CREATE TABLE IF NOT EXISTS " +
EXTERNAL_SUBTITLES_TABLE_NAME + " (" +
EXTERNAL_SUBTITLES_URI + " TEXT PRIMARY KEY NOT NULL, " +
- EXTERNAL_SUBTITLES_MEDIA_URI + " TEXT NOT NULL" +
+ EXTERNAL_SUBTITLES_MEDIA_NAME + " TEXT NOT NULL" +
");";
db.execSQL(createMrlTableQuery);
}
@@ -1285,18 +1285,18 @@ public class MediaDatabase {
* External subtitles management
*/
- public synchronized void saveSubtitle(String path, String mediaPath) {
+ public synchronized void saveSubtitle(String path, String mediaName) {
ContentValues values = new ContentValues();
values.put(EXTERNAL_SUBTITLES_URI, path);
- values.put(EXTERNAL_SUBTITLES_MEDIA_URI, mediaPath);
+ values.put(EXTERNAL_SUBTITLES_MEDIA_NAME, mediaName);
mDb.replace(EXTERNAL_SUBTITLES_TABLE_NAME, null, values);
}
- public synchronized ArrayList<String> getSubtitles(String mediaPath) {
+ public synchronized ArrayList<String> getSubtitles(String mediaName) {
Cursor cursor = mDb.query(EXTERNAL_SUBTITLES_TABLE_NAME,
- new String[] { EXTERNAL_SUBTITLES_MEDIA_URI, EXTERNAL_SUBTITLES_URI },
- EXTERNAL_SUBTITLES_MEDIA_URI + "=?",
- new String[] { mediaPath },
+ new String[] {EXTERNAL_SUBTITLES_MEDIA_NAME, EXTERNAL_SUBTITLES_URI },
+ EXTERNAL_SUBTITLES_MEDIA_NAME + "=?",
+ new String[] { mediaName },
null, null, null);
ArrayList<String> list = new ArrayList<>(cursor.getCount());
if (cursor != null) {
@@ -1305,9 +1305,9 @@ public class MediaDatabase {
if (!TextUtils.isEmpty(url)) {
String fileUrl = Uri.decode(url);
if (new File(fileUrl).exists())
- list.add(Uri.decode(url));
+ list.add(fileUrl);
else
- deleteSubtitle(Uri.parse(url));
+ deleteSubtitle(url);
}
}
cursor.close();
@@ -1315,8 +1315,8 @@ public class MediaDatabase {
return list;
}
- public synchronized void deleteSubtitle(Uri uri) {
- mDb.delete(EXTERNAL_SUBTITLES_TABLE_NAME, EXTERNAL_SUBTITLES_URI + "=?", new String[] { uri.toString() });
+ public synchronized void deleteSubtitle(String path) {
+ mDb.delete(EXTERNAL_SUBTITLES_TABLE_NAME, EXTERNAL_SUBTITLES_URI + "=?", new String[] { path });
}
public synchronized void clearExternalSubtitlesTable() {
diff --git a/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java b/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
index aac7c0d..e3b0d80 100644
--- a/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
+++ b/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
@@ -310,11 +310,12 @@ public class SubtitlesDownloader {
logOut();
}
- private void downloadSubtitles(String subUrl, String path, String name, String subFormat, String language){
+ private void downloadSubtitles(String subUrl, String path, String fileName, String subFormat, String language){
if (mToken == null || path == null)
return;
StringBuilder sb = new StringBuilder();
+ String name = fileName.lastIndexOf('.') > 0 ? fileName.substring(0, fileName.lastIndexOf('.')) : fileName;
sb.append(FileUtils.SUBTITLES_DIRECTORY.getPath()).append('/').append(name).append('.').append(language).append('.').append(subFormat);
String srtUrl = sb.toString();
FileOutputStream f = null;
@@ -334,7 +335,7 @@ public class SubtitlesDownloader {
while ((length = gzIS.read(buffer)) != -1) {
f.write(buffer, 0, length);
}
- MediaDatabase.getInstance().saveSubtitle(srtUrl, path);
+ MediaDatabase.getInstance().saveSubtitle(srtUrl, fileName);
} catch (IOException e) {
if (BuildConfig.DEBUG) Log.e(TAG, "download fail", e);
} catch (Throwable e) { //for various service outages
More information about the Android
mailing list