Consider protocol as base url when it is a custom one (e.g. vnd.youtube)
This commit is contained in:
		
							parent
							
								
									bcc01b99c7
								
							
						
					
					
						commit
						c190a3029b
					
				
					 5 changed files with 17 additions and 33 deletions
				
			
		|  | @ -55,12 +55,6 @@ public class YoutubeParsingHelper { | ||||||
|     private YoutubeParsingHelper() { |     private YoutubeParsingHelper() { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * The official youtube app supports intents in this format, where after the ':' is the videoId. |  | ||||||
|      * Accordingly there are other apps sharing streams in this format. |  | ||||||
|      */ |  | ||||||
|     public final static String BASE_YOUTUBE_INTENT_URL = "vnd.youtube"; |  | ||||||
| 
 |  | ||||||
|     private static final String HARDCODED_CLIENT_VERSION = "2.20200214.04.00"; |     private static final String HARDCODED_CLIENT_VERSION = "2.20200214.04.00"; | ||||||
|     private static String clientVersion; |     private static String clientVersion; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,10 +1,7 @@ | ||||||
| package org.schabi.newpipe.extractor.services.youtube.linkHandler; | package org.schabi.newpipe.extractor.services.youtube.linkHandler; | ||||||
| 
 | 
 | ||||||
| import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.BASE_YOUTUBE_INTENT_URL; |  | ||||||
| 
 |  | ||||||
| import org.schabi.newpipe.extractor.exceptions.FoundAdException; | import org.schabi.newpipe.extractor.exceptions.FoundAdException; | ||||||
| import org.schabi.newpipe.extractor.exceptions.ParsingException; | import org.schabi.newpipe.extractor.exceptions.ParsingException; | ||||||
| import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; |  | ||||||
| import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; | import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; | ||||||
| 
 | 
 | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  | @ -17,15 +14,6 @@ public class YoutubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory { | ||||||
|         return instance; |         return instance; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |  | ||||||
|     public ListLinkHandler fromUrl(String url) throws ParsingException { |  | ||||||
|         if (url.startsWith(BASE_YOUTUBE_INTENT_URL)){ |  | ||||||
|             return super.fromUrl(url, BASE_YOUTUBE_INTENT_URL); |  | ||||||
|         } else { |  | ||||||
|             return super.fromUrl(url); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public String getUrl(String id) { |     public String getUrl(String id) { | ||||||
|         return "https://m.youtube.com/watch?v=" + id; |         return "https://m.youtube.com/watch?v=" + id; | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ package org.schabi.newpipe.extractor.services.youtube.linkHandler; | ||||||
| 
 | 
 | ||||||
| import org.schabi.newpipe.extractor.exceptions.FoundAdException; | import org.schabi.newpipe.extractor.exceptions.FoundAdException; | ||||||
| import org.schabi.newpipe.extractor.exceptions.ParsingException; | import org.schabi.newpipe.extractor.exceptions.ParsingException; | ||||||
| import org.schabi.newpipe.extractor.linkhandler.LinkHandler; |  | ||||||
| import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; | import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; | ||||||
| import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; | import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; | ||||||
| import org.schabi.newpipe.extractor.utils.Utils; | import org.schabi.newpipe.extractor.utils.Utils; | ||||||
|  | @ -15,8 +14,6 @@ import java.net.URL; | ||||||
| import java.util.regex.Matcher; | import java.util.regex.Matcher; | ||||||
| import java.util.regex.Pattern; | import java.util.regex.Pattern; | ||||||
| 
 | 
 | ||||||
| import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.BASE_YOUTUBE_INTENT_URL; |  | ||||||
| 
 |  | ||||||
| /* | /* | ||||||
|  * Created by Christian Schabesberger on 02.02.16. |  * Created by Christian Schabesberger on 02.02.16. | ||||||
|  * |  * | ||||||
|  | @ -67,15 +64,6 @@ public class YoutubeStreamLinkHandlerFactory extends LinkHandlerFactory { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |  | ||||||
|     public LinkHandler fromUrl(String url) throws ParsingException { |  | ||||||
|         if (url.startsWith(BASE_YOUTUBE_INTENT_URL)) { |  | ||||||
|             return super.fromUrl(url, BASE_YOUTUBE_INTENT_URL); |  | ||||||
|         } else { |  | ||||||
|             return super.fromUrl(url); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public String getUrl(String id) { |     public String getUrl(String id) { | ||||||
|         return "https://www.youtube.com/watch?v=" + id; |         return "https://www.youtube.com/watch?v=" + id; | ||||||
|  |  | ||||||
|  | @ -182,13 +182,18 @@ public class Utils { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static String getBaseUrl(String url) throws ParsingException { |     public static String getBaseUrl(String url) throws ParsingException { | ||||||
|         URL uri; |  | ||||||
|         try { |         try { | ||||||
|             uri = stringToURL(url); |             final URL uri = stringToURL(url); | ||||||
|  |             return uri.getProtocol() + "://" + uri.getAuthority(); | ||||||
|         } catch (MalformedURLException e) { |         } catch (MalformedURLException e) { | ||||||
|  |             final String message = e.getMessage(); | ||||||
|  |             if (message.startsWith("unknown protocol: ")) { | ||||||
|  |                 System.out.println(message.substring(18)); | ||||||
|  |                 return message.substring(18); // return just the protocol (e.g. vnd.youtube) | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|             throw new ParsingException("Malformed url: " + url, e); |             throw new ParsingException("Malformed url: " + url, e); | ||||||
|         } |         } | ||||||
|         return uri.getProtocol() + "://" + uri.getAuthority(); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static boolean isNullOrEmpty(final String str) { |     public static boolean isNullOrEmpty(final String str) { | ||||||
|  |  | ||||||
|  | @ -21,4 +21,13 @@ public class UtilsTest { | ||||||
|     public void testJoin() { |     public void testJoin() { | ||||||
|         assertEquals("some,random,stuff", Utils.join(",", Arrays.asList("some", "random", "stuff"))); |         assertEquals("some,random,stuff", Utils.join(",", Arrays.asList("some", "random", "stuff"))); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     @Test | ||||||
|  |     public void testGetBaseUrl() throws ParsingException { | ||||||
|  |         assertEquals("https://www.youtube.com", Utils.getBaseUrl("https://www.youtube.com/watch?v=Hu80uDzh8RY")); | ||||||
|  |         assertEquals("vnd.youtube", Utils.getBaseUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI")); | ||||||
|  |         assertEquals("vnd.youtube", Utils.getBaseUrl("vnd.youtube:jZViOEv90dI")); | ||||||
|  |         assertEquals("vnd.youtube", Utils.getBaseUrl("vnd.youtube://n8X9_MgEdCg")); | ||||||
|  |         assertEquals("https://music.youtube.com", Utils.getBaseUrl("https://music.youtube.com/watch?v=O0EDx9WAelc")); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue