mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-07-07 12:32:59 +00:00
App Crashes
This commit is contained in:
parent
b7d34ea25d
commit
758d84a87f
@ -41,7 +41,6 @@ import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
|
|||||||
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
|
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
|
||||||
import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard;
|
import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard;
|
||||||
import org.schabi.newpipe.streams.io.StoredFileHelper;
|
import org.schabi.newpipe.streams.io.StoredFileHelper;
|
||||||
import org.schabi.newpipe.util.Constants;
|
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.OnClickGesture;
|
import org.schabi.newpipe.util.OnClickGesture;
|
||||||
|
|
||||||
@ -58,8 +57,6 @@ import io.reactivex.rxjava3.disposables.Disposable;
|
|||||||
public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistLocalItem>, Void> {
|
public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistLocalItem>, Void> {
|
||||||
@State
|
@State
|
||||||
protected Parcelable itemsListState;
|
protected Parcelable itemsListState;
|
||||||
@State
|
|
||||||
int currentServiceId = Constants.NO_SERVICE_ID;
|
|
||||||
|
|
||||||
private Subscription databaseSubscription;
|
private Subscription databaseSubscription;
|
||||||
private CompositeDisposable disposables = new CompositeDisposable();
|
private CompositeDisposable disposables = new CompositeDisposable();
|
||||||
@ -131,7 +128,8 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
|||||||
// Check if the selected file is a text file
|
// Check if the selected file is a text file
|
||||||
if (mimeType != null && mimeType.equals("text/plain")) {
|
if (mimeType != null && mimeType.equals("text/plain")) {
|
||||||
|
|
||||||
final BookmarkImportService parser = new BookmarkImportService(uri);
|
final BookmarkImportService parser = new BookmarkImportService(uri,
|
||||||
|
remotePlaylistManager, localPlaylistManager);
|
||||||
parser.importBookmarks(activity);
|
parser.importBookmarks(activity);
|
||||||
System.out.println(parser);
|
System.out.println(parser);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,41 +2,110 @@ package org.schabi.newpipe.local.bookmark;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.widget.Toast;
|
|
||||||
|
import org.schabi.newpipe.database.stream.model.StreamEntity;
|
||||||
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
|
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
|
||||||
|
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
|
||||||
|
import org.schabi.newpipe.util.ExtractorHelper;
|
||||||
|
import org.schabi.newpipe.util.image.ImageStrategy;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.reactivex.rxjava3.core.Single;
|
||||||
|
|
||||||
public class BookmarkImportService {
|
public class BookmarkImportService {
|
||||||
private Uri textFileUri;
|
private Uri textFileUri;
|
||||||
|
private RemotePlaylistManager remotePlaylistManager;
|
||||||
public BookmarkImportService(final Uri textFileUri) {
|
private LocalPlaylistManager localPlaylistManager;
|
||||||
|
private StreamingService streamingService;
|
||||||
|
private Single<StreamInfo> streamInfoSingle;
|
||||||
|
private StreamInfo streamInfo;
|
||||||
|
List<StreamEntity> streams;
|
||||||
|
public BookmarkImportService(final Uri textFileUri,
|
||||||
|
final RemotePlaylistManager remotePlaylistManager,
|
||||||
|
final LocalPlaylistManager localPlaylistManager) {
|
||||||
this.textFileUri = textFileUri;
|
this.textFileUri = textFileUri;
|
||||||
|
this.remotePlaylistManager = remotePlaylistManager;
|
||||||
|
this.localPlaylistManager = localPlaylistManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importBookmarks(final Activity activity) {
|
public void importBookmarks(final Activity activity) {
|
||||||
|
readTextFile(activity);
|
||||||
|
}
|
||||||
|
public void readTextFile(final Activity activity) {
|
||||||
|
int count = 0;
|
||||||
if (textFileUri != null) {
|
if (textFileUri != null) {
|
||||||
try {
|
try {
|
||||||
final InputStream inputStream =
|
final InputStream inputStream =
|
||||||
activity.getContentResolver().openInputStream(textFileUri);
|
activity.getContentResolver().openInputStream(textFileUri);
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
final BufferedReader reader =
|
final BufferedReader reader =
|
||||||
new BufferedReader(new InputStreamReader(inputStream));
|
new BufferedReader(new InputStreamReader(inputStream));
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
Toast.makeText(activity, line, Toast.LENGTH_SHORT).show();
|
if (count == 0) {
|
||||||
|
//cannot create an empty playlist
|
||||||
|
createNewPlayListWithOneEntry();
|
||||||
|
count++;
|
||||||
|
getStreamEntity(line);
|
||||||
|
} else {
|
||||||
|
addEntries();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
inputStream.close();
|
||||||
}
|
}
|
||||||
|
} catch (final IOException e) {
|
||||||
reader.close();
|
throw new RuntimeException(e);
|
||||||
inputStream.close();
|
|
||||||
}
|
}
|
||||||
} catch (final IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void createNewPlayListWithOneEntry() {
|
||||||
|
System.out.println("LOL");
|
||||||
|
}
|
||||||
|
public void addEntries() {
|
||||||
|
System.out.println("LOL");
|
||||||
|
}
|
||||||
|
public void getStreamEntity(final String url) {
|
||||||
|
try {
|
||||||
|
streamingService = NewPipe.getServiceByUrl(url);
|
||||||
|
|
||||||
|
streamInfoSingle =
|
||||||
|
ExtractorHelper.getStreamInfo(streamingService.getServiceId(),
|
||||||
|
url, true);
|
||||||
|
convertToStreamEntity(streamInfoSingle);
|
||||||
|
} catch (final ExtractionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void convertToStreamEntity(final Single<StreamInfo> singleStreamInfo) {
|
||||||
|
streamInfo = singleStreamInfo.blockingGet();
|
||||||
|
final StreamEntity streamEntity = new StreamEntity(
|
||||||
|
Long.parseLong(streamInfo.getId()),
|
||||||
|
streamInfo.getServiceId(),
|
||||||
|
streamInfo.getUrl(),
|
||||||
|
streamInfo.getName(),
|
||||||
|
streamInfo.getStreamType(),
|
||||||
|
streamInfo.getDuration(),
|
||||||
|
streamInfo.getUploaderName(),
|
||||||
|
streamInfo.getUploaderUrl(),
|
||||||
|
ImageStrategy.imageListToDbUrl(streamInfo.getThumbnails()),
|
||||||
|
streamInfo.getViewCount(),
|
||||||
|
streamInfo.getTextualUploadDate(),
|
||||||
|
streamInfo.getUploadDate() != null
|
||||||
|
? streamInfo.getUploadDate().offsetDateTime() : null,
|
||||||
|
streamInfo.getUploadDate() != null
|
||||||
|
? streamInfo.getUploadDate().isApproximation() : null
|
||||||
|
);
|
||||||
|
streams.add(streamEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user