mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-07-27 14:23:04 +00:00
App does not crash now. Function not working. Will re-write.
This commit is contained in:
parent
758d84a87f
commit
4a96735bf8
@ -129,7 +129,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
|||||||
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);
|
remotePlaylistManager, localPlaylistManager, disposables);
|
||||||
parser.importBookmarks(activity);
|
parser.importBookmarks(activity);
|
||||||
System.out.println(parser);
|
System.out.println(parser);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
package org.schabi.newpipe.local.bookmark;
|
package org.schabi.newpipe.local.bookmark;
|
||||||
|
|
||||||
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
|
|
||||||
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.database.stream.model.StreamEntity;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
|
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.util.ExtractorHelper;
|
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;
|
||||||
@ -20,21 +24,24 @@ import java.io.InputStreamReader;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.reactivex.rxjava3.core.Single;
|
import io.reactivex.rxjava3.core.Single;
|
||||||
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class BookmarkImportService {
|
public class BookmarkImportService {
|
||||||
private Uri textFileUri;
|
private Uri textFileUri;
|
||||||
private RemotePlaylistManager remotePlaylistManager;
|
private RemotePlaylistManager remotePlaylistManager;
|
||||||
private LocalPlaylistManager localPlaylistManager;
|
private LocalPlaylistManager localPlaylistManager;
|
||||||
private StreamingService streamingService;
|
|
||||||
private Single<StreamInfo> streamInfoSingle;
|
private CompositeDisposable disposable;
|
||||||
private StreamInfo streamInfo;
|
|
||||||
List<StreamEntity> streams;
|
List<StreamEntity> streams;
|
||||||
public BookmarkImportService(final Uri textFileUri,
|
public BookmarkImportService(final Uri textFileUri,
|
||||||
final RemotePlaylistManager remotePlaylistManager,
|
final RemotePlaylistManager remotePlaylistManager,
|
||||||
final LocalPlaylistManager localPlaylistManager) {
|
final LocalPlaylistManager localPlaylistManager,
|
||||||
|
final CompositeDisposable compositeDisposable) {
|
||||||
this.textFileUri = textFileUri;
|
this.textFileUri = textFileUri;
|
||||||
this.remotePlaylistManager = remotePlaylistManager;
|
this.remotePlaylistManager = remotePlaylistManager;
|
||||||
this.localPlaylistManager = localPlaylistManager;
|
this.localPlaylistManager = localPlaylistManager;
|
||||||
|
this.disposable = compositeDisposable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importBookmarks(final Activity activity) {
|
public void importBookmarks(final Activity activity) {
|
||||||
@ -52,11 +59,11 @@ public class BookmarkImportService {
|
|||||||
String line;
|
String line;
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
|
Toast.makeText(activity, handleUrl(line), LENGTH_SHORT).show();
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
//cannot create an empty playlist
|
//cannot create an empty playlist
|
||||||
createNewPlayListWithOneEntry();
|
createNewPlayListWithOneEntry();
|
||||||
count++;
|
count++;
|
||||||
getStreamEntity(line);
|
|
||||||
} else {
|
} else {
|
||||||
addEntries();
|
addEntries();
|
||||||
}
|
}
|
||||||
@ -75,37 +82,30 @@ public class BookmarkImportService {
|
|||||||
public void addEntries() {
|
public void addEntries() {
|
||||||
System.out.println("LOL");
|
System.out.println("LOL");
|
||||||
}
|
}
|
||||||
public void getStreamEntity(final String url) {
|
public String handleUrl(final String url) {
|
||||||
|
final StreamingService service;
|
||||||
|
final StreamingService.LinkType linkType;
|
||||||
try {
|
try {
|
||||||
streamingService = NewPipe.getServiceByUrl(url);
|
service = NewPipe.getServiceByUrl(url);
|
||||||
|
linkType = service.getLinkTypeByUrl(url);
|
||||||
streamInfoSingle =
|
if (linkType == StreamingService.LinkType.STREAM) {
|
||||||
ExtractorHelper.getStreamInfo(streamingService.getServiceId(),
|
final LinkHandlerFactory factory = service.getStreamLHFactory();
|
||||||
url, true);
|
final String cleanUrl;
|
||||||
convertToStreamEntity(streamInfoSingle);
|
try {
|
||||||
|
cleanUrl = factory.getUrl(factory.getId(url));
|
||||||
|
} catch (final ParsingException e) {
|
||||||
|
return "parsingException";
|
||||||
|
}
|
||||||
|
final Single<StreamInfo> single =
|
||||||
|
ExtractorHelper.getStreamInfo(service.getServiceId(), cleanUrl, false);
|
||||||
|
if (single == null) {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
return "not null";
|
||||||
|
}
|
||||||
} catch (final ExtractionException e) {
|
} catch (final ExtractionException e) {
|
||||||
throw new RuntimeException(e);
|
return "false1";
|
||||||
}
|
}
|
||||||
}
|
return "false2";
|
||||||
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