use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class ChannelActivity method requestData.
private void requestData(final boolean onlyVideos) {
// start processing
isLoading = true;
if (!onlyVideos) {
//delete already displayed content
progressBar.setVisibility(View.VISIBLE);
infoListAdapter.clearSteamItemList();
pageNumber = 0;
subscriberLayout.setVisibility(View.GONE);
titleView.setText("");
getSupportActionBar().setTitle("");
if (SDK_INT >= 21) {
channelBanner.setImageDrawable(getDrawable(R.drawable.channel_banner));
avatarView.setImageDrawable(getDrawable(R.drawable.buddy));
}
infoListAdapter.showFooter(false);
}
Thread channelExtractorThread = new Thread(new Runnable() {
Handler h = new Handler();
@Override
public void run() {
StreamingService service = null;
try {
service = NewPipe.getService(serviceId);
ChannelExtractor extractor = service.getChannelExtractorInstance(channelUrl, pageNumber);
final ChannelInfo info = ChannelInfo.getInfo(extractor);
h.post(new Runnable() {
@Override
public void run() {
isLoading = false;
if (!onlyVideos) {
updateUi(info);
infoListAdapter.showFooter(true);
}
hasNextPage = info.hasNextPage;
if (!hasNextPage) {
infoListAdapter.showFooter(false);
}
addVideos(info);
}
});
// look for non critical errors during extraction
if (info != null && !info.errors.isEmpty()) {
Log.e(TAG, "OCCURRED ERRORS DURING EXTRACTION:");
for (Throwable e : info.errors) {
e.printStackTrace();
Log.e(TAG, "------");
}
View rootView = findViewById(android.R.id.content);
ErrorActivity.reportError(h, ChannelActivity.this, info.errors, null, rootView, ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_CHANNEL, service.getServiceInfo().name, channelUrl, 0));
}
} catch (IOException ioe) {
postNewErrorToast(h, R.string.network_error);
ioe.printStackTrace();
} catch (ParsingException pe) {
ErrorActivity.reportError(h, ChannelActivity.this, pe, VideoItemDetailFragment.class, null, ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_CHANNEL, service.getServiceInfo().name, channelUrl, R.string.parsing_error));
h.post(new Runnable() {
@Override
public void run() {
ChannelActivity.this.finish();
}
});
pe.printStackTrace();
} catch (ExtractionException ex) {
String name = "none";
if (service != null) {
name = service.getServiceInfo().name;
}
ErrorActivity.reportError(h, ChannelActivity.this, ex, VideoItemDetailFragment.class, null, ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_CHANNEL, name, channelUrl, R.string.parsing_error));
h.post(new Runnable() {
@Override
public void run() {
ChannelActivity.this.finish();
}
});
ex.printStackTrace();
} catch (Exception e) {
ErrorActivity.reportError(h, ChannelActivity.this, e, VideoItemDetailFragment.class, null, ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_CHANNEL, service.getServiceInfo().name, channelUrl, R.string.general_error));
h.post(new Runnable() {
@Override
public void run() {
ChannelActivity.this.finish();
}
});
e.printStackTrace();
}
}
});
channelExtractorThread.start();
}
use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class NavigationHelper method getIntentByLink.
public static Intent getIntentByLink(Context context, StreamingService service, String url) throws ExtractionException {
StreamingService.LinkType linkType = service.getLinkTypeByUrl(url);
if (linkType == StreamingService.LinkType.NONE) {
throw new ExtractionException("Url not known to service. service=" + service + " url=" + url);
}
url = getCleanUrl(service, url, linkType);
Intent rIntent = getOpenIntent(context, url, service.getServiceId(), linkType);
switch(linkType) {
case STREAM:
rIntent.putExtra(VideoDetailFragment.AUTO_PLAY, PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.autoplay_through_intent_key), false));
break;
}
return rIntent;
}
use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class ThemeHelper method getThemeForService.
/**
* Return the selected theme styled according to the serviceId.
*
* @param context context to get the selected theme
* @param serviceId return a theme styled to this service,
* -1 to get the default
* @return the selected style (styled)
*/
@StyleRes
public static int getThemeForService(Context context, int serviceId) {
String lightTheme = context.getResources().getString(R.string.light_theme_key);
String darkTheme = context.getResources().getString(R.string.dark_theme_key);
String blackTheme = context.getResources().getString(R.string.black_theme_key);
String selectedTheme = getSelectedThemeString(context);
int defaultTheme = R.style.DarkTheme;
if (selectedTheme.equals(lightTheme))
defaultTheme = R.style.LightTheme;
else if (selectedTheme.equals(blackTheme))
defaultTheme = R.style.BlackTheme;
else if (selectedTheme.equals(darkTheme))
defaultTheme = R.style.DarkTheme;
if (serviceId <= -1) {
return defaultTheme;
}
final StreamingService service;
try {
service = NewPipe.getService(serviceId);
} catch (ExtractionException ignored) {
return defaultTheme;
}
String themeName = "DarkTheme";
if (selectedTheme.equals(lightTheme))
themeName = "LightTheme";
else if (selectedTheme.equals(blackTheme))
themeName = "BlackTheme";
else if (selectedTheme.equals(darkTheme))
themeName = "DarkTheme";
themeName += "." + service.getServiceInfo().getName();
int resourceId = context.getResources().getIdentifier(themeName, "style", context.getPackageName());
if (resourceId > 0) {
return resourceId;
}
return defaultTheme;
}
use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class PopupActivity method handleIntent.
private void handleIntent(Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !PermissionHelper.checkSystemAlertWindowPermission(this)) {
Toast.makeText(this, R.string.msg_popup_permission, Toast.LENGTH_LONG).show();
return;
}
String videoUrl = "";
StreamingService service = null;
// first gather data and find service
if (intent.getData() != null) {
// this means the video was called though another app
videoUrl = intent.getData().toString();
} else if (intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
//this means that vidoe was called through share menu
String extraText = intent.getStringExtra(Intent.EXTRA_TEXT);
videoUrl = getUris(extraText)[0];
}
service = NewPipe.getServiceByUrl(videoUrl);
if (service == null) {
Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show();
return;
} else {
Intent callIntent = new Intent();
switch(service.getLinkTypeByUrl(videoUrl)) {
case STREAM:
callIntent.setClass(this, PopupVideoPlayer.class);
break;
case PLAYLIST:
Log.e(TAG, "NOT YET DEFINED");
break;
default:
Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show();
return;
}
callIntent.putExtra(NavStack.URL, videoUrl);
callIntent.putExtra(NavStack.SERVICE_ID, service.getServiceId());
startService(callIntent);
}
}
use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class RouterActivity method handleIntent.
private void handleIntent(Intent intent) {
String videoUrl = "";
StreamingService service = null;
// first gather data and find service
if (intent.getData() != null) {
// this means the video was called though another app
videoUrl = intent.getData().toString();
} else if (intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
//this means that vidoe was called through share menu
String extraText = intent.getStringExtra(Intent.EXTRA_TEXT);
videoUrl = getUris(extraText)[0];
}
service = NewPipe.getServiceByUrl(videoUrl);
if (service == null) {
Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show();
return;
} else {
Intent callIntent = new Intent();
switch(service.getLinkTypeByUrl(videoUrl)) {
case CHANNEL:
callIntent.setClass(this, ChannelActivity.class);
break;
case STREAM:
callIntent.setClass(this, VideoItemDetailActivity.class);
callIntent.putExtra(VideoItemDetailFragment.AUTO_PLAY, PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.autoplay_through_intent_key), false));
break;
case PLAYLIST:
Log.e(TAG, "NOT YET DEFINED");
break;
default:
Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show();
return;
}
callIntent.putExtra(NavStack.URL, videoUrl);
callIntent.putExtra(NavStack.SERVICE_ID, service.getServiceId());
startActivity(callIntent);
}
}
Aggregations