Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Extractor and fix compile errors #21

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ dependencies {
/** NewPipe libraries **/
// You can use a local version by uncommenting a few lines in settings.gradle
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
implementation 'com.github.ShareASmile:NewPipeExtractor:v0.22.5.3'
implementation 'com.github.Jtfk:NewPipeExtractor-j8:0.22.7-j8'

/** Third-party libraries **/
// Instance state boilerplate elimination
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/org/schabi/newpipelegacy/error/ErrorInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import android.os.Parcelable
import androidx.annotation.StringRes
import kotlinx.android.parcel.Parcelize
import org.schabi.newpipe.extractor.Info
import org.schabi.newpipe.extractor.NewPipe
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException
import org.schabi.newpipe.extractor.exceptions.ExtractionException
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor.DeobfuscateException
import org.schabi.newpipelegacy.R
import org.schabi.newpipelegacy.ktx.isNetworkRelated
import org.schabi.newpipelegacy.util.ServiceHelper
import java.io.PrintWriter
import java.io.StringWriter

Expand Down Expand Up @@ -57,15 +57,15 @@ class ErrorInfo(
constructor(throwable: Throwable, userAction: UserAction, request: String) :
this(throwable, userAction, SERVICE_NONE, request)
constructor(throwable: Throwable, userAction: UserAction, request: String, serviceId: Int) :
this(throwable, userAction, NewPipe.getNameOfService(serviceId), request)
this(throwable, userAction, ServiceHelper.getNameOfServiceById(serviceId), request)
constructor(throwable: Throwable, userAction: UserAction, request: String, info: Info?) :
this(throwable, userAction, getInfoServiceName(info), request)

// constructors with list of throwables
constructor(throwable: List<Throwable>, userAction: UserAction, request: String) :
this(throwable, userAction, SERVICE_NONE, request)
constructor(throwable: List<Throwable>, userAction: UserAction, request: String, serviceId: Int) :
this(throwable, userAction, NewPipe.getNameOfService(serviceId), request)
this(throwable, userAction, ServiceHelper.getNameOfServiceById(serviceId), request)
constructor(throwable: List<Throwable>, userAction: UserAction, request: String, info: Info?) :
this(throwable, userAction, getInfoServiceName(info), request)

Expand All @@ -87,7 +87,7 @@ class ErrorInfo(
Array(throwable.size) { i -> getStackTrace(throwable[i]) }

private fun getInfoServiceName(info: Info?) =
if (info == null) SERVICE_NONE else NewPipe.getNameOfService(info.serviceId)
if (info == null) SERVICE_NONE else ServiceHelper.getNameOfServiceById(info.serviceId)

@StringRes
private fun getMessageStringId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public void updateFromItem(final InfoItem infoItem,
streamUrl = item.getUrl();

itemContentView.setLines(COMMENT_DEFAULT_LINES);
commentText = item.getCommentText();
//commentText = item.getCommentText();
commentText = item.getCommentText().getContent();
itemContentView.setText(commentText);
itemContentView.setOnTouchListener(CommentTextOnTouchListener.INSTANCE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import org.schabi.newpipelegacy.R;
import org.schabi.newpipelegacy.database.LocalItem;
import org.schabi.newpipelegacy.database.playlist.PlaylistStreamEntry;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipelegacy.ktx.ViewUtils;
import org.schabi.newpipelegacy.local.LocalItemBuilder;
import org.schabi.newpipelegacy.local.history.HistoryRecordManager;
import org.schabi.newpipelegacy.util.ImageDisplayConstants;
import org.schabi.newpipelegacy.util.Localization;
import org.schabi.newpipelegacy.util.ServiceHelper;
import org.schabi.newpipelegacy.views.AnimatedProgressBar;

import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -59,7 +59,7 @@ public void updateFromItem(final LocalItem localItem,
itemVideoTitleView.setText(item.getStreamEntity().getTitle());
itemAdditionalDetailsView.setText(Localization
.concatenateStrings(item.getStreamEntity().getUploader(),
NewPipe.getNameOfService(item.getStreamEntity().getServiceId())));
ServiceHelper.getNameOfServiceById(item.getStreamEntity().getServiceId())));

if (item.getStreamEntity().getDuration() > 0) {
itemDurationView.setText(Localization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import org.schabi.newpipelegacy.R;
import org.schabi.newpipelegacy.database.LocalItem;
import org.schabi.newpipelegacy.database.stream.StreamStatisticsEntry;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipelegacy.ktx.ViewUtils;
import org.schabi.newpipelegacy.local.LocalItemBuilder;
import org.schabi.newpipelegacy.local.history.HistoryRecordManager;
import org.schabi.newpipelegacy.util.ImageDisplayConstants;
import org.schabi.newpipelegacy.util.Localization;
import org.schabi.newpipelegacy.util.ServiceHelper;
import org.schabi.newpipelegacy.views.AnimatedProgressBar;

import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -70,11 +70,12 @@ public LocalStatisticStreamItemHolder(final LocalItemBuilder itemBuilder,

private String getStreamInfoDetailLine(final StreamStatisticsEntry entry,
final DateTimeFormatter dateTimeFormatter) {
final String watchCount = Localization
.shortViewCount(itemBuilder.getContext(), entry.getWatchCount());
final String uploadDate = dateTimeFormatter.format(entry.getLatestAccessDate());
final String serviceName = NewPipe.getNameOfService(entry.getStreamEntity().getServiceId());
return Localization.concatenateStrings(watchCount, uploadDate, serviceName);
return Localization.concatenateStrings(
// watchCount
Localization.shortViewCount(itemBuilder.getContext(), entry.getWatchCount()),
dateTimeFormatter.format(entry.getLatestAccessDate()),
// serviceName
ServiceHelper.getNameOfServiceById(entry.getStreamEntity().getServiceId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import org.schabi.newpipelegacy.database.LocalItem;
import org.schabi.newpipelegacy.database.playlist.model.PlaylistRemoteEntity;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipelegacy.local.LocalItemBuilder;
import org.schabi.newpipelegacy.local.history.HistoryRecordManager;
import org.schabi.newpipelegacy.util.ImageDisplayConstants;
import org.schabi.newpipelegacy.util.Localization;
import org.schabi.newpipelegacy.util.ServiceHelper;

import java.time.format.DateTimeFormatter;

Expand Down Expand Up @@ -39,9 +39,9 @@ public void updateFromItem(final LocalItem localItem,
// Here is where the uploader name is set in the bookmarked playlists library
if (!TextUtils.isEmpty(item.getUploader())) {
itemUploaderView.setText(Localization.concatenateStrings(item.getUploader(),
NewPipe.getNameOfService(item.getServiceId())));
ServiceHelper.getNameOfServiceById(item.getServiceId())));
} else {
itemUploaderView.setText(NewPipe.getNameOfService(item.getServiceId()));
itemUploaderView.setText(ServiceHelper.getNameOfServiceById(item.getServiceId()));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package org.schabi.newpipelegacy.local.subscription;

import static org.schabi.newpipe.extractor.subscription.SubscriptionExtractor.ContentSource.CHANNEL_URL;
import static org.schabi.newpipelegacy.local.subscription.services.SubscriptionsImportService.CHANNEL_URL_MODE;
import static org.schabi.newpipelegacy.local.subscription.services.SubscriptionsImportService.INPUT_STREAM_MODE;
import static org.schabi.newpipelegacy.local.subscription.services.SubscriptionsImportService.KEY_MODE;
import static org.schabi.newpipelegacy.local.subscription.services.SubscriptionsImportService.KEY_VALUE;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
Expand Down Expand Up @@ -38,12 +44,6 @@

import icepick.State;

import static org.schabi.newpipe.extractor.subscription.SubscriptionExtractor.ContentSource.CHANNEL_URL;
import static org.schabi.newpipelegacy.local.subscription.services.SubscriptionsImportService.CHANNEL_URL_MODE;
import static org.schabi.newpipelegacy.local.subscription.services.SubscriptionsImportService.INPUT_STREAM_MODE;
import static org.schabi.newpipelegacy.local.subscription.services.SubscriptionsImportService.KEY_MODE;
import static org.schabi.newpipelegacy.local.subscription.services.SubscriptionsImportService.KEY_VALUE;

public class SubscriptionsImportFragment extends BaseFragment {
private static final int REQUEST_IMPORT_FILE_CODE = 666;

Expand Down Expand Up @@ -86,7 +86,7 @@ public void onCreate(final Bundle savedInstanceState) {
if (supportedSources.isEmpty() && currentServiceId != Constants.NO_SERVICE_ID) {
ErrorActivity.reportErrorInSnackbar(activity,
new ErrorInfo(new String[]{}, UserAction.SUBSCRIPTION_IMPORT_EXPORT,
NewPipe.getNameOfService(currentServiceId),
ServiceHelper.getNameOfServiceById(currentServiceId),
"Service does not support importing subscriptions",
R.string.general_error,
null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import com.nostra13.universalimageloader.core.ImageLoader;

import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipelegacy.util.ImageDisplayConstants;
import org.schabi.newpipelegacy.util.Localization;
import org.schabi.newpipelegacy.util.ServiceHelper;

public class PlayQueueItemBuilder {
private static final String TAG = PlayQueueItemBuilder.class.toString();
Expand All @@ -27,7 +27,7 @@ public void buildStreamInfoItem(final PlayQueueItemHolder holder, final PlayQueu
holder.itemVideoTitleView.setText(item.getTitle());
}
holder.itemAdditionalDetailsView.setText(Localization.concatenateStrings(item.getUploader(),
NewPipe.getNameOfService(item.getServiceId())));
ServiceHelper.getNameOfServiceById(item.getServiceId())));

if (item.getDuration() > 0) {
holder.itemDurationView.setText(Localization.getDurationString(item.getDuration()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.schabi.newpipelegacy.settings.tabs;

import static org.schabi.newpipelegacy.settings.tabs.Tab.typeFrom;
import static org.schabi.newpipelegacy.util.ServiceHelper.getNameOfServiceById;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
Expand Down Expand Up @@ -30,7 +33,6 @@
import org.schabi.newpipelegacy.error.ErrorActivity;
import org.schabi.newpipelegacy.error.ErrorInfo;
import org.schabi.newpipelegacy.error.UserAction;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipelegacy.settings.SelectChannelFragment;
import org.schabi.newpipelegacy.settings.SelectKioskFragment;
import org.schabi.newpipelegacy.settings.SelectPlaylistFragment;
Expand All @@ -41,8 +43,6 @@
import java.util.Collections;
import java.util.List;

import static org.schabi.newpipelegacy.settings.tabs.Tab.typeFrom;

public class ChooseTabsFragment extends Fragment {
private static final int MENU_ITEM_RESTORE_ID = 123456;

Expand Down Expand Up @@ -387,36 +387,31 @@ void bind(final int position, final TabViewHolder holder) {
return;
}

final String tabName;
tabNameView.setText(getTabName(type, tab));
tabIconView.setImageResource(tab.getTabIconRes(requireContext()));
}

private String getTabName(@NonNull final Tab.Type type, @NonNull final Tab tab) {
switch (type) {
case BLANK:
tabName = getString(R.string.blank_page_summary);
break;
return getString(R.string.blank_page_summary);
case DEFAULT_KIOSK:
tabName = getString(R.string.default_kiosk_page_summary);
break;
return getString(R.string.default_kiosk_page_summary);
case KIOSK:
tabName = NewPipe.getNameOfService(((Tab.KioskTab) tab)
.getKioskServiceId()) + "/" + tab.getTabName(requireContext());
break;
return getNameOfServiceById(((Tab.KioskTab) tab).getKioskServiceId())
+ "/" + tab.getTabName(requireContext());
case CHANNEL:
tabName = NewPipe.getNameOfService(((Tab.ChannelTab) tab)
.getChannelServiceId()) + "/" + tab.getTabName(requireContext());
break;
return getNameOfServiceById(((Tab.ChannelTab) tab).getChannelServiceId())
+ "/" + tab.getTabName(requireContext());
case PLAYLIST:
final int serviceId = ((Tab.PlaylistTab) tab).getPlaylistServiceId();
final String serviceName = serviceId == -1
? getString(R.string.local)
: NewPipe.getNameOfService(serviceId);
tabName = serviceName + "/" + tab.getTabName(requireContext());
break;
: getNameOfServiceById(serviceId);
return serviceName + "/" + tab.getTabName(requireContext());
default:
tabName = tab.getTabName(requireContext());
break;
return tab.getTabName(requireContext());
}

tabNameView.setText(tabName);
tabIconView.setImageResource(tab.getTabIconRes(requireContext()));
}

@SuppressLint("ClickableViewAccessibility")
Expand Down
40 changes: 23 additions & 17 deletions app/src/main/java/org/schabi/newpipelegacy/util/ServiceHelper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.schabi.newpipelegacy.util;

import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.preference.PreferenceManager;

Expand All @@ -18,10 +22,9 @@
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;

public final class ServiceHelper {
private static final StreamingService DEFAULT_FALLBACK_SERVICE = ServiceList.YouTube;

Expand Down Expand Up @@ -113,18 +116,31 @@ public static int getImportInstructionsHint(final int serviceId) {
}

public static int getSelectedServiceId(final Context context) {
return Optional.ofNullable(getSelectedService(context))
.orElse(DEFAULT_FALLBACK_SERVICE)
.getServiceId();
}

@Nullable
public static StreamingService getSelectedService(final Context context) {
final String serviceName = PreferenceManager.getDefaultSharedPreferences(context)
.getString(context.getString(R.string.current_service_key),
context.getString(R.string.default_service_value));

int serviceId;
try {
serviceId = NewPipe.getService(serviceName).getServiceId();
return NewPipe.getService(serviceName);
} catch (final ExtractionException e) {
serviceId = DEFAULT_FALLBACK_SERVICE.getServiceId();
return null;
}

return serviceId;
}
@NonNull
public static String getNameOfServiceById(final int serviceId) {
return ServiceList.all().stream()
.filter(s -> s.getServiceId() == serviceId)
.findFirst()
.map(StreamingService::getServiceInfo)
.map(StreamingService.ServiceInfo::getName)
.orElse("<unknown>");
}

public static void setSelectedServiceId(final Context context, final int serviceId) {
Expand All @@ -138,16 +154,6 @@ public static void setSelectedServiceId(final Context context, final int service
setSelectedServicePreferences(context, serviceName);
}

public static void setSelectedServiceId(final Context context, final String serviceName) {
final int serviceId = NewPipe.getIdOfService(serviceName);
if (serviceId == -1) {
setSelectedServicePreferences(context,
DEFAULT_FALLBACK_SERVICE.getServiceInfo().getName());
} else {
setSelectedServicePreferences(context, serviceName);
}
}

private static void setSelectedServicePreferences(final Context context,
final String serviceName) {
PreferenceManager.getDefaultSharedPreferences(context).edit().
Expand Down