1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 00:20:32 +00:00

code lint

This commit is contained in:
Christian Schabesberger 2015-11-29 13:06:27 +01:00
parent cb4b20af45
commit f6974e8315
21 changed files with 149 additions and 141 deletions

View File

@ -6,7 +6,6 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
@ -36,7 +35,8 @@ import android.widget.ArrayAdapter;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class ActionBarHandler {
class ActionBarHandler {
private static final String TAG = ActionBarHandler.class.toString();
private static final String KORE_PACKET = "org.xbmc.kore";
@ -47,10 +47,11 @@ public class ActionBarHandler {
private int selectedStream = -1;
private String videoTitle = "";
SharedPreferences defaultPreferences = null;
private SharedPreferences defaultPreferences = null;
private int startPosition;
class FormatItemSelectListener implements ActionBar.OnNavigationListener {
@SuppressWarnings("deprecation")
private class FormatItemSelectListener implements ActionBar.OnNavigationListener {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
selectFormatItem((int)itemId);
@ -62,11 +63,17 @@ public class ActionBarHandler {
this.activity = activity;
}
@SuppressWarnings({"deprecation", "ConstantConditions"})
public void setupNavMenu(AppCompatActivity activity) {
this.activity = activity;
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
try {
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
} catch(NullPointerException e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStream[] audioStreams) {
this.videoStreams = videoStreams;
selectedStream = 0;
@ -84,12 +91,14 @@ public class ActionBarHandler {
}
}
ArrayAdapter<String> itemAdapter = new ArrayAdapter<String>(activity.getBaseContext(),
ArrayAdapter<String> itemAdapter = new ArrayAdapter<>(activity.getBaseContext(),
android.R.layout.simple_spinner_dropdown_item, itemArray);
if(activity != null) {
ActionBar ab = activity.getSupportActionBar();
ab.setListNavigationCallbacks(itemAdapter
,new FormatItemSelectListener());
assert ab != null : "Could not get actionbar";
ab.setListNavigationCallbacks(itemAdapter
, new FormatItemSelectListener());
ab.setSelectedNavigationItem(defaultResolutionPos);
}
@ -117,7 +126,7 @@ public class ActionBarHandler {
selectedStream = i;
}
public boolean setupMenu(Menu menu, MenuInflater inflater) {
public void setupMenu(Menu menu, MenuInflater inflater) {
// CAUTION set item properties programmatically otherwise it would not be accepted by
// appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu);
@ -128,8 +137,6 @@ public class ActionBarHandler {
castItem.setVisible(defaultPreferences
.getBoolean(activity.getString(R.string.showPlayWidthKodiPreference), false));
return true;
}
public boolean onItemSelected(MenuItem item) {
@ -229,7 +236,7 @@ public class ActionBarHandler {
this.startPosition = startPositionSeconds;
}
public void downloadVideo() {
private void downloadVideo() {
if(!videoTitle.isEmpty()) {
String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format);
String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
@ -245,7 +252,7 @@ public class ActionBarHandler {
}
}
public void openInBrowser() {
private void openInBrowser() {
if(!videoTitle.isEmpty()) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
@ -255,7 +262,7 @@ public class ActionBarHandler {
}
}
public void playWithKodi() {
private void playWithKodi() {
if(!videoTitle.isEmpty()) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
@ -286,7 +293,7 @@ public class ActionBarHandler {
}
}
public void playAudio() {
private void playAudio() {
Intent intent = new Intent();
try {
intent.setAction(Intent.ACTION_VIEW);

View File

@ -8,6 +8,7 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.util.Log;
@ -42,8 +43,9 @@ public class DownloadDialog extends DialogFragment {
public static final String FILE_SUFFIX_VIDEO = "file_suffix_video";
public static final String AUDIO_URL = "audio_url";
public static final String VIDEO_URL = "video_url";
Bundle arguments;
private Bundle arguments;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
arguments = getArguments();

View File

@ -50,8 +50,8 @@ public class Downloader {
return ret;
}
/**Common functionality between download(String url) and download(String url, String language)*/
private static String dl(HttpURLConnection con) {
StringBuffer response = new StringBuffer();
private static String dl(HttpURLConnection con) throws IOException {
StringBuilder response = new StringBuilder();
try {
con.setRequestMethod("GET");
@ -71,9 +71,7 @@ public class Downloader {
uhe.printStackTrace();
//Toast.makeText(getActivity(), uhe.getMessage(), Toast.LENGTH_LONG).show();
}
catch (Exception e) {
e.printStackTrace();
}
return response.toString();
}

View File

@ -23,6 +23,7 @@ package org.schabi.newpipe;
*/
/**Static data about various media formats support by Newpipe, eg mime type, extension*/
public enum MediaFormat {
// id name suffix mime type
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
@ -32,7 +33,9 @@ public enum MediaFormat {
WEBMA (0x4, "WebM", "webm", "audio/webm");
public final int id;
@SuppressWarnings("WeakerAccess")
public final String name;
@SuppressWarnings("WeakerAccess")
public final String suffix;
public final String mimeType;

View File

@ -84,6 +84,7 @@ public class PlayVideoActivity extends AppCompatActivity {
hasSoftKeys = checkIfHasSoftKeys();
actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
if(mediaController == null) {
@ -291,11 +292,9 @@ public class PlayVideoActivity extends AppCompatActivity {
}
private boolean checkIfHasSoftKeys(){
if(Build.VERSION.SDK_INT >= 17) {
return getNavigationBarHeight() != 0 || getNavigationBarWidth() != 0;
} else {
return true;
}
return Build.VERSION.SDK_INT >= 17 ||
getNavigationBarHeight() != 0 ||
getNavigationBarWidth() != 0;
}
private int getNavigationBarHeight() {
@ -332,7 +331,7 @@ public class PlayVideoActivity extends AppCompatActivity {
}
}
public boolean checkIfLandscape() {
private boolean checkIfLandscape() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels < displayMetrics.widthPixels;

View File

@ -9,10 +9,9 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
@ -70,14 +69,11 @@ public class SettingsActivity extends PreferenceActivity {
getDelegate().onPostCreate(savedInstanceState);
}
public ActionBar getSupportActionBar() {
private ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}
public void setSupportActionBar(@Nullable Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}
@NonNull
@Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();

View File

@ -58,6 +58,7 @@ public class VideoInfo extends AbstractVideoInfo {
/**Creates a new VideoInfo object from an existing AbstractVideoInfo.
* All the shared properties are copied to the new VideoInfo.*/
@SuppressWarnings("WeakerAccess")
public VideoInfo(AbstractVideoInfo avi) {
this.id = avi.id;
this.title = avi.title;
@ -76,7 +77,6 @@ public class VideoInfo extends AbstractVideoInfo {
int seconds = Integer.parseInt(dur.substring(dur.indexOf(":")+1, dur.length()));
this.duration = (minutes*60)+seconds;
}
}
public static class VideoStream {

View File

@ -26,10 +26,10 @@ import android.widget.TextView;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class VideoInfoItemViewCreator {
class VideoInfoItemViewCreator {
private static final String TAG = VideoInfoItemViewCreator.class.toString();
LayoutInflater inflater;
private final LayoutInflater inflater;
public VideoInfoItemViewCreator(LayoutInflater inflater) {
this.inflater = inflater;

View File

@ -5,11 +5,11 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import org.schabi.newpipe.services.VideoExtractor;
import org.schabi.newpipe.services.ServiceList;
import org.schabi.newpipe.services.StreamingService;
@ -36,7 +36,7 @@ public class VideoItemDetailActivity extends AppCompatActivity {
private static final String TAG = VideoItemDetailActivity.class.toString();
VideoItemDetailFragment fragment;
private VideoItemDetailFragment fragment;
private String videoUrl;
private int currentStreamingService = -1;
@ -46,7 +46,13 @@ public class VideoItemDetailActivity extends AppCompatActivity {
setContentView(R.layout.activity_videoitem_detail);
// Show the Up button in the action bar.
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
try {
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} catch(Exception e) {
Log.d(TAG, "Could not get SupportActionBar");
e.printStackTrace();
}
// savedInstanceState is non-null when there is fragment state
// saved from previous configurations of this activity
@ -64,7 +70,7 @@ public class VideoItemDetailActivity extends AppCompatActivity {
if (getIntent().getData() != null) {
videoUrl = getIntent().getData().toString();
StreamingService[] serviceList = ServiceList.getServices();
VideoExtractor videoExtractor = null;
//VideoExtractor videoExtractor = null;
for (int i = 0; i < serviceList.length; i++) {
if (serviceList[i].acceptUrl(videoUrl)) {
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i);

View File

@ -81,7 +81,6 @@ public class VideoItemDetailFragment extends Fragment {
private ActionBarHandler actionBarHandler;
private boolean autoPlayEnabled = false;
private Thread videoExtractorThread = null;
private VideoInfo currentVideoInfo = null;
private boolean showNextVideoItem = false;
@ -92,12 +91,12 @@ public class VideoItemDetailFragment extends Fragment {
private OnInvokeCreateOptionsMenuListener onInvokeCreateOptionsMenuListener = null;
private class VideoExtractorRunnable implements Runnable {
private Handler h = new Handler();
private final Handler h = new Handler();
private VideoExtractor videoExtractor;
private StreamingService service;
private String videoUrl;
private final StreamingService service;
private final String videoUrl;
public VideoExtractorRunnable(String videoUrl, StreamingService service, VideoItemDetailFragment f) {
public VideoExtractorRunnable(String videoUrl, StreamingService service) {
this.service = service;
this.videoUrl = videoUrl;
}
@ -137,7 +136,7 @@ public class VideoItemDetailFragment extends Fragment {
}
private class VideoResultReturnedRunnable implements Runnable {
private VideoInfo videoInfo;
private final VideoInfo videoInfo;
public VideoResultReturnedRunnable(VideoInfo videoInfo) {
this.videoInfo = videoInfo;
}
@ -153,8 +152,8 @@ public class VideoItemDetailFragment extends Fragment {
public static final int VIDEO_THUMBNAIL = 1;
public static final int CHANNEL_THUMBNAIL = 2;
public static final int NEXT_VIDEO_THUMBNAIL = 3;
private Bitmap thumbnail;
private int thumbnailId;
private final Bitmap thumbnail;
private final int thumbnailId;
public SetThumbnailRunnable(Bitmap thumbnail, int id) {
this.thumbnail = thumbnail;
this.thumbnailId = id;
@ -165,9 +164,9 @@ public class VideoItemDetailFragment extends Fragment {
}
}
public void updateThumbnail(Bitmap thumbnail, int id) {
private void updateThumbnail(Bitmap thumbnail, int id) {
Activity a = getActivity();
ImageView thumbnailView = null;
ImageView thumbnailView;
try {
switch (id) {
case SetThumbnailRunnable.VIDEO_THUMBNAIL:
@ -196,7 +195,7 @@ public class VideoItemDetailFragment extends Fragment {
}
}
public void updateInfo(VideoInfo info) {
private void updateInfo(VideoInfo info) {
currentVideoInfo = info;
Resources res = activity.getResources();
try {
@ -330,8 +329,6 @@ public class VideoItemDetailFragment extends Fragment {
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public VideoItemDetailFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
@ -367,8 +364,8 @@ public class VideoItemDetailFragment extends Fragment {
try {
StreamingService streamingService = ServiceList.getService(
getArguments().getInt(STREAMING_SERVICE));
videoExtractorThread = new Thread(new VideoExtractorRunnable(
getArguments().getString(VIDEO_URL), streamingService, this));
Thread videoExtractorThread = new Thread(new VideoExtractorRunnable(
getArguments().getString(VIDEO_URL), streamingService));
autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);
videoExtractorThread.start();
@ -416,10 +413,12 @@ public class VideoItemDetailFragment extends Fragment {
/**Returns the java.util.Locale object which corresponds to the locale set in NewPipe's preferences.
* Currently not affected by the device's locale.*/
public Locale getPreferredLocale() {
private Locale getPreferredLocale() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
String languageKey = getContext().getString(R.string.searchLanguage);
String languageCode = "en";//i know the following line defaults languageCode to "en", but java is picky about uninitialised values
//i know the following line defaults languageCode to "en", but java is picky about uninitialised values
// Schabi: well lint tels me the value is redundant. I'll suppress it for now.
@SuppressWarnings("UnusedAssignment") String languageCode = "en";
languageCode = sp.getString(languageKey, "en");
if(languageCode.length() == 2) {
@ -433,7 +432,7 @@ public class VideoItemDetailFragment extends Fragment {
return Locale.getDefault();
}
public boolean checkIfLandscape() {
private boolean checkIfLandscape() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels < displayMetrics.widthPixels;

View File

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -56,9 +57,9 @@ public class VideoItemListActivity extends AppCompatActivity
private VideoItemListFragment listFragment;
private VideoItemDetailFragment videoFragment = null;
Menu menu = null;
private Menu menu = null;
public class SearchVideoQueryListener implements SearchView.OnQueryTextListener {
private class SearchVideoQueryListener implements SearchView.OnQueryTextListener {
@Override
public boolean onQueryTextSubmit(String query) {
@ -69,8 +70,14 @@ public class VideoItemListActivity extends AppCompatActivity
// hide virtual keyboard
InputMethodManager inputManager =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(
getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
try {
//noinspection ConstantConditions
inputManager.hideSoftInputFromWindow(
getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
} catch(NullPointerException e) {
Log.e(TAG, "Could not get widget with focus");
e.printStackTrace();
}
// clear focus
// 1. to not open up the keyboard after switching back to this
// 2. It's a workaround to a seeming bug by the Android OS it self, causing
@ -116,7 +123,13 @@ public class VideoItemListActivity extends AppCompatActivity
ArrayList<VideoPreviewInfo> p = arguments.getParcelableArrayList(VIDEO_INFO_ITEMS);
if(p != null) {
mode = PRESENT_VIDEOS_MODE;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
try {
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} catch (NullPointerException e) {
Log.e(TAG, "Could not get SupportActionBar");
e.printStackTrace();
}
listFragment.present(p);
}

View File

@ -64,8 +64,8 @@ public class VideoItemListFragment extends ListFragment {
private ListView list;
private class ResultRunnable implements Runnable {
private SearchEngine.Result result;
private int requestId;
private final SearchEngine.Result result;
private final int requestId;
public ResultRunnable(SearchEngine.Result result, int requestId) {
this.result = result;
this.requestId = requestId;
@ -77,12 +77,12 @@ public class VideoItemListFragment extends ListFragment {
}
private class SearchRunnable implements Runnable {
private SearchEngine engine;
private String query;
private int page;
Handler h = new Handler();
private final SearchEngine engine;
private final String query;
private final int page;
final Handler h = new Handler();
private volatile boolean run = true;
private int requestId;
private final int requestId;
public SearchRunnable(SearchEngine engine, String query, int page, int requestId) {
this.engine = engine;
this.query = query;
@ -116,11 +116,11 @@ public class VideoItemListFragment extends ListFragment {
}
private class LoadThumbsRunnable implements Runnable {
private Vector<String> thumbnailUrlList = new Vector<>();
private Vector<Boolean> downloadedList;
Handler h = new Handler();
private final Vector<String> thumbnailUrlList = new Vector<>();
private final Vector<Boolean> downloadedList;
final Handler h = new Handler();
private volatile boolean run = true;
private int requestId;
private final int requestId;
public LoadThumbsRunnable(Vector<VideoPreviewInfo> videoList,
Vector<Boolean> downloadedList, int requestId) {
for(VideoPreviewInfo item : videoList) {
@ -139,7 +139,7 @@ public class VideoItemListFragment extends ListFragment {
public void run() {
for(int i = 0; i < thumbnailUrlList.size() && run; i++) {
if(!downloadedList.get(i)) {
Bitmap thumbnail = null;
Bitmap thumbnail;
try {
thumbnail = BitmapFactory.decodeStream(
new URL(thumbnailUrlList.get(i)).openConnection().getInputStream());
@ -153,9 +153,9 @@ public class VideoItemListFragment extends ListFragment {
}
private class SetThumbnailRunnable implements Runnable {
private int index;
private Bitmap thumbnail;
private int requestId;
private final int index;
private final Bitmap thumbnail;
private final int requestId;
public SetThumbnailRunnable(int index, Bitmap thumbnail, int requestId) {
this.index = index;
this.thumbnail = thumbnail;
@ -164,7 +164,7 @@ public class VideoItemListFragment extends ListFragment {
@Override
public void run() {
if(requestId == currentRequestId) {
videoListAdapter.updateDownloadedThumbnailList(index, true);
videoListAdapter.updateDownloadedThumbnailList(index);
videoListAdapter.setThumbnail(index, thumbnail);
}
}
@ -188,7 +188,7 @@ public class VideoItemListFragment extends ListFragment {
getListView().smoothScrollToPosition(0);
}
public void nextPage() {
private void nextPage() {
lastPage++;
Log.d(TAG, getString(R.string.searchPage) + Integer.toString(lastPage));
startSearch(query, lastPage);
@ -207,7 +207,7 @@ public class VideoItemListFragment extends ListFragment {
this.streamingService = streamingService;
}
public void updateListOnResult(SearchEngine.Result result, int requestId) {
private void updateListOnResult(SearchEngine.Result result, int requestId) {
if(requestId == currentRequestId) {
setListShown(true);
if (result.resultList.isEmpty()) {
@ -237,7 +237,7 @@ public class VideoItemListFragment extends ListFragment {
}
}
public void terminateThreads() {
private void terminateThreads() {
if(loadThumbsRunnable != null && loadThumbsRunnable.isRunning()) {
loadThumbsRunnable.terminate();
try {
@ -276,12 +276,7 @@ public class VideoItemListFragment extends ListFragment {
void onItemSelected(String id);
}
Callbacks mCallbacks = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
private Callbacks mCallbacks = null;
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
@ -333,11 +328,6 @@ public class VideoItemListFragment extends ListFragment {
mCallbacks = (Callbacks) context;
}
@Override
public void onDetach() {
super.onDetach();
}
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
@ -345,22 +335,11 @@ public class VideoItemListFragment extends ListFragment {
mCallbacks.onItemSelected(Long.toString(id));
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
/*
if (mActivatedPosition != ListView.INVALID_POSITION) {
// Serialize and persist the activated item position.
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
}
*/
}
/**
* Turns on activate-on-click mode. When this mode is on, list items will be
* given the 'activated' state when touched.
*/
public void setActivateOnItemClick(boolean activateOnItemClick) {
public void setActivateOnItemClick(@SuppressWarnings("SameParameterValue") boolean activateOnItemClick) {
// When setting CHOICE_MODE_SINGLE, ListView will automatically
// give items the 'activated' state when touched.
getListView().setChoiceMode(activateOnItemClick

View File

@ -32,19 +32,17 @@ import java.util.Vector;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class VideoListAdapter extends BaseAdapter {
class VideoListAdapter extends BaseAdapter {
private static final String TAG = VideoListAdapter.class.toString();
private Context context;
private VideoInfoItemViewCreator viewCreator;
private final Context context;
private final VideoInfoItemViewCreator viewCreator;
private Vector<VideoPreviewInfo> videoList = new Vector<>();
private Vector<Boolean> downloadedThumbnailList = new Vector<>();
VideoItemListFragment videoListFragment;
ListView listView;
private final ListView listView;
public VideoListAdapter(Context context, VideoItemListFragment videoListFragment) {
viewCreator = new VideoInfoItemViewCreator(LayoutInflater.from(context));
this.videoListFragment = videoListFragment;
this.listView = videoListFragment.getListView();
this.context = context;
}
@ -67,8 +65,8 @@ public class VideoListAdapter extends BaseAdapter {
return videoList;
}
public void updateDownloadedThumbnailList(int index, boolean val) {
downloadedThumbnailList.set(index, val);
public void updateDownloadedThumbnailList(int index) {
downloadedThumbnailList.set(index, true);
}
public Vector<Boolean> getDownloadedThumbnailList() {

View File

@ -29,6 +29,7 @@ import org.schabi.newpipe.services.AbstractVideoInfo;
/**Info object for previews of unopened videos, eg search results, related videos*/
public class VideoPreviewInfo extends AbstractVideoInfo implements Parcelable {
public String duration = "";
@SuppressWarnings("WeakerAccess")
protected VideoPreviewInfo(Parcel in) {
id = in.readString();
title = in.readString();

View File

@ -31,7 +31,7 @@ public interface SearchEngine {
class Result {
public String errorMessage = "";
public String suggestion = "";
public Vector<VideoPreviewInfo> resultList = new Vector<>();
public final Vector<VideoPreviewInfo> resultList = new Vector<>();
}
ArrayList<String> suggestionList(String query);

View File

@ -42,7 +42,7 @@ public class ServiceList {
}
public static int getIdOfService(String serviceName) {
for(int i = 0; i < services.length; i++) {
if(services[i].getServiceInfo().name == serviceName) {
if(services[i].getServiceInfo().name.equals(serviceName)) {
return i;
}
}

View File

@ -24,9 +24,10 @@ import org.schabi.newpipe.VideoInfo;
/**Scrapes information from a video streaming service (eg, YouTube).*/
public abstract class VideoExtractor {
public String pageUrl;
public VideoInfo videoInfo;
protected final String pageUrl;
protected VideoInfo videoInfo;
@SuppressWarnings("WeakerAccess")
public VideoExtractor(String url) {
this.pageUrl = url;
}
@ -99,17 +100,17 @@ public abstract class VideoExtractor {
return videoInfo;
}
public abstract String getVideoUrl(String videoId);
public abstract String getVideoId(String siteUrl);
public abstract int getTimeStamp();
public abstract String getTitle();
public abstract String getDescription();
public abstract String getUploader();
public abstract int getLength();
public abstract int getViews();
public abstract String getUploadDate();
public abstract String getThumbnailUrl();
public abstract String getUploaderThumbnailUrl();
public abstract VideoInfo.AudioStream[] getAudioStreams();
public abstract VideoInfo.VideoStream[] getVideoStreams();
protected abstract String getVideoUrl(String videoId);
protected abstract String getVideoId(String siteUrl);
protected abstract int getTimeStamp();
protected abstract String getTitle();
protected abstract String getDescription();
protected abstract String getUploader();
protected abstract int getLength();
protected abstract int getViews();
protected abstract String getUploadDate();
protected abstract String getThumbnailUrl();
protected abstract String getUploaderThumbnailUrl();
protected abstract VideoInfo.AudioStream[] getAudioStreams();
protected abstract VideoInfo.VideoStream[] getVideoStreams();
}

View File

@ -95,20 +95,18 @@ public class YoutubeSearchEngine implements SearchEngine {
// both types of spell correction item
if(!((el = item.select("div[class*=\"spell-correction\"]").first()) == null)) {
result.suggestion = el.select("a").first().text();
// search message item
// search message item
} else if(!((el = item.select("div[class*=\"search-message\"]").first()) == null)) {
result.errorMessage = el.text();
// video item type
// video item type
} else if(!((el = item.select("div[class*=\"yt-lockup-video\"").first()) == null)) {
//todo: de-duplicate this with YoutubeVideoExtractor.getVideoPreviewInfo()
VideoPreviewInfo resultItem = new VideoPreviewInfo();
Element dl = el.select("h3").first().select("a").first();
resultItem.webpage_url = dl.attr("abs:href");
try {
Pattern p = Pattern.compile("v=([0-9a-zA-Z-]*)");
Matcher m = p.matcher(resultItem.webpage_url);
m.find();
resultItem.id=m.group(1);
} catch (Exception e) {
e.printStackTrace();
@ -134,6 +132,7 @@ public class YoutubeSearchEngine implements SearchEngine {
}
result.resultList.add(resultItem);
} else {
//noinspection ConstantConditions
Log.e(TAG, "unexpected element found:\""+el+"\"");
}
}

View File

@ -50,8 +50,7 @@ import java.util.regex.Pattern;
public class YoutubeVideoExtractor extends VideoExtractor {
private static final String TAG = YoutubeVideoExtractor.class.toString();
private String pageContents;
private Document doc;
private final Document doc;
private JSONObject jsonObj;
private JSONObject playerArgs;
@ -64,7 +63,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
public YoutubeVideoExtractor(String pageUrl) {
super(pageUrl);//most common videoInfo fields are now set in our superclass, for all services
pageContents = Downloader.download(cleanUrl(pageUrl));
String pageContents = Downloader.download(cleanUrl(pageUrl));
doc = Jsoup.parse(pageContents, pageUrl);
//attempt to load the youtube js player JSON arguments
@ -266,6 +265,8 @@ public class YoutubeVideoExtractor extends VideoExtractor {
/**These lists only contain itag formats that are supported by the common Android Video player.
However if you are looking for a list showing all itag formats, look at
https://github.com/rg3/youtube-dl/issues/1687 */
@SuppressWarnings("WeakerAccess")
public static int resolveFormat(int itag) {
switch(itag) {
// video
@ -285,6 +286,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
}
}
@SuppressWarnings("WeakerAccess")
public static String resolveResolutionString(int itag) {
switch(itag) {
case 17: return "144p";
@ -303,6 +305,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
}
}
@SuppressWarnings("WeakerAccess")
@Override
public String getVideoId(String url) {
String id;
@ -327,6 +330,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
return "";
}
@SuppressWarnings("WeakerAccess")
@Override
public String getVideoUrl(String videoId) {
return "https://www.youtube.com/watch?v=" + videoId;
@ -579,7 +583,10 @@ public class YoutubeVideoExtractor extends VideoExtractor {
e.printStackTrace();
}
Context.exit();
return result.toString();
if(result != null)
return result.toString();
else
return "";
}
private String cleanUrl(String complexUrl) {

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Categories -->
<string name="settingsCategoryVideoAudio">settings_categoery_video_audio</string>
<string name="settingsCategoryVideoInfo">settings_category_video_info</string>

View File

@ -15,7 +15,7 @@
<item name="background">@color/primaryColorYoutube</item>
</style>
<style name="PlayVideoTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="VideoPlayerTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowFullscreen">false</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>