Skip to content

Commit f8f2dfc

Browse files
authored
Merge pull request #6882 from talanc/dev
Add support for CSV+ZIP subscriptions (Google Takeout)
2 parents 15691ba + 5284072 commit f8f2dfc

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ dependencies {
184184
// name and the commit hash with the commit hash of the (pushed) commit you want to test
185185
// This works thanks to JitPack: https://jitpack.io/
186186
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
187-
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.21.9'
187+
implementation 'com.github.TeamNewPipe:NewPipeExtractor:68f1fa994af78d2cd0f354f9226d5dbe3dc03d54'
188188

189189
/** Checkstyle **/
190190
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"

app/src/main/java/org/schabi/newpipe/local/subscription/services/SubscriptionsImportService.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
package org.schabi.newpipe.local.subscription.services;
2121

22+
import static org.schabi.newpipe.MainActivity.DEBUG;
23+
import static org.schabi.newpipe.streams.io.StoredFileHelper.DEFAULT_MIME;
24+
2225
import android.content.Intent;
2326
import android.net.Uri;
2427
import android.text.TextUtils;
@@ -46,6 +49,7 @@
4649
import java.io.InputStream;
4750
import java.util.ArrayList;
4851
import java.util.List;
52+
import java.util.Objects;
4953

5054
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
5155
import io.reactivex.rxjava3.core.Flowable;
@@ -54,9 +58,6 @@
5458
import io.reactivex.rxjava3.functions.Function;
5559
import io.reactivex.rxjava3.schedulers.Schedulers;
5660

57-
import static org.schabi.newpipe.MainActivity.DEBUG;
58-
import static org.schabi.newpipe.streams.io.StoredFileHelper.DEFAULT_MIME;
59-
6061
public class SubscriptionsImportService extends BaseImportExportService {
6162
public static final int CHANNEL_URL_MODE = 0;
6263
public static final int INPUT_STREAM_MODE = 1;
@@ -89,6 +90,8 @@ public class SubscriptionsImportService extends BaseImportExportService {
8990
private String channelUrl;
9091
@Nullable
9192
private InputStream inputStream;
93+
@Nullable
94+
private String inputStreamType;
9295

9396
@Override
9497
public int onStartCommand(final Intent intent, final int flags, final int startId) {
@@ -111,8 +114,20 @@ public int onStartCommand(final Intent intent, final int flags, final int startI
111114
}
112115

113116
try {
114-
inputStream = new SharpInputStream(
115-
new StoredFileHelper(this, uri, DEFAULT_MIME).getStream());
117+
final StoredFileHelper fileHelper = new StoredFileHelper(this, uri, DEFAULT_MIME);
118+
inputStream = new SharpInputStream(fileHelper.getStream());
119+
inputStreamType = fileHelper.getType();
120+
121+
if (inputStreamType == null || inputStreamType.equals(DEFAULT_MIME)) {
122+
// mime type could not be determined, just take file extension
123+
final String name = fileHelper.getName();
124+
final int pointIndex = name.lastIndexOf('.');
125+
if (pointIndex == -1 || pointIndex >= name.length() - 1) {
126+
inputStreamType = DEFAULT_MIME; // no extension, will fail in the extractor
127+
} else {
128+
inputStreamType = name.substring(pointIndex + 1);
129+
}
130+
}
116131
} catch (final IOException e) {
117132
handleError(e);
118133
return START_NOT_STICKY;
@@ -248,9 +263,9 @@ private Consumer<Notification<ChannelInfo>> getNotificationsConsumer() {
248263
final Throwable error = notification.getError();
249264
final Throwable cause = error.getCause();
250265
if (error instanceof IOException) {
251-
throw (IOException) error;
266+
throw error;
252267
} else if (cause instanceof IOException) {
253-
throw (IOException) cause;
268+
throw cause;
254269
} else if (ExceptionUtils.isNetworkRelated(error)) {
255270
throw new IOException(error);
256271
}
@@ -280,9 +295,12 @@ private Flowable<List<SubscriptionItem>> importFromChannelUrl() {
280295
}
281296

282297
private Flowable<List<SubscriptionItem>> importFromInputStream() {
298+
Objects.requireNonNull(inputStream);
299+
Objects.requireNonNull(inputStreamType);
300+
283301
return Flowable.fromCallable(() -> NewPipe.getService(currentServiceId)
284302
.getSubscriptionExtractor()
285-
.fromInputStream(inputStream));
303+
.fromInputStream(inputStream, inputStreamType));
286304
}
287305

288306
private Flowable<List<SubscriptionItem>> importFromPreviousExport() {

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@
542542
<string name="previous_export">Previous export</string>
543543
<string name="subscriptions_import_unsuccessful">Could not import subscriptions</string>
544544
<string name="subscriptions_export_unsuccessful">Could not export subscriptions</string>
545-
<string name="import_youtube_instructions">Import YouTube subscriptions from Google takeout:\n\n1. Go to this URL: %1$s\n2. Log in when asked\n3. Click on \"All data included\", then on \"Deselect all\", then select only \"subscriptions\" and click \"OK\"\n4. Click on \"Next step\" and then on \"Create export\"\n5. Click on the \"Download\" button after it appears and \n6. From the downloaded takeout zip extract the .json file (usually under \"YouTube and YouTube Music/subscriptions/subscriptions.json\") and import it here.</string>
545+
<string name="import_youtube_instructions">Import YouTube subscriptions from Google takeout:\n\n1. Go to this URL: %1$s\n2. Log in when asked\n3. Click on \"All data included\", then on \"Deselect all\", then select only \"subscriptions\" and click \"OK\"\n4. Click on \"Next step\" and then on \"Create export\"\n5. Click on the \"Download\" button after it appears\n6. Click on IMPORT FILE below and select the downloaded zip file\n7. [If the zip import fails] Extract the .csv file (usually under \"YouTube and YouTube Music/subscriptions/subscriptions.csv\"), click on IMPORT FILE below and select the extracted csv file</string>
546546
<string name="import_soundcloud_instructions">Import a SoundCloud profile by typing either the URL or your ID:\n\n1. Enable \"desktop mode\" in a web-browser (the site is not available for mobile devices)\n2. Go to this URL: %1$s\n3. Log in when asked\n4. Copy the profile URL you were redirected to.</string>
547547
<string name="import_soundcloud_instructions_hint">yourID, soundcloud.com/yourid</string>
548548
<string name="import_network_expensive_warning">Keep in mind this operation can be network expensive.\n\nDo you want to continue?</string>

0 commit comments

Comments
 (0)