Search in sources :

Example 1 with FileSystem

use of com.frostwire.platform.FileSystem in project frostwire by frostwire.

the class MusicUtils method deleteTracks.

/**
 * Permanently deletes item(s) from the user's device.
 *
 * @param context The {@link Context} to use.
 * @param list    The item(s) to delete.
 */
public static void deleteTracks(final Context context, final long[] list, boolean showNotification) {
    if (list == null) {
        return;
    }
    final String[] projection = new String[] { BaseColumns._ID, MediaColumns.DATA, AudioColumns.ALBUM_ID };
    final StringBuilder selection = new StringBuilder();
    selection.append(BaseColumns._ID + " IN (");
    for (int i = 0; i < list.length; i++) {
        selection.append(list[i]);
        if (i < list.length - 1) {
            selection.append(",");
        }
    }
    selection.append(")");
    final Cursor c = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection.toString(), null, null);
    if (c != null) {
        // Step 1: Remove selected tracks from the current playlist, as well
        // as from the album art cache
        c.moveToFirst();
        while (!c.isAfterLast()) {
            // Remove from current playlist.
            final long id = c.getLong(0);
            removeTrack(id);
            // Remove from the favorites playlist.
            FavoritesStore.getInstance(context).removeItem(id);
            // Remove any items in the recent's database
            RecentStore.getInstance(context).removeItem(id);
            // Remove from all remaining playlists.
            removeSongFromAllPlaylists(context, id);
            c.moveToNext();
        }
        // Step 2: Remove selected tracks from the database
        context.getContentResolver().delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, selection.toString(), null);
        // Step 3: Remove files from card
        FileSystem fs = Platforms.fileSystem();
        c.moveToFirst();
        while (!c.isAfterLast()) {
            final String name = c.getString(1);
            try {
                // File.delete can throw a security exception
                final File f = new File(name);
                if (!fs.delete(f)) {
                    // I'm not sure if we'd ever get here (deletion would
                    // have to fail, but no exception thrown)
                    Log.e("MusicUtils", "Failed to delete file " + name);
                }
                c.moveToNext();
            } catch (final Throwable ex) {
                c.moveToNext();
            }
        }
        c.close();
        UIUtils.broadcastAction(context, Constants.ACTION_FILE_ADDED_OR_REMOVED, new UIUtils.IntentByteExtra(Constants.EXTRA_REFRESH_FILE_TYPE, Constants.FILE_TYPE_AUDIO));
    }
    if (showNotification) {
        try {
            final String message = makeLabel(context, R.plurals.NNNtracksdeleted, list.length);
            AppMsg.makeText(context, message, AppMsg.STYLE_CONFIRM).show();
        } catch (Throwable ignored) {
        }
    }
    // We deleted a number of tracks, which could affect any number of
    // things
    // in the media content domain, so update everything.
    context.getContentResolver().notifyChange(Uri.parse("content://media"), null);
    // Notify the lists to update
    refresh();
}
Also used : FileSystem(com.frostwire.platform.FileSystem) UIUtils(com.frostwire.android.gui.util.UIUtils) Cursor(android.database.Cursor) File(java.io.File)

Example 2 with FileSystem

use of com.frostwire.platform.FileSystem in project frostwire by frostwire.

the class AndroidPlatform method buildFileSystem.

private static FileSystem buildFileSystem(Application app) {
    FileSystem fs;
    if (Build.VERSION.SDK_INT >= VERSION_CODE_LOLLIPOP) {
        LollipopFileSystem lfs = new LollipopFileSystem(app);
        PosixCalls w = new PosixCalls(lfs);
        w.swigReleaseOwnership();
        libtorrent.set_posix_wrapper(w);
        // LibTorrent.setPosixWrapper(new PosixCalls(lfs));
        fs = lfs;
    } else {
        fs = new DefaultFileSystem() {

            @Override
            public void scan(File file) {
                Librarian.instance().scan(app, file);
            }
        };
    }
    return fs;
}
Also used : DefaultFileSystem(com.frostwire.platform.DefaultFileSystem) FileSystem(com.frostwire.platform.FileSystem) File(java.io.File) DocumentFile(android.support.v4.provider.DocumentFile) DefaultFileSystem(com.frostwire.platform.DefaultFileSystem)

Example 3 with FileSystem

use of com.frostwire.platform.FileSystem in project frostwire by frostwire.

the class BaseHttpDownload method remove.

@Override
public void remove(boolean deleteData) {
    if (complete) {
        return;
    }
    complete(state = TransferState.CANCELED);
    FileSystem fs = Platforms.fileSystem();
    if (fs.delete(tempPath)) {
        LOG.warn("Error deleting temporary file: " + tempPath);
    }
    if (deleteData) {
        if (fs.delete(savePath)) {
            LOG.warn("Error deleting download data file: " + savePath);
        }
    }
}
Also used : FileSystem(com.frostwire.platform.FileSystem)

Example 4 with FileSystem

use of com.frostwire.platform.FileSystem in project frostwire by frostwire.

the class YouTubeDownload method onHttpComplete.

@Override
protected void onHttpComplete() throws Throwable {
    boolean callSuper = true;
    if (downloadType == DownloadType.DASH) {
        FileSystem fs = Platforms.fileSystem();
        if (fs.exists(tempVideo) && !fs.exists(tempAudio)) {
            start(sr.getAudio().link, tempAudio, false);
            callSuper = false;
        }
    }
    if (callSuper) {
        super.onHttpComplete();
    }
}
Also used : FileSystem(com.frostwire.platform.FileSystem)

Example 5 with FileSystem

use of com.frostwire.platform.FileSystem in project frostwire by frostwire.

the class YouTubeDownload method onFinishing.

@Override
protected void onFinishing() throws Throwable {
    if (downloadType == DownloadType.VIDEO) {
        removeUdta(tempVideo);
        moveAndComplete(tempVideo, savePath);
    } else if (downloadType == DownloadType.DEMUX) {
        state = TransferState.DEMUXING;
        Mp4Demuxer.audio(tempAudio.getAbsoluteFile(), tempPath, buildMp4Info(true), readCount -> demuxerReadCount = readCount);
        moveAndComplete(tempPath, savePath);
        FileSystem fs = Platforms.fileSystem();
        if (!fs.delete(tempAudio)) {
            LOG.warn("Error deleting temporary audio file: " + tempAudio);
        }
    } else if (downloadType == DownloadType.DASH) {
        // intentionally not using FileSystem here
        if (tempVideo.exists() && tempAudio.exists()) {
            state = TransferState.DEMUXING;
            Mp4Demuxer.muxFragments(tempVideo.getAbsoluteFile(), tempAudio.getAbsoluteFile(), tempPath.getAbsoluteFile(), buildMp4Info(false), null);
            moveAndComplete(tempPath, savePath);
            FileSystem fs = Platforms.fileSystem();
            if (!fs.delete(tempVideo)) {
                LOG.warn("Error deleting temporary video file: " + tempVideo);
            }
            if (!fs.delete(tempAudio)) {
                LOG.warn("Error deleting temporary audio file: " + tempAudio);
            }
        } else {
            complete(TransferState.ERROR);
        }
    }
}
Also used : IsoFile(com.frostwire.mp4.IsoFile) RandomAccessFile(java.io.RandomAccessFile) YouTubeExtractor(com.frostwire.search.youtube.YouTubeExtractor) FileSystem(com.frostwire.platform.FileSystem) Logger(com.frostwire.util.Logger) IOException(java.io.IOException) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) IOUtils(org.apache.commons.io.IOUtils) Platforms(com.frostwire.platform.Platforms) Mp4Demuxer(com.frostwire.mp4.Mp4Demuxer) YouTubeCrawledSearchResult(com.frostwire.search.youtube.YouTubeCrawledSearchResult) Box(com.frostwire.mp4.Box) HttpClientFactory(com.frostwire.util.HttpClientFactory) FilenameUtils(org.apache.commons.io.FilenameUtils) Mp4Info(com.frostwire.mp4.Mp4Info) FileSystem(com.frostwire.platform.FileSystem)

Aggregations

FileSystem (com.frostwire.platform.FileSystem)9 File (java.io.File)6 UIUtils (com.frostwire.android.gui.util.UIUtils)2 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 DocumentFile (android.support.v4.provider.DocumentFile)1 FileDescriptor (com.frostwire.android.core.FileDescriptor)1 TableFetcher (com.frostwire.android.core.providers.TableFetcher)1 Box (com.frostwire.mp4.Box)1 IsoFile (com.frostwire.mp4.IsoFile)1 Mp4Demuxer (com.frostwire.mp4.Mp4Demuxer)1 Mp4Info (com.frostwire.mp4.Mp4Info)1 DefaultFileSystem (com.frostwire.platform.DefaultFileSystem)1 Platforms (com.frostwire.platform.Platforms)1 YouTubeCrawledSearchResult (com.frostwire.search.youtube.YouTubeCrawledSearchResult)1 YouTubeExtractor (com.frostwire.search.youtube.YouTubeExtractor)1 HttpClientFactory (com.frostwire.util.HttpClientFactory)1 Logger (com.frostwire.util.Logger)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1