mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	add streamtype field
This commit is contained in:
		| @@ -76,6 +76,7 @@ public abstract class StreamExtractor { | |||||||
|     public abstract List<StreamPreviewInfo> getRelatedVideos() throws ParsingException; |     public abstract List<StreamPreviewInfo> getRelatedVideos() throws ParsingException; | ||||||
|     public abstract StreamUrlIdHandler getUrlIdConverter(); |     public abstract StreamUrlIdHandler getUrlIdConverter(); | ||||||
|     public abstract String getPageUrl(); |     public abstract String getPageUrl(); | ||||||
|  |     public abstract StreamInfo.StreamType getStreamType() throws ParsingException; | ||||||
|     public int getServiceId() { |     public int getServiceId() { | ||||||
|         return serviceId; |         return serviceId; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -34,6 +34,38 @@ public class StreamInfo extends AbstractVideoInfo { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public StreamInfo() {} | ||||||
|  |  | ||||||
|  |     /**Creates a new StreamInfo object from an existing AbstractVideoInfo. | ||||||
|  |      * All the shared properties are copied to the new StreamInfo.*/ | ||||||
|  |     @SuppressWarnings("WeakerAccess") | ||||||
|  |     public StreamInfo(AbstractVideoInfo avi) { | ||||||
|  |         this.id = avi.id; | ||||||
|  |         this.title = avi.title; | ||||||
|  |         this.uploader = avi.uploader; | ||||||
|  |         this.thumbnail_url = avi.thumbnail_url; | ||||||
|  |         this.thumbnail = avi.thumbnail; | ||||||
|  |         this.webpage_url = avi.webpage_url; | ||||||
|  |         this.upload_date = avi.upload_date; | ||||||
|  |         this.upload_date = avi.upload_date; | ||||||
|  |         this.view_count = avi.view_count; | ||||||
|  |  | ||||||
|  |         //todo: better than this | ||||||
|  |         if(avi instanceof StreamPreviewInfo) { | ||||||
|  |             //shitty String to convert code | ||||||
|  |             /* | ||||||
|  |             String dur = ((StreamPreviewInfo)avi).duration; | ||||||
|  |             int minutes = Integer.parseInt(dur.substring(0, dur.indexOf(":"))); | ||||||
|  |             int seconds = Integer.parseInt(dur.substring(dur.indexOf(":")+1, dur.length())); | ||||||
|  |             */ | ||||||
|  |             this.duration = ((StreamPreviewInfo)avi).duration; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void addException(Exception e) { | ||||||
|  |         errors.add(e); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /**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 StreamInfo getVideoInfo(StreamExtractor extractor, Downloader downloader) |     public static StreamInfo getVideoInfo(StreamExtractor extractor, Downloader downloader) | ||||||
| @@ -57,14 +89,18 @@ public class StreamInfo extends AbstractVideoInfo { | |||||||
|  |  | ||||||
|         streamInfo.service_id = extractor.getServiceId(); |         streamInfo.service_id = extractor.getServiceId(); | ||||||
|         streamInfo.webpage_url = extractor.getPageUrl(); |         streamInfo.webpage_url = extractor.getPageUrl(); | ||||||
|  |         streamInfo.stream_type = extractor.getStreamType(); | ||||||
|         streamInfo.id = uiconv.getVideoId(extractor.getPageUrl()); |         streamInfo.id = uiconv.getVideoId(extractor.getPageUrl()); | ||||||
|         streamInfo.title = extractor.getTitle(); |         streamInfo.title = extractor.getTitle(); | ||||||
|         streamInfo.age_limit = extractor.getAgeLimit(); |         streamInfo.age_limit = extractor.getAgeLimit(); | ||||||
|  |  | ||||||
|         if((streamInfo.webpage_url == null || streamInfo.webpage_url.isEmpty()) |         if((streamInfo.stream_type == StreamType.NONE) | ||||||
|  |                 || (streamInfo.webpage_url == null || streamInfo.webpage_url.isEmpty()) | ||||||
|                 || (streamInfo.id == null || streamInfo.id.isEmpty()) |                 || (streamInfo.id == null || streamInfo.id.isEmpty()) | ||||||
|                 || (streamInfo.title == null /* streamInfo.title can be empty of course */) |                 || (streamInfo.title == null /* streamInfo.title can be empty of course */) | ||||||
|                 || (streamInfo.age_limit == -1)); |                 || (streamInfo.age_limit == -1)) { | ||||||
|  |             throw new ExtractionException("Some importand stream information was not given."); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return streamInfo; |         return streamInfo; | ||||||
|     } |     } | ||||||
| @@ -202,15 +238,20 @@ public class StreamInfo extends AbstractVideoInfo { | |||||||
|         } catch(Exception e) { |         } catch(Exception e) { | ||||||
|             streamInfo.addException(e); |             streamInfo.addException(e); | ||||||
|         } |         } | ||||||
|         try { |  | ||||||
|  |  | ||||||
|         } catch (Exception e) { |  | ||||||
|             streamInfo.addException(e); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return streamInfo; |         return streamInfo; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static enum StreamType { | ||||||
|  |         NONE,   // placeholder to check if stream type was checked or not | ||||||
|  |         VIDEO_STREAM, | ||||||
|  |         AUDIO_STREAM, | ||||||
|  |         LIVE_STREAM, | ||||||
|  |         AUDIO_LIVE_STREAM, | ||||||
|  |         FILE | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public StreamType stream_type; | ||||||
|     public String uploader_thumbnail_url = ""; |     public String uploader_thumbnail_url = ""; | ||||||
|     public String description = ""; |     public String description = ""; | ||||||
|  |  | ||||||
| @@ -234,36 +275,4 @@ public class StreamInfo extends AbstractVideoInfo { | |||||||
|     public int start_position = 0; |     public int start_position = 0; | ||||||
|  |  | ||||||
|     public List<Exception> errors = new Vector<>(); |     public List<Exception> errors = new Vector<>(); | ||||||
|  |  | ||||||
|     public StreamInfo() {} |  | ||||||
|  |  | ||||||
|     public void addException(Exception e) { |  | ||||||
|         errors.add(e); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /**Creates a new StreamInfo object from an existing AbstractVideoInfo. |  | ||||||
|      * All the shared properties are copied to the new StreamInfo.*/ |  | ||||||
|     @SuppressWarnings("WeakerAccess") |  | ||||||
|     public StreamInfo(AbstractVideoInfo avi) { |  | ||||||
|         this.id = avi.id; |  | ||||||
|         this.title = avi.title; |  | ||||||
|         this.uploader = avi.uploader; |  | ||||||
|         this.thumbnail_url = avi.thumbnail_url; |  | ||||||
|         this.thumbnail = avi.thumbnail; |  | ||||||
|         this.webpage_url = avi.webpage_url; |  | ||||||
|         this.upload_date = avi.upload_date; |  | ||||||
|         this.upload_date = avi.upload_date; |  | ||||||
|         this.view_count = avi.view_count; |  | ||||||
|  |  | ||||||
|         //todo: better than this |  | ||||||
|         if(avi instanceof StreamPreviewInfo) { |  | ||||||
|             //shitty String to convert code |  | ||||||
|             /* |  | ||||||
|             String dur = ((StreamPreviewInfo)avi).duration; |  | ||||||
|             int minutes = Integer.parseInt(dur.substring(0, dur.indexOf(":"))); |  | ||||||
|             int seconds = Integer.parseInt(dur.substring(dur.indexOf(":")+1, dur.length())); |  | ||||||
|             */ |  | ||||||
|             this.duration = ((StreamPreviewInfo)avi).duration; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| @@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.ExtractionException; | |||||||
| 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; | ||||||
|  | import org.schabi.newpipe.extractor.StreamInfo; | ||||||
| import org.schabi.newpipe.extractor.StreamPreviewInfo; | import org.schabi.newpipe.extractor.StreamPreviewInfo; | ||||||
| import org.schabi.newpipe.extractor.StreamUrlIdHandler; | import org.schabi.newpipe.extractor.StreamUrlIdHandler; | ||||||
| import org.schabi.newpipe.extractor.StreamExtractor; | import org.schabi.newpipe.extractor.StreamExtractor; | ||||||
| @@ -510,7 +511,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { | |||||||
|                     } |                     } | ||||||
|                 } catch (Exception e) { |                 } catch (Exception e) { | ||||||
|                     //todo: dont log throw an error |                     //todo: dont log throw an error | ||||||
|                     System.err.println( "Could not get Video stream."); |                     System.err.println("Could not get Video stream."); | ||||||
|                     e.printStackTrace(); |                     e.printStackTrace(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @@ -672,6 +673,12 @@ public class YoutubeStreamExtractor extends StreamExtractor { | |||||||
|         return pageUrl; |         return pageUrl; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public StreamInfo.StreamType getStreamType() throws ParsingException { | ||||||
|  |         //todo: if implementing livestream support this value should be generated dynamically | ||||||
|  |         return StreamInfo.StreamType.VIDEO_STREAM; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /**Provides information about links to other videos on the video page, such as related videos. |     /**Provides information about links to other videos on the video page, such as related videos. | ||||||
|      * This is encapsulated in a StreamPreviewInfo object, |      * This is encapsulated in a StreamPreviewInfo object, | ||||||
|      * which is a subset of the fields in a full StreamInfo.*/ |      * which is a subset of the fields in a full StreamInfo.*/ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Christian Schabesberger
					Christian Schabesberger