mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-24 17:10:33 +00:00
made the ui react on missing information
This commit is contained in:
parent
77850464d4
commit
a94f9fd3e5
@ -3,7 +3,7 @@ package org.schabi.newpipe.services.youtube;
|
|||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
import org.schabi.newpipe.Downloader;
|
import org.schabi.newpipe.Downloader;
|
||||||
import org.schabi.newpipe.extractor.CrawlingException;
|
import org.schabi.newpipe.extractor.ExctractionException;
|
||||||
import org.schabi.newpipe.extractor.ParsingException;
|
import org.schabi.newpipe.extractor.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
|
||||||
import org.schabi.newpipe.extractor.VideoInfo;
|
import org.schabi.newpipe.extractor.VideoInfo;
|
||||||
@ -33,7 +33,7 @@ import java.io.IOException;
|
|||||||
public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase {
|
public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase {
|
||||||
private YoutubeStreamExtractor extractor;
|
private YoutubeStreamExtractor extractor;
|
||||||
|
|
||||||
public void setUp() throws IOException, CrawlingException {
|
public void setUp() throws IOException, ExctractionException {
|
||||||
/* some anonymus video test
|
/* some anonymus video test
|
||||||
extractor = new YoutubeStreamExtractor("https://www.youtube.com/watch?v=FmG385_uUys",
|
extractor = new YoutubeStreamExtractor("https://www.youtube.com/watch?v=FmG385_uUys",
|
||||||
new Downloader()); */
|
new Downloader()); */
|
||||||
@ -47,7 +47,7 @@ public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase {
|
|||||||
extractor.getTimeStamp() <= 0);
|
extractor.getTimeStamp() <= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetValidTimeStamp() throws CrawlingException, IOException {
|
public void testGetValidTimeStamp() throws ExctractionException, IOException {
|
||||||
YoutubeStreamExtractor extractor =
|
YoutubeStreamExtractor extractor =
|
||||||
new YoutubeStreamExtractor("https://youtu.be/FmG385_uUys?t=174", new Downloader());
|
new YoutubeStreamExtractor("https://youtu.be/FmG385_uUys?t=174", new Downloader());
|
||||||
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
||||||
|
@ -3,7 +3,7 @@ package org.schabi.newpipe.services.youtube;
|
|||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
import org.schabi.newpipe.Downloader;
|
import org.schabi.newpipe.Downloader;
|
||||||
import org.schabi.newpipe.extractor.CrawlingException;
|
import org.schabi.newpipe.extractor.ExctractionException;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -35,7 +35,7 @@ public class YoutubeStreamExtractorGemaTest extends AndroidTestCase {
|
|||||||
// Deaktivate this Test Case bevore uploading it githup, otherwise CI will fail.
|
// Deaktivate this Test Case bevore uploading it githup, otherwise CI will fail.
|
||||||
private static final boolean testActive = false;
|
private static final boolean testActive = false;
|
||||||
|
|
||||||
public void testGemaError() throws IOException, CrawlingException {
|
public void testGemaError() throws IOException, ExctractionException {
|
||||||
if(testActive) {
|
if(testActive) {
|
||||||
try {
|
try {
|
||||||
new YoutubeStreamExtractor("https://www.youtube.com/watch?v=3O1_3zBUKM8",
|
new YoutubeStreamExtractor("https://www.youtube.com/watch?v=3O1_3zBUKM8",
|
||||||
|
@ -98,7 +98,7 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
private Bitmap videoThumbnail;
|
private Bitmap videoThumbnail;
|
||||||
|
|
||||||
private View thumbnailWindowLayout;
|
private View thumbnailWindowLayout;
|
||||||
//this only remains dueto downwards compartiblity
|
//this only remains due to downwards compatibility
|
||||||
private FloatingActionButton playVideoButton;
|
private FloatingActionButton playVideoButton;
|
||||||
private final Point initialThumbnailPos = new Point(0, 0);
|
private final Point initialThumbnailPos = new Point(0, 0);
|
||||||
|
|
||||||
@ -224,11 +224,20 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
Button backgroundButton = (Button)
|
Button backgroundButton = (Button)
|
||||||
activity.findViewById(R.id.detailVideoThumbnailWindowBackgroundButton);
|
activity.findViewById(R.id.detailVideoThumbnailWindowBackgroundButton);
|
||||||
View topView = activity.findViewById(R.id.detailTopView);
|
View topView = activity.findViewById(R.id.detailTopView);
|
||||||
View nextVideoView = videoItemViewCreator
|
View nextVideoView = null;
|
||||||
|
if(info.next_video != null) {
|
||||||
|
nextVideoView = videoItemViewCreator
|
||||||
.getViewFromVideoInfoItem(null, nextVideoFrame, info.next_video, getContext());
|
.getViewFromVideoInfoItem(null, nextVideoFrame, info.next_video, getContext());
|
||||||
|
} else {
|
||||||
|
activity.findViewById(R.id.detailNextVidButtonAndContentLayout).setVisibility(View.GONE);
|
||||||
|
activity.findViewById(R.id.detailNextVideoTitle).setVisibility(View.GONE);
|
||||||
|
activity.findViewById(R.id.detailNextVideoButton).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
|
if(nextVideoView != null) {
|
||||||
nextVideoFrame.addView(nextVideoView);
|
nextVideoFrame.addView(nextVideoView);
|
||||||
|
}
|
||||||
|
|
||||||
initThumbnailViews(info, nextVideoFrame);
|
initThumbnailViews(info, nextVideoFrame);
|
||||||
|
|
||||||
@ -265,14 +274,43 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
uploaderView.setText(info.uploader);
|
// Since newpipe is designed to work even if certain information is not available,
|
||||||
|
// the UI has to react on missing information.
|
||||||
videoTitleView.setText(info.title);
|
videoTitleView.setText(info.title);
|
||||||
|
if(!info.uploader.isEmpty()) {
|
||||||
uploaderView.setText(info.uploader);
|
uploaderView.setText(info.uploader);
|
||||||
|
} else {
|
||||||
|
activity.findViewById(R.id.detailUploaderWrapView).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if(info.view_count >= 0) {
|
||||||
viewCountView.setText(Localization.localizeViewCount(info.view_count, c));
|
viewCountView.setText(Localization.localizeViewCount(info.view_count, c));
|
||||||
thumbsUpView.setText(Localization.localizeNumber(info.like_count, c));
|
} else {
|
||||||
|
viewCountView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if(info.dislike_count >= 0) {
|
||||||
thumbsDownView.setText(Localization.localizeNumber(info.dislike_count, c));
|
thumbsDownView.setText(Localization.localizeNumber(info.dislike_count, c));
|
||||||
|
} else {
|
||||||
|
thumbsDownView.setVisibility(View.INVISIBLE);
|
||||||
|
activity.findViewById(R.id.detailThumbsDownImgView).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if(info.like_count >= 0) {
|
||||||
|
thumbsUpView.setText(Localization.localizeNumber(info.like_count, c));
|
||||||
|
} else {
|
||||||
|
thumbsUpView.setVisibility(View.GONE);
|
||||||
|
activity.findViewById(R.id.detailThumbsUpImgView).setVisibility(View.GONE);
|
||||||
|
thumbsDownView.setVisibility(View.GONE);
|
||||||
|
activity.findViewById(R.id.detailThumbsDownImgView).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if(!info.upload_date.isEmpty()) {
|
||||||
uploadDateView.setText(Localization.localizeDate(info.upload_date, c));
|
uploadDateView.setText(Localization.localizeDate(info.upload_date, c));
|
||||||
|
} else {
|
||||||
|
uploadDateView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if(!info.description.isEmpty()) {
|
||||||
descriptionView.setText(Html.fromHtml(info.description));
|
descriptionView.setText(Html.fromHtml(info.description));
|
||||||
|
} else {
|
||||||
|
descriptionView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
descriptionView.setMovementMethod(LinkMovementMethod.getInstance());
|
descriptionView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
@ -299,7 +337,12 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
});
|
});
|
||||||
textContentLayout.setVisibility(View.VISIBLE);
|
textContentLayout.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if(info.related_videos != null && !info.related_videos.isEmpty()) {
|
||||||
initSimilarVideos(info, videoItemViewCreator);
|
initSimilarVideos(info, videoItemViewCreator);
|
||||||
|
} else {
|
||||||
|
activity.findViewById(R.id.detailSimilarTitle).setVisibility(View.GONE);
|
||||||
|
activity.findViewById(R.id.similarVideosView).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
if(autoPlayEnabled) {
|
if(autoPlayEnabled) {
|
||||||
playVideo(info);
|
playVideo(info);
|
||||||
@ -335,6 +378,7 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
ImageView nextVideoThumb =
|
ImageView nextVideoThumb =
|
||||||
(ImageView) nextVideoFrame.findViewById(R.id.itemThumbnailView);
|
(ImageView) nextVideoFrame.findViewById(R.id.itemThumbnailView);
|
||||||
|
|
||||||
|
if(info.thumbnail_url != null && !info.thumbnail_url.isEmpty()) {
|
||||||
imageLoader.displayImage(info.thumbnail_url, videoThumbnailView,
|
imageLoader.displayImage(info.thumbnail_url, videoThumbnailView,
|
||||||
displayImageOptions, new ImageLoadingListener() {
|
displayImageOptions, new ImageLoadingListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -357,11 +401,18 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
public void onLoadingCancelled(String imageUri, View view) {
|
public void onLoadingCancelled(String imageUri, View view) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
videoThumbnailView.setImageResource(R.drawable.dummy_thumbnail_dark);
|
||||||
|
}
|
||||||
|
if(info.uploader_thumbnail_url != null && !info.uploader_thumbnail_url.isEmpty()) {
|
||||||
imageLoader.displayImage(info.uploader_thumbnail_url,
|
imageLoader.displayImage(info.uploader_thumbnail_url,
|
||||||
uploaderThumb, displayImageOptions, new ThumbnailLoadingListener());
|
uploaderThumb, displayImageOptions, new ThumbnailLoadingListener());
|
||||||
|
}
|
||||||
|
if(info.thumbnail_url != null && !info.thumbnail_url.isEmpty()) {
|
||||||
imageLoader.displayImage(info.next_video.thumbnail_url,
|
imageLoader.displayImage(info.next_video.thumbnail_url,
|
||||||
nextVideoThumb, displayImageOptions, new ThumbnailLoadingListener());
|
nextVideoThumb, displayImageOptions, new ThumbnailLoadingListener());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setupActionBarHandler(final VideoInfo info) {
|
private void setupActionBarHandler(final VideoInfo info) {
|
||||||
actionBarHandler.setupStreamList(info.video_streams);
|
actionBarHandler.setupStreamList(info.video_streams);
|
||||||
|
@ -16,7 +16,7 @@ import android.widget.Toast;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.CrawlingException;
|
import org.schabi.newpipe.extractor.ExctractionException;
|
||||||
import org.schabi.newpipe.extractor.VideoPreviewInfo;
|
import org.schabi.newpipe.extractor.VideoPreviewInfo;
|
||||||
import org.schabi.newpipe.extractor.SearchEngine;
|
import org.schabi.newpipe.extractor.SearchEngine;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
@ -115,7 +115,7 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
postNewErrorToast(h, R.string.network_error);
|
postNewErrorToast(h, R.string.network_error);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch(CrawlingException ce) {
|
} catch(ExctractionException ce) {
|
||||||
postNewErrorToast(h, R.string.parsing_error);
|
postNewErrorToast(h, R.string.parsing_error);
|
||||||
ce.printStackTrace();
|
ce.printStackTrace();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
@ -4,7 +4,7 @@ package org.schabi.newpipe.extractor;
|
|||||||
* Created by Christian Schabesberger on 30.01.16.
|
* Created by Christian Schabesberger on 30.01.16.
|
||||||
*
|
*
|
||||||
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
||||||
* CrawlingException.java is part of NewPipe.
|
* ExctractionException.java is part of NewPipe.
|
||||||
*
|
*
|
||||||
* NewPipe is free software: you can redistribute it and/or modify
|
* NewPipe is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -20,18 +20,18 @@ package org.schabi.newpipe.extractor;
|
|||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CrawlingException extends Exception {
|
public class ExctractionException extends Exception {
|
||||||
public CrawlingException() {}
|
public ExctractionException() {}
|
||||||
|
|
||||||
public CrawlingException(String message) {
|
public ExctractionException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CrawlingException(Throwable cause) {
|
public ExctractionException(Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CrawlingException(String message, Throwable cause) {
|
public ExctractionException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ package org.schabi.newpipe.extractor;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class ParsingException extends CrawlingException {
|
public class ParsingException extends ExctractionException {
|
||||||
public ParsingException() {}
|
public ParsingException() {}
|
||||||
public ParsingException(String message) {
|
public ParsingException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
@ -34,9 +34,9 @@ public interface SearchEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> suggestionList(String query, Downloader dl)
|
ArrayList<String> suggestionList(String query, Downloader dl)
|
||||||
throws CrawlingException, IOException;
|
throws ExctractionException, IOException;
|
||||||
|
|
||||||
//Result search(String query, int page);
|
//Result search(String query, int page);
|
||||||
Result search(String query, int page, String contentCountry, Downloader dl)
|
Result search(String query, int page, String contentCountry, Downloader dl)
|
||||||
throws CrawlingException, IOException;
|
throws ExctractionException, IOException;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import java.util.List;
|
|||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL")
|
||||||
public interface StreamExtractor {
|
public interface StreamExtractor {
|
||||||
|
|
||||||
public class ExctractorInitException extends CrawlingException {
|
public class ExctractorInitException extends ExctractionException {
|
||||||
public ExctractorInitException() {}
|
public ExctractorInitException() {}
|
||||||
public ExctractorInitException(String message) {
|
public ExctractorInitException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
@ -28,7 +28,7 @@ public interface StreamingService {
|
|||||||
}
|
}
|
||||||
ServiceInfo getServiceInfo();
|
ServiceInfo getServiceInfo();
|
||||||
StreamExtractor getExtractorInstance(String url, Downloader downloader)
|
StreamExtractor getExtractorInstance(String url, Downloader downloader)
|
||||||
throws IOException, CrawlingException;
|
throws IOException, ExctractionException;
|
||||||
SearchEngine getSearchEngineInstance();
|
SearchEngine getSearchEngineInstance();
|
||||||
|
|
||||||
VideoUrlIdHandler getUrlIdHandler();
|
VideoUrlIdHandler getUrlIdHandler();
|
||||||
|
@ -31,33 +31,54 @@ public class VideoInfo extends AbstractVideoInfo {
|
|||||||
/**Fills out the video info fields which are common to all services.
|
/**Fills out the video info fields which are common to all services.
|
||||||
* Probably needs to be overridden by subclasses*/
|
* Probably needs to be overridden by subclasses*/
|
||||||
public static VideoInfo getVideoInfo(StreamExtractor extractor, Downloader downloader)
|
public static VideoInfo getVideoInfo(StreamExtractor extractor, Downloader downloader)
|
||||||
throws CrawlingException, IOException {
|
throws ExctractionException, IOException {
|
||||||
VideoInfo videoInfo = new VideoInfo();
|
VideoInfo videoInfo = new VideoInfo();
|
||||||
|
|
||||||
|
videoInfo = extractImportantData(videoInfo, extractor, downloader);
|
||||||
|
videoInfo = extractStreams(videoInfo, extractor, downloader);
|
||||||
|
videoInfo = extractOptionalData(videoInfo, extractor, downloader);
|
||||||
|
|
||||||
|
return videoInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static VideoInfo extractImportantData(
|
||||||
|
VideoInfo videoInfo, StreamExtractor extractor, Downloader downloader)
|
||||||
|
throws ExctractionException, IOException {
|
||||||
|
/* ---- importand data, withoug the video can't be displayed goes here: ---- */
|
||||||
|
// if one of these is not available an exception is ment to be thrown directly into the frontend.
|
||||||
|
|
||||||
VideoUrlIdHandler uiconv = extractor.getUrlIdConverter();
|
VideoUrlIdHandler uiconv = extractor.getUrlIdConverter();
|
||||||
|
|
||||||
|
|
||||||
videoInfo.webpage_url = extractor.getPageUrl();
|
videoInfo.webpage_url = extractor.getPageUrl();
|
||||||
videoInfo.title = extractor.getTitle();
|
|
||||||
videoInfo.duration = extractor.getLength();
|
|
||||||
videoInfo.uploader = extractor.getUploader();
|
|
||||||
videoInfo.description = extractor.getDescription();
|
|
||||||
videoInfo.view_count = extractor.getViews();
|
|
||||||
videoInfo.upload_date = extractor.getUploadDate();
|
|
||||||
videoInfo.thumbnail_url = extractor.getThumbnailUrl();
|
|
||||||
videoInfo.id = uiconv.getVideoId(extractor.getPageUrl());
|
videoInfo.id = uiconv.getVideoId(extractor.getPageUrl());
|
||||||
//todo: make this quick and dirty solution a real fallback
|
videoInfo.title = extractor.getTitle();
|
||||||
// The front end should be notified that the dash mpd could not be downloaded
|
|
||||||
// although not getting the dash mpd is not the end of the world, therfore
|
if((videoInfo.webpage_url == null || videoInfo.webpage_url.isEmpty())
|
||||||
// we continue.
|
|| (videoInfo.id == null || videoInfo.id.isEmpty())
|
||||||
|
|| (videoInfo.title == null /* videoInfo.title can be empty of course */));
|
||||||
|
|
||||||
|
return videoInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static VideoInfo extractStreams(
|
||||||
|
VideoInfo videoInfo, StreamExtractor extractor, Downloader downloader)
|
||||||
|
throws ExctractionException, IOException {
|
||||||
|
/* ---- stream extraction goes here ---- */
|
||||||
|
// At least one type of stream has to be available,
|
||||||
|
// otherwise an exception will be thrown directly into the frontend.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
videoInfo.dashMpdUrl = extractor.getDashMpdUrl();
|
videoInfo.dashMpdUrl = extractor.getDashMpdUrl();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
videoInfo.addException(new ExctractionException("Couldn't get Dash manifest", e));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Load and extract audio*/
|
/* Load and extract audio */
|
||||||
|
try {
|
||||||
videoInfo.audio_streams = extractor.getAudioStreams();
|
videoInfo.audio_streams = extractor.getAudioStreams();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(new ExctractionException("Couldn't get audio streams", e));
|
||||||
|
}
|
||||||
// also try to get streams from the dashMpd
|
// also try to get streams from the dashMpd
|
||||||
if(videoInfo.dashMpdUrl != null && !videoInfo.dashMpdUrl.isEmpty()) {
|
if(videoInfo.dashMpdUrl != null && !videoInfo.dashMpdUrl.isEmpty()) {
|
||||||
if(videoInfo.audio_streams == null) {
|
if(videoInfo.audio_streams == null) {
|
||||||
@ -69,28 +90,115 @@ public class VideoInfo extends AbstractVideoInfo {
|
|||||||
videoInfo.audio_streams.addAll(
|
videoInfo.audio_streams.addAll(
|
||||||
DashMpdParser.getAudioStreams(videoInfo.dashMpdUrl, downloader));
|
DashMpdParser.getAudioStreams(videoInfo.dashMpdUrl, downloader));
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
videoInfo.addException(
|
||||||
|
new ExctractionException("Couldn't get audio streams from dash mpd", e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** Extract video stream url*/
|
/* Extract video stream url*/
|
||||||
|
try {
|
||||||
videoInfo.video_streams = extractor.getVideoStreams();
|
videoInfo.video_streams = extractor.getVideoStreams();
|
||||||
/** Extract video only stream url*/
|
} catch (Exception e) {
|
||||||
|
videoInfo.addException(
|
||||||
|
new ExctractionException("Couldn't get video streams", e));
|
||||||
|
}
|
||||||
|
/* Extract video only stream url*/
|
||||||
|
try {
|
||||||
videoInfo.video_only_streams = extractor.getVideoOnlyStreams();
|
videoInfo.video_only_streams = extractor.getVideoOnlyStreams();
|
||||||
videoInfo.uploader_thumbnail_url = extractor.getUploaderThumbnailUrl();
|
} catch(Exception e) {
|
||||||
videoInfo.start_position = extractor.getTimeStamp();
|
videoInfo.addException(
|
||||||
videoInfo.average_rating = extractor.getAverageRating();
|
new ExctractionException("Couldn't get video only streams", e));
|
||||||
videoInfo.like_count = extractor.getLikeCount();
|
}
|
||||||
videoInfo.dislike_count = extractor.getDislikeCount();
|
|
||||||
videoInfo.next_video = extractor.getNextVideo();
|
// either dash_mpd audio_only or video has to be available, otherwise we didn't get a stream,
|
||||||
videoInfo.related_videos = extractor.getRelatedVideos();
|
// and therefore failed. (Since video_only_streams are just optional they don't caunt).
|
||||||
|
if((videoInfo.video_streams == null || videoInfo.video_streams.isEmpty())
|
||||||
|
&& (videoInfo.audio_streams == null || videoInfo.audio_streams.isEmpty())
|
||||||
|
&& (videoInfo.dashMpdUrl == null || videoInfo.dashMpdUrl.isEmpty())) {
|
||||||
|
throw new ExctractionException("Could not get any stream. See error variable to get further details.");
|
||||||
|
}
|
||||||
|
|
||||||
return videoInfo;
|
return videoInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static VideoInfo extractOptionalData(
|
||||||
|
VideoInfo videoInfo, StreamExtractor extractor, Downloader downloader) {
|
||||||
|
/* ---- optional data goes here: ---- */
|
||||||
|
// If one of these failes, the frontend neets to handle that they are not available.
|
||||||
|
// Exceptions are therfore not thrown into the frontend, but stored into the error List,
|
||||||
|
// so the frontend can afterwads check where errors happend.
|
||||||
|
|
||||||
|
try {
|
||||||
|
videoInfo.thumbnail_url = extractor.getThumbnailUrl();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.duration = extractor.getLength();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.uploader = extractor.getUploader();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.description = extractor.getDescription();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.view_count = extractor.getViews();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.upload_date = extractor.getUploadDate();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.uploader_thumbnail_url = extractor.getUploaderThumbnailUrl();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.start_position = extractor.getTimeStamp();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.average_rating = extractor.getAverageRating();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.like_count = extractor.getLikeCount();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.dislike_count = extractor.getDislikeCount();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.next_video = extractor.getNextVideo();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
videoInfo.related_videos = extractor.getRelatedVideos();
|
||||||
|
} catch(Exception e) {
|
||||||
|
videoInfo.addException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return videoInfo;
|
||||||
|
}
|
||||||
|
|
||||||
public String uploader_thumbnail_url = "";
|
public String uploader_thumbnail_url = "";
|
||||||
public String description = "";
|
public String description = "";
|
||||||
/*todo: make this lists over vectors*/
|
|
||||||
public List<VideoStream> video_streams = null;
|
public List<VideoStream> video_streams = null;
|
||||||
public List<AudioStream> audio_streams = null;
|
public List<AudioStream> audio_streams = null;
|
||||||
public List<VideoStream> video_only_streams = null;
|
public List<VideoStream> video_only_streams = null;
|
||||||
@ -101,8 +209,6 @@ public class VideoInfo extends AbstractVideoInfo {
|
|||||||
public String dashMpdUrl = "";
|
public String dashMpdUrl = "";
|
||||||
public int duration = -1;
|
public int duration = -1;
|
||||||
|
|
||||||
/*YouTube-specific fields
|
|
||||||
todo: move these to a subclass*/
|
|
||||||
public int age_limit = 0;
|
public int age_limit = 0;
|
||||||
public int like_count = -1;
|
public int like_count = -1;
|
||||||
public int dislike_count = -1;
|
public int dislike_count = -1;
|
||||||
@ -113,6 +219,8 @@ public class VideoInfo extends AbstractVideoInfo {
|
|||||||
public int start_position = 0;
|
public int start_position = 0;
|
||||||
//todo: public int service_id = -1;
|
//todo: public int service_id = -1;
|
||||||
|
|
||||||
|
public List<Exception> errors = new Vector<>();
|
||||||
|
|
||||||
public VideoInfo() {}
|
public VideoInfo() {}
|
||||||
|
|
||||||
/**Creates a new VideoInfo object from an existing AbstractVideoInfo.
|
/**Creates a new VideoInfo object from an existing AbstractVideoInfo.
|
||||||
@ -187,4 +295,8 @@ public class VideoInfo extends AbstractVideoInfo {
|
|||||||
&& url == cmp.url;
|
&& url == cmp.url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addException(Exception e) {
|
||||||
|
errors.add(e);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package org.schabi.newpipe.extractor.services.youtube;
|
package org.schabi.newpipe.extractor.services.youtube;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.CrawlingException;
|
import org.schabi.newpipe.extractor.ExctractionException;
|
||||||
import org.schabi.newpipe.extractor.Downloader;
|
import org.schabi.newpipe.extractor.Downloader;
|
||||||
import org.schabi.newpipe.extractor.StreamExtractor;
|
import org.schabi.newpipe.extractor.StreamExtractor;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
@ -39,7 +39,7 @@ public class YoutubeService implements StreamingService {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public StreamExtractor getExtractorInstance(String url, Downloader downloader)
|
public StreamExtractor getExtractorInstance(String url, Downloader downloader)
|
||||||
throws CrawlingException, IOException {
|
throws ExctractionException, IOException {
|
||||||
VideoUrlIdHandler urlIdHandler = new YoutubeVideoUrlIdHandler();
|
VideoUrlIdHandler urlIdHandler = new YoutubeVideoUrlIdHandler();
|
||||||
if(urlIdHandler.acceptUrl(url)) {
|
if(urlIdHandler.acceptUrl(url)) {
|
||||||
return new YoutubeStreamExtractor(url, downloader) ;
|
return new YoutubeStreamExtractor(url, downloader) ;
|
||||||
|
@ -10,7 +10,7 @@ import org.jsoup.nodes.Element;
|
|||||||
import org.mozilla.javascript.Context;
|
import org.mozilla.javascript.Context;
|
||||||
import org.mozilla.javascript.Function;
|
import org.mozilla.javascript.Function;
|
||||||
import org.mozilla.javascript.ScriptableObject;
|
import org.mozilla.javascript.ScriptableObject;
|
||||||
import org.schabi.newpipe.extractor.CrawlingException;
|
import org.schabi.newpipe.extractor.ExctractionException;
|
||||||
import org.schabi.newpipe.extractor.Downloader;
|
import org.schabi.newpipe.extractor.Downloader;
|
||||||
import org.schabi.newpipe.extractor.Parser;
|
import org.schabi.newpipe.extractor.Parser;
|
||||||
import org.schabi.newpipe.extractor.ParsingException;
|
import org.schabi.newpipe.extractor.ParsingException;
|
||||||
@ -173,7 +173,7 @@ public class YoutubeStreamExtractor implements StreamExtractor {
|
|||||||
|
|
||||||
private Downloader downloader;
|
private Downloader downloader;
|
||||||
|
|
||||||
public YoutubeStreamExtractor(String pageUrl, Downloader dl) throws CrawlingException, IOException {
|
public YoutubeStreamExtractor(String pageUrl, Downloader dl) throws ExctractionException, IOException {
|
||||||
//most common videoInfo fields are now set in our superclass, for all services
|
//most common videoInfo fields are now set in our superclass, for all services
|
||||||
downloader = dl;
|
downloader = dl;
|
||||||
this.pageUrl = pageUrl;
|
this.pageUrl = pageUrl;
|
||||||
|
@ -266,10 +266,10 @@
|
|||||||
android:layout_below="@id/detailNextVidButtonAndContentLayout"
|
android:layout_below="@id/detailNextVidButtonAndContentLayout"
|
||||||
android:textAllCaps="true" />
|
android:textAllCaps="true" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/similarVideosView"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/similarVideosView"
|
|
||||||
android:layout_below="@id/detailSimilarTitle">
|
android:layout_below="@id/detailSimilarTitle">
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user