mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
code lint
This commit is contained in:
parent
cb4b20af45
commit
f6974e8315
@ -6,7 +6,6 @@ import android.content.SharedPreferences;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
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/>.
|
* 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 TAG = ActionBarHandler.class.toString();
|
||||||
private static final String KORE_PACKET = "org.xbmc.kore";
|
private static final String KORE_PACKET = "org.xbmc.kore";
|
||||||
|
|
||||||
@ -47,10 +47,11 @@ public class ActionBarHandler {
|
|||||||
private int selectedStream = -1;
|
private int selectedStream = -1;
|
||||||
private String videoTitle = "";
|
private String videoTitle = "";
|
||||||
|
|
||||||
SharedPreferences defaultPreferences = null;
|
private SharedPreferences defaultPreferences = null;
|
||||||
private int startPosition;
|
private int startPosition;
|
||||||
|
|
||||||
class FormatItemSelectListener implements ActionBar.OnNavigationListener {
|
@SuppressWarnings("deprecation")
|
||||||
|
private class FormatItemSelectListener implements ActionBar.OnNavigationListener {
|
||||||
@Override
|
@Override
|
||||||
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
|
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
|
||||||
selectFormatItem((int)itemId);
|
selectFormatItem((int)itemId);
|
||||||
@ -62,11 +63,17 @@ public class ActionBarHandler {
|
|||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"deprecation", "ConstantConditions"})
|
||||||
public void setupNavMenu(AppCompatActivity activity) {
|
public void setupNavMenu(AppCompatActivity activity) {
|
||||||
this.activity = 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) {
|
public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStream[] audioStreams) {
|
||||||
this.videoStreams = videoStreams;
|
this.videoStreams = videoStreams;
|
||||||
selectedStream = 0;
|
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);
|
android.R.layout.simple_spinner_dropdown_item, itemArray);
|
||||||
if(activity != null) {
|
if(activity != null) {
|
||||||
ActionBar ab = activity.getSupportActionBar();
|
ActionBar ab = activity.getSupportActionBar();
|
||||||
ab.setListNavigationCallbacks(itemAdapter
|
assert ab != null : "Could not get actionbar";
|
||||||
,new FormatItemSelectListener());
|
ab.setListNavigationCallbacks(itemAdapter
|
||||||
|
, new FormatItemSelectListener());
|
||||||
|
|
||||||
ab.setSelectedNavigationItem(defaultResolutionPos);
|
ab.setSelectedNavigationItem(defaultResolutionPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +126,7 @@ public class ActionBarHandler {
|
|||||||
selectedStream = i;
|
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
|
// CAUTION set item properties programmatically otherwise it would not be accepted by
|
||||||
// appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu);
|
// appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu);
|
||||||
|
|
||||||
@ -128,8 +137,6 @@ public class ActionBarHandler {
|
|||||||
|
|
||||||
castItem.setVisible(defaultPreferences
|
castItem.setVisible(defaultPreferences
|
||||||
.getBoolean(activity.getString(R.string.showPlayWidthKodiPreference), false));
|
.getBoolean(activity.getString(R.string.showPlayWidthKodiPreference), false));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onItemSelected(MenuItem item) {
|
public boolean onItemSelected(MenuItem item) {
|
||||||
@ -229,7 +236,7 @@ public class ActionBarHandler {
|
|||||||
this.startPosition = startPositionSeconds;
|
this.startPosition = startPositionSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadVideo() {
|
private void downloadVideo() {
|
||||||
if(!videoTitle.isEmpty()) {
|
if(!videoTitle.isEmpty()) {
|
||||||
String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format);
|
String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format);
|
||||||
String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
|
String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
|
||||||
@ -245,7 +252,7 @@ public class ActionBarHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openInBrowser() {
|
private void openInBrowser() {
|
||||||
if(!videoTitle.isEmpty()) {
|
if(!videoTitle.isEmpty()) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
@ -255,7 +262,7 @@ public class ActionBarHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playWithKodi() {
|
private void playWithKodi() {
|
||||||
if(!videoTitle.isEmpty()) {
|
if(!videoTitle.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
@ -286,7 +293,7 @@ public class ActionBarHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playAudio() {
|
private void playAudio() {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
try {
|
try {
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
|
@ -8,6 +8,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.util.Log;
|
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 FILE_SUFFIX_VIDEO = "file_suffix_video";
|
||||||
public static final String AUDIO_URL = "audio_url";
|
public static final String AUDIO_URL = "audio_url";
|
||||||
public static final String VIDEO_URL = "video_url";
|
public static final String VIDEO_URL = "video_url";
|
||||||
Bundle arguments;
|
private Bundle arguments;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
arguments = getArguments();
|
arguments = getArguments();
|
||||||
|
@ -50,8 +50,8 @@ public class Downloader {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/**Common functionality between download(String url) and download(String url, String language)*/
|
/**Common functionality between download(String url) and download(String url, String language)*/
|
||||||
private static String dl(HttpURLConnection con) {
|
private static String dl(HttpURLConnection con) throws IOException {
|
||||||
StringBuffer response = new StringBuffer();
|
StringBuilder response = new StringBuilder();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
@ -71,9 +71,7 @@ public class Downloader {
|
|||||||
uhe.printStackTrace();
|
uhe.printStackTrace();
|
||||||
//Toast.makeText(getActivity(), uhe.getMessage(), Toast.LENGTH_LONG).show();
|
//Toast.makeText(getActivity(), uhe.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return response.toString();
|
return response.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ package org.schabi.newpipe;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**Static data about various media formats support by Newpipe, eg mime type, extension*/
|
/**Static data about various media formats support by Newpipe, eg mime type, extension*/
|
||||||
|
|
||||||
public enum MediaFormat {
|
public enum MediaFormat {
|
||||||
// id name suffix mime type
|
// id name suffix mime type
|
||||||
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
|
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
|
||||||
@ -32,7 +33,9 @@ public enum MediaFormat {
|
|||||||
WEBMA (0x4, "WebM", "webm", "audio/webm");
|
WEBMA (0x4, "WebM", "webm", "audio/webm");
|
||||||
|
|
||||||
public final int id;
|
public final int id;
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public final String name;
|
public final String name;
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public final String suffix;
|
public final String suffix;
|
||||||
public final String mimeType;
|
public final String mimeType;
|
||||||
|
|
||||||
|
@ -84,6 +84,7 @@ public class PlayVideoActivity extends AppCompatActivity {
|
|||||||
hasSoftKeys = checkIfHasSoftKeys();
|
hasSoftKeys = checkIfHasSoftKeys();
|
||||||
|
|
||||||
actionBar = getSupportActionBar();
|
actionBar = getSupportActionBar();
|
||||||
|
assert actionBar != null;
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if(mediaController == null) {
|
if(mediaController == null) {
|
||||||
@ -291,11 +292,9 @@ public class PlayVideoActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkIfHasSoftKeys(){
|
private boolean checkIfHasSoftKeys(){
|
||||||
if(Build.VERSION.SDK_INT >= 17) {
|
return Build.VERSION.SDK_INT >= 17 ||
|
||||||
return getNavigationBarHeight() != 0 || getNavigationBarWidth() != 0;
|
getNavigationBarHeight() != 0 ||
|
||||||
} else {
|
getNavigationBarWidth() != 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNavigationBarHeight() {
|
private int getNavigationBarHeight() {
|
||||||
@ -332,7 +331,7 @@ public class PlayVideoActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkIfLandscape() {
|
private boolean checkIfLandscape() {
|
||||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||||
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||||
return displayMetrics.heightPixels < displayMetrics.widthPixels;
|
return displayMetrics.heightPixels < displayMetrics.widthPixels;
|
||||||
|
@ -9,10 +9,9 @@ import android.preference.PreferenceActivity;
|
|||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.LayoutRes;
|
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.ActionBar;
|
||||||
import android.support.v7.app.AppCompatDelegate;
|
import android.support.v7.app.AppCompatDelegate;
|
||||||
import android.support.v7.widget.Toolbar;
|
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -70,14 +69,11 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
getDelegate().onPostCreate(savedInstanceState);
|
getDelegate().onPostCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionBar getSupportActionBar() {
|
private ActionBar getSupportActionBar() {
|
||||||
return getDelegate().getSupportActionBar();
|
return getDelegate().getSupportActionBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSupportActionBar(@Nullable Toolbar toolbar) {
|
@NonNull
|
||||||
getDelegate().setSupportActionBar(toolbar);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MenuInflater getMenuInflater() {
|
public MenuInflater getMenuInflater() {
|
||||||
return getDelegate().getMenuInflater();
|
return getDelegate().getMenuInflater();
|
||||||
|
@ -58,6 +58,7 @@ public class VideoInfo extends AbstractVideoInfo {
|
|||||||
|
|
||||||
/**Creates a new VideoInfo object from an existing AbstractVideoInfo.
|
/**Creates a new VideoInfo object from an existing AbstractVideoInfo.
|
||||||
* All the shared properties are copied to the new VideoInfo.*/
|
* All the shared properties are copied to the new VideoInfo.*/
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public VideoInfo(AbstractVideoInfo avi) {
|
public VideoInfo(AbstractVideoInfo avi) {
|
||||||
this.id = avi.id;
|
this.id = avi.id;
|
||||||
this.title = avi.title;
|
this.title = avi.title;
|
||||||
@ -76,7 +77,6 @@ public class VideoInfo extends AbstractVideoInfo {
|
|||||||
int seconds = Integer.parseInt(dur.substring(dur.indexOf(":")+1, dur.length()));
|
int seconds = Integer.parseInt(dur.substring(dur.indexOf(":")+1, dur.length()));
|
||||||
this.duration = (minutes*60)+seconds;
|
this.duration = (minutes*60)+seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class VideoStream {
|
public static class VideoStream {
|
||||||
|
@ -26,10 +26,10 @@ import android.widget.TextView;
|
|||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class VideoInfoItemViewCreator {
|
class VideoInfoItemViewCreator {
|
||||||
private static final String TAG = VideoInfoItemViewCreator.class.toString();
|
private static final String TAG = VideoInfoItemViewCreator.class.toString();
|
||||||
|
|
||||||
LayoutInflater inflater;
|
private final LayoutInflater inflater;
|
||||||
|
|
||||||
public VideoInfoItemViewCreator(LayoutInflater inflater) {
|
public VideoInfoItemViewCreator(LayoutInflater inflater) {
|
||||||
this.inflater = inflater;
|
this.inflater = inflater;
|
||||||
|
@ -5,11 +5,11 @@ import android.os.Bundle;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.schabi.newpipe.services.VideoExtractor;
|
|
||||||
import org.schabi.newpipe.services.ServiceList;
|
import org.schabi.newpipe.services.ServiceList;
|
||||||
import org.schabi.newpipe.services.StreamingService;
|
import org.schabi.newpipe.services.StreamingService;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ public class VideoItemDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private static final String TAG = VideoItemDetailActivity.class.toString();
|
private static final String TAG = VideoItemDetailActivity.class.toString();
|
||||||
|
|
||||||
VideoItemDetailFragment fragment;
|
private VideoItemDetailFragment fragment;
|
||||||
|
|
||||||
private String videoUrl;
|
private String videoUrl;
|
||||||
private int currentStreamingService = -1;
|
private int currentStreamingService = -1;
|
||||||
@ -46,7 +46,13 @@ public class VideoItemDetailActivity extends AppCompatActivity {
|
|||||||
setContentView(R.layout.activity_videoitem_detail);
|
setContentView(R.layout.activity_videoitem_detail);
|
||||||
|
|
||||||
// Show the Up button in the action bar.
|
// 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
|
// savedInstanceState is non-null when there is fragment state
|
||||||
// saved from previous configurations of this activity
|
// saved from previous configurations of this activity
|
||||||
@ -64,7 +70,7 @@ public class VideoItemDetailActivity extends AppCompatActivity {
|
|||||||
if (getIntent().getData() != null) {
|
if (getIntent().getData() != null) {
|
||||||
videoUrl = getIntent().getData().toString();
|
videoUrl = getIntent().getData().toString();
|
||||||
StreamingService[] serviceList = ServiceList.getServices();
|
StreamingService[] serviceList = ServiceList.getServices();
|
||||||
VideoExtractor videoExtractor = null;
|
//VideoExtractor videoExtractor = null;
|
||||||
for (int i = 0; i < serviceList.length; i++) {
|
for (int i = 0; i < serviceList.length; i++) {
|
||||||
if (serviceList[i].acceptUrl(videoUrl)) {
|
if (serviceList[i].acceptUrl(videoUrl)) {
|
||||||
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i);
|
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i);
|
||||||
|
@ -81,7 +81,6 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
private ActionBarHandler actionBarHandler;
|
private ActionBarHandler actionBarHandler;
|
||||||
|
|
||||||
private boolean autoPlayEnabled = false;
|
private boolean autoPlayEnabled = false;
|
||||||
private Thread videoExtractorThread = null;
|
|
||||||
private VideoInfo currentVideoInfo = null;
|
private VideoInfo currentVideoInfo = null;
|
||||||
private boolean showNextVideoItem = false;
|
private boolean showNextVideoItem = false;
|
||||||
|
|
||||||
@ -92,12 +91,12 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
private OnInvokeCreateOptionsMenuListener onInvokeCreateOptionsMenuListener = null;
|
private OnInvokeCreateOptionsMenuListener onInvokeCreateOptionsMenuListener = null;
|
||||||
|
|
||||||
private class VideoExtractorRunnable implements Runnable {
|
private class VideoExtractorRunnable implements Runnable {
|
||||||
private Handler h = new Handler();
|
private final Handler h = new Handler();
|
||||||
private VideoExtractor videoExtractor;
|
private VideoExtractor videoExtractor;
|
||||||
private StreamingService service;
|
private final StreamingService service;
|
||||||
private String videoUrl;
|
private final String videoUrl;
|
||||||
|
|
||||||
public VideoExtractorRunnable(String videoUrl, StreamingService service, VideoItemDetailFragment f) {
|
public VideoExtractorRunnable(String videoUrl, StreamingService service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.videoUrl = videoUrl;
|
this.videoUrl = videoUrl;
|
||||||
}
|
}
|
||||||
@ -137,7 +136,7 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class VideoResultReturnedRunnable implements Runnable {
|
private class VideoResultReturnedRunnable implements Runnable {
|
||||||
private VideoInfo videoInfo;
|
private final VideoInfo videoInfo;
|
||||||
public VideoResultReturnedRunnable(VideoInfo videoInfo) {
|
public VideoResultReturnedRunnable(VideoInfo videoInfo) {
|
||||||
this.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 VIDEO_THUMBNAIL = 1;
|
||||||
public static final int CHANNEL_THUMBNAIL = 2;
|
public static final int CHANNEL_THUMBNAIL = 2;
|
||||||
public static final int NEXT_VIDEO_THUMBNAIL = 3;
|
public static final int NEXT_VIDEO_THUMBNAIL = 3;
|
||||||
private Bitmap thumbnail;
|
private final Bitmap thumbnail;
|
||||||
private int thumbnailId;
|
private final int thumbnailId;
|
||||||
public SetThumbnailRunnable(Bitmap thumbnail, int id) {
|
public SetThumbnailRunnable(Bitmap thumbnail, int id) {
|
||||||
this.thumbnail = thumbnail;
|
this.thumbnail = thumbnail;
|
||||||
this.thumbnailId = id;
|
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();
|
Activity a = getActivity();
|
||||||
ImageView thumbnailView = null;
|
ImageView thumbnailView;
|
||||||
try {
|
try {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case SetThumbnailRunnable.VIDEO_THUMBNAIL:
|
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;
|
currentVideoInfo = info;
|
||||||
Resources res = activity.getResources();
|
Resources res = activity.getResources();
|
||||||
try {
|
try {
|
||||||
@ -330,8 +329,6 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||||
* fragment (e.g. upon screen orientation changes).
|
* fragment (e.g. upon screen orientation changes).
|
||||||
*/
|
*/
|
||||||
public VideoItemDetailFragment() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -367,8 +364,8 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
try {
|
try {
|
||||||
StreamingService streamingService = ServiceList.getService(
|
StreamingService streamingService = ServiceList.getService(
|
||||||
getArguments().getInt(STREAMING_SERVICE));
|
getArguments().getInt(STREAMING_SERVICE));
|
||||||
videoExtractorThread = new Thread(new VideoExtractorRunnable(
|
Thread videoExtractorThread = new Thread(new VideoExtractorRunnable(
|
||||||
getArguments().getString(VIDEO_URL), streamingService, this));
|
getArguments().getString(VIDEO_URL), streamingService));
|
||||||
|
|
||||||
autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);
|
autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);
|
||||||
videoExtractorThread.start();
|
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.
|
/**Returns the java.util.Locale object which corresponds to the locale set in NewPipe's preferences.
|
||||||
* Currently not affected by the device's locale.*/
|
* Currently not affected by the device's locale.*/
|
||||||
public Locale getPreferredLocale() {
|
private Locale getPreferredLocale() {
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
String languageKey = getContext().getString(R.string.searchLanguage);
|
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");
|
languageCode = sp.getString(languageKey, "en");
|
||||||
|
|
||||||
if(languageCode.length() == 2) {
|
if(languageCode.length() == 2) {
|
||||||
@ -433,7 +432,7 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
return Locale.getDefault();
|
return Locale.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkIfLandscape() {
|
private boolean checkIfLandscape() {
|
||||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||||
return displayMetrics.heightPixels < displayMetrics.widthPixels;
|
return displayMetrics.heightPixels < displayMetrics.widthPixels;
|
||||||
|
@ -6,6 +6,7 @@ import android.os.Bundle;
|
|||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -56,9 +57,9 @@ public class VideoItemListActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private VideoItemListFragment listFragment;
|
private VideoItemListFragment listFragment;
|
||||||
private VideoItemDetailFragment videoFragment = null;
|
private VideoItemDetailFragment videoFragment = null;
|
||||||
Menu menu = null;
|
private Menu menu = null;
|
||||||
|
|
||||||
public class SearchVideoQueryListener implements SearchView.OnQueryTextListener {
|
private class SearchVideoQueryListener implements SearchView.OnQueryTextListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String query) {
|
public boolean onQueryTextSubmit(String query) {
|
||||||
@ -69,8 +70,14 @@ public class VideoItemListActivity extends AppCompatActivity
|
|||||||
// hide virtual keyboard
|
// hide virtual keyboard
|
||||||
InputMethodManager inputManager =
|
InputMethodManager inputManager =
|
||||||
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
inputManager.hideSoftInputFromWindow(
|
try {
|
||||||
getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
|
//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
|
// clear focus
|
||||||
// 1. to not open up the keyboard after switching back to this
|
// 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
|
// 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);
|
ArrayList<VideoPreviewInfo> p = arguments.getParcelableArrayList(VIDEO_INFO_ITEMS);
|
||||||
if(p != null) {
|
if(p != null) {
|
||||||
mode = PRESENT_VIDEOS_MODE;
|
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);
|
listFragment.present(p);
|
||||||
}
|
}
|
||||||
|
@ -64,8 +64,8 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
private ListView list;
|
private ListView list;
|
||||||
|
|
||||||
private class ResultRunnable implements Runnable {
|
private class ResultRunnable implements Runnable {
|
||||||
private SearchEngine.Result result;
|
private final SearchEngine.Result result;
|
||||||
private int requestId;
|
private final int requestId;
|
||||||
public ResultRunnable(SearchEngine.Result result, int requestId) {
|
public ResultRunnable(SearchEngine.Result result, int requestId) {
|
||||||
this.result = result;
|
this.result = result;
|
||||||
this.requestId = requestId;
|
this.requestId = requestId;
|
||||||
@ -77,12 +77,12 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class SearchRunnable implements Runnable {
|
private class SearchRunnable implements Runnable {
|
||||||
private SearchEngine engine;
|
private final SearchEngine engine;
|
||||||
private String query;
|
private final String query;
|
||||||
private int page;
|
private final int page;
|
||||||
Handler h = new Handler();
|
final Handler h = new Handler();
|
||||||
private volatile boolean run = true;
|
private volatile boolean run = true;
|
||||||
private int requestId;
|
private final int requestId;
|
||||||
public SearchRunnable(SearchEngine engine, String query, int page, int requestId) {
|
public SearchRunnable(SearchEngine engine, String query, int page, int requestId) {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
@ -116,11 +116,11 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class LoadThumbsRunnable implements Runnable {
|
private class LoadThumbsRunnable implements Runnable {
|
||||||
private Vector<String> thumbnailUrlList = new Vector<>();
|
private final Vector<String> thumbnailUrlList = new Vector<>();
|
||||||
private Vector<Boolean> downloadedList;
|
private final Vector<Boolean> downloadedList;
|
||||||
Handler h = new Handler();
|
final Handler h = new Handler();
|
||||||
private volatile boolean run = true;
|
private volatile boolean run = true;
|
||||||
private int requestId;
|
private final int requestId;
|
||||||
public LoadThumbsRunnable(Vector<VideoPreviewInfo> videoList,
|
public LoadThumbsRunnable(Vector<VideoPreviewInfo> videoList,
|
||||||
Vector<Boolean> downloadedList, int requestId) {
|
Vector<Boolean> downloadedList, int requestId) {
|
||||||
for(VideoPreviewInfo item : videoList) {
|
for(VideoPreviewInfo item : videoList) {
|
||||||
@ -139,7 +139,7 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
public void run() {
|
public void run() {
|
||||||
for(int i = 0; i < thumbnailUrlList.size() && run; i++) {
|
for(int i = 0; i < thumbnailUrlList.size() && run; i++) {
|
||||||
if(!downloadedList.get(i)) {
|
if(!downloadedList.get(i)) {
|
||||||
Bitmap thumbnail = null;
|
Bitmap thumbnail;
|
||||||
try {
|
try {
|
||||||
thumbnail = BitmapFactory.decodeStream(
|
thumbnail = BitmapFactory.decodeStream(
|
||||||
new URL(thumbnailUrlList.get(i)).openConnection().getInputStream());
|
new URL(thumbnailUrlList.get(i)).openConnection().getInputStream());
|
||||||
@ -153,9 +153,9 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class SetThumbnailRunnable implements Runnable {
|
private class SetThumbnailRunnable implements Runnable {
|
||||||
private int index;
|
private final int index;
|
||||||
private Bitmap thumbnail;
|
private final Bitmap thumbnail;
|
||||||
private int requestId;
|
private final int requestId;
|
||||||
public SetThumbnailRunnable(int index, Bitmap thumbnail, int requestId) {
|
public SetThumbnailRunnable(int index, Bitmap thumbnail, int requestId) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.thumbnail = thumbnail;
|
this.thumbnail = thumbnail;
|
||||||
@ -164,7 +164,7 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if(requestId == currentRequestId) {
|
if(requestId == currentRequestId) {
|
||||||
videoListAdapter.updateDownloadedThumbnailList(index, true);
|
videoListAdapter.updateDownloadedThumbnailList(index);
|
||||||
videoListAdapter.setThumbnail(index, thumbnail);
|
videoListAdapter.setThumbnail(index, thumbnail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
getListView().smoothScrollToPosition(0);
|
getListView().smoothScrollToPosition(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void nextPage() {
|
private void nextPage() {
|
||||||
lastPage++;
|
lastPage++;
|
||||||
Log.d(TAG, getString(R.string.searchPage) + Integer.toString(lastPage));
|
Log.d(TAG, getString(R.string.searchPage) + Integer.toString(lastPage));
|
||||||
startSearch(query, lastPage);
|
startSearch(query, lastPage);
|
||||||
@ -207,7 +207,7 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
this.streamingService = streamingService;
|
this.streamingService = streamingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateListOnResult(SearchEngine.Result result, int requestId) {
|
private void updateListOnResult(SearchEngine.Result result, int requestId) {
|
||||||
if(requestId == currentRequestId) {
|
if(requestId == currentRequestId) {
|
||||||
setListShown(true);
|
setListShown(true);
|
||||||
if (result.resultList.isEmpty()) {
|
if (result.resultList.isEmpty()) {
|
||||||
@ -237,7 +237,7 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void terminateThreads() {
|
private void terminateThreads() {
|
||||||
if(loadThumbsRunnable != null && loadThumbsRunnable.isRunning()) {
|
if(loadThumbsRunnable != null && loadThumbsRunnable.isRunning()) {
|
||||||
loadThumbsRunnable.terminate();
|
loadThumbsRunnable.terminate();
|
||||||
try {
|
try {
|
||||||
@ -276,12 +276,7 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
void onItemSelected(String id);
|
void onItemSelected(String id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Callbacks mCallbacks = null;
|
private Callbacks mCallbacks = null;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
@ -333,11 +328,6 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
mCallbacks = (Callbacks) context;
|
mCallbacks = (Callbacks) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDetach() {
|
|
||||||
super.onDetach();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView listView, View view, int position, long id) {
|
public void onListItemClick(ListView listView, View view, int position, long id) {
|
||||||
super.onListItemClick(listView, view, position, id);
|
super.onListItemClick(listView, view, position, id);
|
||||||
@ -345,22 +335,11 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
mCallbacks.onItemSelected(Long.toString(id));
|
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
|
* Turns on activate-on-click mode. When this mode is on, list items will be
|
||||||
* given the 'activated' state when touched.
|
* 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
|
// When setting CHOICE_MODE_SINGLE, ListView will automatically
|
||||||
// give items the 'activated' state when touched.
|
// give items the 'activated' state when touched.
|
||||||
getListView().setChoiceMode(activateOnItemClick
|
getListView().setChoiceMode(activateOnItemClick
|
||||||
|
@ -32,19 +32,17 @@ import java.util.Vector;
|
|||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
* 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 static final String TAG = VideoListAdapter.class.toString();
|
||||||
|
|
||||||
private Context context;
|
private final Context context;
|
||||||
private VideoInfoItemViewCreator viewCreator;
|
private final VideoInfoItemViewCreator viewCreator;
|
||||||
private Vector<VideoPreviewInfo> videoList = new Vector<>();
|
private Vector<VideoPreviewInfo> videoList = new Vector<>();
|
||||||
private Vector<Boolean> downloadedThumbnailList = new Vector<>();
|
private Vector<Boolean> downloadedThumbnailList = new Vector<>();
|
||||||
VideoItemListFragment videoListFragment;
|
private final ListView listView;
|
||||||
ListView listView;
|
|
||||||
|
|
||||||
public VideoListAdapter(Context context, VideoItemListFragment videoListFragment) {
|
public VideoListAdapter(Context context, VideoItemListFragment videoListFragment) {
|
||||||
viewCreator = new VideoInfoItemViewCreator(LayoutInflater.from(context));
|
viewCreator = new VideoInfoItemViewCreator(LayoutInflater.from(context));
|
||||||
this.videoListFragment = videoListFragment;
|
|
||||||
this.listView = videoListFragment.getListView();
|
this.listView = videoListFragment.getListView();
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
@ -67,8 +65,8 @@ public class VideoListAdapter extends BaseAdapter {
|
|||||||
return videoList;
|
return videoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDownloadedThumbnailList(int index, boolean val) {
|
public void updateDownloadedThumbnailList(int index) {
|
||||||
downloadedThumbnailList.set(index, val);
|
downloadedThumbnailList.set(index, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector<Boolean> getDownloadedThumbnailList() {
|
public Vector<Boolean> getDownloadedThumbnailList() {
|
||||||
|
@ -29,6 +29,7 @@ import org.schabi.newpipe.services.AbstractVideoInfo;
|
|||||||
/**Info object for previews of unopened videos, eg search results, related videos*/
|
/**Info object for previews of unopened videos, eg search results, related videos*/
|
||||||
public class VideoPreviewInfo extends AbstractVideoInfo implements Parcelable {
|
public class VideoPreviewInfo extends AbstractVideoInfo implements Parcelable {
|
||||||
public String duration = "";
|
public String duration = "";
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
protected VideoPreviewInfo(Parcel in) {
|
protected VideoPreviewInfo(Parcel in) {
|
||||||
id = in.readString();
|
id = in.readString();
|
||||||
title = in.readString();
|
title = in.readString();
|
||||||
|
@ -31,7 +31,7 @@ public interface SearchEngine {
|
|||||||
class Result {
|
class Result {
|
||||||
public String errorMessage = "";
|
public String errorMessage = "";
|
||||||
public String suggestion = "";
|
public String suggestion = "";
|
||||||
public Vector<VideoPreviewInfo> resultList = new Vector<>();
|
public final Vector<VideoPreviewInfo> resultList = new Vector<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> suggestionList(String query);
|
ArrayList<String> suggestionList(String query);
|
||||||
|
@ -42,7 +42,7 @@ public class ServiceList {
|
|||||||
}
|
}
|
||||||
public static int getIdOfService(String serviceName) {
|
public static int getIdOfService(String serviceName) {
|
||||||
for(int i = 0; i < services.length; i++) {
|
for(int i = 0; i < services.length; i++) {
|
||||||
if(services[i].getServiceInfo().name == serviceName) {
|
if(services[i].getServiceInfo().name.equals(serviceName)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,10 @@ import org.schabi.newpipe.VideoInfo;
|
|||||||
|
|
||||||
/**Scrapes information from a video streaming service (eg, YouTube).*/
|
/**Scrapes information from a video streaming service (eg, YouTube).*/
|
||||||
public abstract class VideoExtractor {
|
public abstract class VideoExtractor {
|
||||||
public String pageUrl;
|
protected final String pageUrl;
|
||||||
public VideoInfo videoInfo;
|
protected VideoInfo videoInfo;
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public VideoExtractor(String url) {
|
public VideoExtractor(String url) {
|
||||||
this.pageUrl = url;
|
this.pageUrl = url;
|
||||||
}
|
}
|
||||||
@ -99,17 +100,17 @@ public abstract class VideoExtractor {
|
|||||||
return videoInfo;
|
return videoInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getVideoUrl(String videoId);
|
protected abstract String getVideoUrl(String videoId);
|
||||||
public abstract String getVideoId(String siteUrl);
|
protected abstract String getVideoId(String siteUrl);
|
||||||
public abstract int getTimeStamp();
|
protected abstract int getTimeStamp();
|
||||||
public abstract String getTitle();
|
protected abstract String getTitle();
|
||||||
public abstract String getDescription();
|
protected abstract String getDescription();
|
||||||
public abstract String getUploader();
|
protected abstract String getUploader();
|
||||||
public abstract int getLength();
|
protected abstract int getLength();
|
||||||
public abstract int getViews();
|
protected abstract int getViews();
|
||||||
public abstract String getUploadDate();
|
protected abstract String getUploadDate();
|
||||||
public abstract String getThumbnailUrl();
|
protected abstract String getThumbnailUrl();
|
||||||
public abstract String getUploaderThumbnailUrl();
|
protected abstract String getUploaderThumbnailUrl();
|
||||||
public abstract VideoInfo.AudioStream[] getAudioStreams();
|
protected abstract VideoInfo.AudioStream[] getAudioStreams();
|
||||||
public abstract VideoInfo.VideoStream[] getVideoStreams();
|
protected abstract VideoInfo.VideoStream[] getVideoStreams();
|
||||||
}
|
}
|
||||||
|
@ -95,20 +95,18 @@ public class YoutubeSearchEngine implements SearchEngine {
|
|||||||
// both types of spell correction item
|
// both types of spell correction item
|
||||||
if(!((el = item.select("div[class*=\"spell-correction\"]").first()) == null)) {
|
if(!((el = item.select("div[class*=\"spell-correction\"]").first()) == null)) {
|
||||||
result.suggestion = el.select("a").first().text();
|
result.suggestion = el.select("a").first().text();
|
||||||
// search message item
|
// search message item
|
||||||
} else if(!((el = item.select("div[class*=\"search-message\"]").first()) == null)) {
|
} else if(!((el = item.select("div[class*=\"search-message\"]").first()) == null)) {
|
||||||
result.errorMessage = el.text();
|
result.errorMessage = el.text();
|
||||||
|
|
||||||
// video item type
|
// video item type
|
||||||
} else if(!((el = item.select("div[class*=\"yt-lockup-video\"").first()) == null)) {
|
} else if(!((el = item.select("div[class*=\"yt-lockup-video\"").first()) == null)) {
|
||||||
//todo: de-duplicate this with YoutubeVideoExtractor.getVideoPreviewInfo()
|
|
||||||
VideoPreviewInfo resultItem = new VideoPreviewInfo();
|
VideoPreviewInfo resultItem = new VideoPreviewInfo();
|
||||||
Element dl = el.select("h3").first().select("a").first();
|
Element dl = el.select("h3").first().select("a").first();
|
||||||
resultItem.webpage_url = dl.attr("abs:href");
|
resultItem.webpage_url = dl.attr("abs:href");
|
||||||
try {
|
try {
|
||||||
Pattern p = Pattern.compile("v=([0-9a-zA-Z-]*)");
|
Pattern p = Pattern.compile("v=([0-9a-zA-Z-]*)");
|
||||||
Matcher m = p.matcher(resultItem.webpage_url);
|
Matcher m = p.matcher(resultItem.webpage_url);
|
||||||
m.find();
|
|
||||||
resultItem.id=m.group(1);
|
resultItem.id=m.group(1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -134,6 +132,7 @@ public class YoutubeSearchEngine implements SearchEngine {
|
|||||||
}
|
}
|
||||||
result.resultList.add(resultItem);
|
result.resultList.add(resultItem);
|
||||||
} else {
|
} else {
|
||||||
|
//noinspection ConstantConditions
|
||||||
Log.e(TAG, "unexpected element found:\""+el+"\"");
|
Log.e(TAG, "unexpected element found:\""+el+"\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,7 @@ import java.util.regex.Pattern;
|
|||||||
public class YoutubeVideoExtractor extends VideoExtractor {
|
public class YoutubeVideoExtractor extends VideoExtractor {
|
||||||
|
|
||||||
private static final String TAG = YoutubeVideoExtractor.class.toString();
|
private static final String TAG = YoutubeVideoExtractor.class.toString();
|
||||||
private String pageContents;
|
private final Document doc;
|
||||||
private Document doc;
|
|
||||||
private JSONObject jsonObj;
|
private JSONObject jsonObj;
|
||||||
private JSONObject playerArgs;
|
private JSONObject playerArgs;
|
||||||
|
|
||||||
@ -64,7 +63,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
|
|||||||
|
|
||||||
public YoutubeVideoExtractor(String pageUrl) {
|
public YoutubeVideoExtractor(String pageUrl) {
|
||||||
super(pageUrl);//most common videoInfo fields are now set in our superclass, for all services
|
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);
|
doc = Jsoup.parse(pageContents, pageUrl);
|
||||||
|
|
||||||
//attempt to load the youtube js player JSON arguments
|
//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.
|
/**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
|
However if you are looking for a list showing all itag formats, look at
|
||||||
https://github.com/rg3/youtube-dl/issues/1687 */
|
https://github.com/rg3/youtube-dl/issues/1687 */
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public static int resolveFormat(int itag) {
|
public static int resolveFormat(int itag) {
|
||||||
switch(itag) {
|
switch(itag) {
|
||||||
// video
|
// video
|
||||||
@ -285,6 +286,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public static String resolveResolutionString(int itag) {
|
public static String resolveResolutionString(int itag) {
|
||||||
switch(itag) {
|
switch(itag) {
|
||||||
case 17: return "144p";
|
case 17: return "144p";
|
||||||
@ -303,6 +305,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
@Override
|
@Override
|
||||||
public String getVideoId(String url) {
|
public String getVideoId(String url) {
|
||||||
String id;
|
String id;
|
||||||
@ -327,6 +330,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
@Override
|
@Override
|
||||||
public String getVideoUrl(String videoId) {
|
public String getVideoUrl(String videoId) {
|
||||||
return "https://www.youtube.com/watch?v=" + videoId;
|
return "https://www.youtube.com/watch?v=" + videoId;
|
||||||
@ -579,7 +583,10 @@ public class YoutubeVideoExtractor extends VideoExtractor {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Context.exit();
|
Context.exit();
|
||||||
return result.toString();
|
if(result != null)
|
||||||
|
return result.toString();
|
||||||
|
else
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String cleanUrl(String complexUrl) {
|
private String cleanUrl(String complexUrl) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources>
|
||||||
<!-- Categories -->
|
<!-- Categories -->
|
||||||
<string name="settingsCategoryVideoAudio">settings_categoery_video_audio</string>
|
<string name="settingsCategoryVideoAudio">settings_categoery_video_audio</string>
|
||||||
<string name="settingsCategoryVideoInfo">settings_category_video_info</string>
|
<string name="settingsCategoryVideoInfo">settings_category_video_info</string>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<item name="background">@color/primaryColorYoutube</item>
|
<item name="background">@color/primaryColorYoutube</item>
|
||||||
</style>
|
</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:windowFullscreen">false</item>
|
||||||
<item name="android:windowActionBarOverlay">true</item>
|
<item name="android:windowActionBarOverlay">true</item>
|
||||||
<item name="windowActionBarOverlay">true</item>
|
<item name="windowActionBarOverlay">true</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user