2018-09-01 13:48:12 +00:00
<!DOCTYPE html>
2022-08-28 11:42:37 +00:00
<!-- [if IE 8]><html class="no - js lt - ie9" lang="en" > <![endif] -->
<!-- [if gt IE 8]><! --> < html class = "no-js" lang = "en" > <!-- <![endif] -->
2018-09-01 13:48:12 +00:00
< head >
2022-08-28 11:42:37 +00:00
< meta charset = "utf-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< link rel = "shortcut icon" href = "../img/favicon.ico" >
< title > Concept of the LinkHandler - NewPipe Development Documentation< / title >
2018-09-08 17:06:35 +00:00
<!-- local fonts -->
2018-09-01 13:48:12 +00:00
< link rel = "stylesheet" href = "../css/local_fonts.css" type = "text/css" / >
< link rel = "stylesheet" href = "../css/theme.css" type = "text/css" / >
< link rel = "stylesheet" href = "../css/theme_extra.css" type = "text/css" / >
2019-04-07 17:32:19 +00:00
< link rel = "stylesheet" href = "../css/theme_child.css" type = "text/css" / >
2018-09-08 17:06:35 +00:00
<!-- local code syntax highlighting -->
< link rel = "stylesheet" href = "../css/github.min.css" type = "text/css" / >
2018-09-01 13:48:12 +00:00
< link rel = "stylesheet" href = "../css/highlight.css" type = "text/css" / >
< script >
// Current page data
2019-03-01 09:02:33 +00:00
var mkdocs_page_name = "Concept of the LinkHandler";
2018-09-01 13:48:12 +00:00
var mkdocs_page_input_path = "02_Concept_of_LinkHandler.md";
var mkdocs_page_url = null;
< / script >
< script src = "../js/jquery-2.1.1.min.js" defer > < / script >
< script src = "../js/modernizr-2.8.3.min.js" defer > < / script >
2018-09-08 17:06:35 +00:00
< script src = "../js/highlight.min.js" > < / script >
2018-09-01 13:48:12 +00:00
< script > hljs . initHighlightingOnLoad ( ) ; < / script >
< / head >
< body class = "wy-body-for-nav" role = "document" >
< div class = "wy-grid-for-nav" >
2022-08-28 11:42:37 +00:00
2018-09-01 13:48:12 +00:00
< nav data-toggle = "wy-nav-shift" class = "wy-nav-side stickynav" >
2020-08-13 00:02:52 +00:00
< div class = "wy-side-scroll" >
2018-09-01 13:48:12 +00:00
< div class = "wy-side-nav-search" >
2022-08-28 11:42:37 +00:00
< a href = ".." class = "icon icon-home" > NewPipe Development Documentation< / a >
< div role = "search" >
2018-09-01 13:48:12 +00:00
< form id = "rtd-search-form" class = "wy-form" action = "../search.html" method = "get" >
2021-10-20 23:09:50 +00:00
< input type = "text" name = "q" placeholder = "Search docs" title = "Type search term here" / >
2018-09-01 13:48:12 +00:00
< / form >
< / div >
< / div >
2022-08-28 11:42:37 +00:00
< div class = "wy-menu wy-menu-vertical" data-spy = "affix" role = "navigation" aria-label = "main navigation" >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = ".." > Welcome to the NewPipe Development Docs< / a >
< / li >
< / ul >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../00_Prepare_everything/" > Before You Start< / a >
< / li >
< / ul >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../01_Concept_of_the_extractor/" > Concept of the Extractor< / a >
< / li >
< / ul >
< ul class = "current" >
< li class = "toctree-l1 current" > < a class = "reference internal current" href = "./" > Concept of the LinkHandler< / a >
2020-08-13 00:02:52 +00:00
< ul class = "current" >
< li class = "toctree-l2" > < a class = "reference internal" href = "#important-notes-about-linkhandler" > Important notes about LinkHandler< / a >
< / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "#usage" > Usage< / a >
< / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "#implementation" > Implementation< / a >
< / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "#listlinkhandler-and-searchqueryhandler" > ListLinkHandler and SearchQueryHandler< / a >
2018-09-08 17:06:35 +00:00
< ul >
2020-08-13 00:02:52 +00:00
< li class = "toctree-l3" > < a class = "reference internal" href = "#searchqueryhandler" > SearchQueryHandler< / a >
< / li >
2018-09-08 17:06:35 +00:00
< / ul >
2020-08-13 00:02:52 +00:00
< / li >
2018-09-01 13:48:12 +00:00
< / ul >
2022-08-28 11:42:37 +00:00
< / li >
< / ul >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../03_Implement_a_service/" > Implementing a Service< / a >
< / li >
< / ul >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../04_Run_changes_in_App/" > Testing Your Changes in the App< / a >
< / li >
< / ul >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../05_Mock_tests/" > Mock Tests< / a >
< / li >
< / ul >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../06_releasing/" > Releasing a New NewPipe Version< / a >
< / li >
< / ul >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../07_release_instructions/" > Release instructions for normal releases< / a >
< / li >
< / ul >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../08_documentation/" > About This Documentation< / a >
< / li >
< / ul >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../09_maintainers_view/" > Maintainers' Section< / a >
< / li >
< / ul >
2018-09-01 13:48:12 +00:00
< / div >
2020-08-13 00:02:52 +00:00
< / div >
2018-09-01 13:48:12 +00:00
< / nav >
< section data-toggle = "wy-nav-shift" class = "wy-nav-content-wrap" >
2022-08-28 11:42:37 +00:00
< nav class = "wy-nav-top" role = "navigation" aria-label = "top navigation" >
< i data-toggle = "wy-nav-top" class = "fa fa-bars" > < / i >
< a href = ".." > NewPipe Development Documentation< / a >
2018-09-01 13:48:12 +00:00
< / nav >
2022-08-28 11:42:37 +00:00
2018-09-01 13:48:12 +00:00
< div class = "wy-nav-content" >
2022-08-28 11:42:37 +00:00
< div class = "rst-content" >
< div role = "navigation" aria-label = "breadcrumbs navigation" >
2018-09-01 13:48:12 +00:00
< ul class = "wy-breadcrumbs" >
2022-08-28 11:42:37 +00:00
< li > < a href = ".." > Docs< / a > » < / li >
< li > Concept of the LinkHandler< / li >
2018-09-01 13:48:12 +00:00
< li class = "wy-breadcrumbs-aside" >
2022-08-28 11:42:37 +00:00
2018-09-01 13:48:12 +00:00
< / li >
< / ul >
2022-08-28 11:42:37 +00:00
2018-09-01 13:48:12 +00:00
< hr / >
< / div >
2022-08-28 11:42:37 +00:00
< div role = "main" >
< div class = "section" >
2018-09-01 13:48:12 +00:00
2019-03-01 09:02:33 +00:00
< h1 id = "concept-of-the-linkhandler" > Concept of the LinkHandler< / h1 >
< p > The < a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/LinkHandler.html" > LinkHandler< / a >
represent links to resources like videos, search requests, channels, etc.
The idea is that a video can have multiple links pointing to it, but it has
2018-09-21 20:40:35 +00:00
one unique ID that represents it, like this example:< / p >
2018-09-08 17:06:35 +00:00
< p > < a href = "https://www.youtube.com/watch?v=oHg5SJYRHA0" > oHg5SJYRHA0< / a > can be represented as:< / p >
< ul >
2019-03-01 09:02:33 +00:00
< li > < a href = "https://www.youtube.com/watch?v=oHg5SJYRHA0" > https://www.youtube.com/watch?v=oHg5SJYRHA0< / a > (the default URL for YouTube)< / li >
< li > < a href = "https://youtu.be/oHg5SJYRHA0" > https://youtu.be/oHg5SJYRHA0< / a > (the shortened link)< / li >
< li > < a href = "https://m.youtube.com/watch?v=oHg5SJYRHA0" > https://m.youtube.com/watch?v=oHg5SJYRHA0< / a > (the link for mobile devices)< / li >
2018-09-08 17:06:35 +00:00
< / ul >
2020-03-01 21:17:35 +00:00
< h3 id = "important-notes-about-linkhandler" > Important notes about LinkHandler< / h3 >
2018-09-08 17:06:35 +00:00
< ul >
2019-03-01 09:02:33 +00:00
< li > A simple < code > LinkHandler< / code > will contain the default URL, the ID, and the original URL.< / li >
< li > < code > LinkHandler< / code > s are read only.< / li >
2018-12-14 08:57:47 +00:00
< li > < code > LinkHandler< / code > s are also used to determine which part of the extractor can handle a certain link.< / li >
2018-09-08 17:06:35 +00:00
< li > In order to get one you must either call
2018-09-21 20:40:35 +00:00
< a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.html#fromUrl-java.lang.String-" > fromUrl()< / a > or < a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.html#fromId-java.lang.String-" > fromId()< / a > of the the corresponding < code > LinkHandlerFactory< / code > .< / li >
2019-03-01 09:02:33 +00:00
< li > Every type of resource has its own < code > LinkHandlerFactory< / code > . Eg. YoutubeStreamLinkHandler, YoutubeChannelLinkHandler, etc.< / li >
2018-09-08 17:06:35 +00:00
< / ul >
< h3 id = "usage" > Usage< / h3 >
2019-03-01 09:02:33 +00:00
< p > The typical usage for obtaining a LinkHandler would look like this:< / p >
2021-10-20 23:09:50 +00:00
< pre > < code class = "language-java" > LinkHandlerFactory myLinkHandlerFactory = new MyStreamLinkHandlerFactory();
2018-09-08 17:06:35 +00:00
LinkHandler myVideo = myLinkHandlerFactory.fromUrl(" https://my.service.com/the_video" );
< / code > < / pre >
< h3 id = "implementation" > Implementation< / h3 >
2019-03-01 09:02:33 +00:00
< p > In order to use LinkHandler for your service, you must override the appropriate LinkHandlerFactory. eg:< / p >
2021-10-20 23:09:50 +00:00
< pre > < code class = "language-java" > class MyStreamLinkHandlerFactory extends LinkHandlerFactory {
2018-09-08 17:06:35 +00:00
@Override
public String getId(String url) throws ParsingException {
2018-09-21 20:40:35 +00:00
// Return the ID based on the URL.
2018-09-08 17:06:35 +00:00
}
@Override
public String getUrl(String id) throws ParsingException {
2018-09-21 20:40:35 +00:00
// Return the URL based on the ID given.
2018-09-08 17:06:35 +00:00
}
@Override
public boolean onAcceptUrl(String url) throws ParsingException {
2020-03-01 21:17:35 +00:00
// Return true if this LinkHandlerFactory can handle this type of link.
2018-09-08 17:06:35 +00:00
}
}
< / code > < / pre >
2018-09-08 19:54:53 +00:00
< h3 id = "listlinkhandler-and-searchqueryhandler" > ListLinkHandler and SearchQueryHandler< / h3 >
2019-03-01 09:02:33 +00:00
< p > List based resources, like channels and playlists, can be sorted and filtered.
2018-09-08 19:54:53 +00:00
Therefore these type of resources don't just use a LinkHandler, but a class called
2019-03-01 09:02:33 +00:00
< a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/ListLinkHandler.html" > ListLinkHandler< / a > ,
which inherits from LinkHandler and adds the field < a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/ListLinkHandler.html#contentFilters" > ContentFilter< / a > ,
which is used to filter by resource type, like stream or playlist, and
< a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/ListLinkHandler.html#sortFilter" > SortFilter< / a > ,
which is used to sort by name, date, or view count.< / p >
< p > < strong > !!ATTENTION!!< / strong > Be careful when you implement a content filter: No selected filter equals all filters selected. If your get an empty content filter list in your extractor, make sure you return everything. By all means, use "if"
statements like < code > contentFilter.contains("video") || contentFilter.isEmpty()< / code > .< / p >
2018-09-08 19:54:53 +00:00
< p > ListLinkHandler are also created by overriding the < a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.html" > ListLinkHandlerFactory< / a >
additionally to the abstract methods this factory inherits from the LinkHandlerFactory you can override
< a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.html#getAvailableContentFilter--" > getAvailableContentFilter()< / a >
and < a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.html#getAvailableSortFilter--" > getAvailableSortFilter()< / a > .
2018-12-14 08:57:47 +00:00
Through these you can tell the front end which kind of filter your service supports.< / p >
2018-09-08 19:54:53 +00:00
< h4 id = "searchqueryhandler" > SearchQueryHandler< / h4 >
2018-09-21 20:40:35 +00:00
< p > You cannot point to a search request with an ID like you point to a playlist or a channel, simply because one and the
2018-12-14 08:57:47 +00:00
same search request might have a different outcome depending on the country or the time you send the request. This is
2020-03-01 21:17:35 +00:00
why the idea of an "ID" is replaced by a "SearchString" in the < a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandler.html" > SearchQueryHandler< / a > .
2018-12-14 08:57:47 +00:00
These work like regular ListLinkHandler, except that you don't have to implement the methods < code > onAcceptUrl()< / code >
2018-09-08 19:54:53 +00:00
and < code > getId()< / code > when overriding < a href = "https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandlerFactory.html" > SearchQueryHandlerFactory< / a > .< / p >
2018-09-01 13:48:12 +00:00
< / div >
2022-08-28 11:42:37 +00:00
< / div >
< footer >
< div class = "rst-footer-buttons" role = "navigation" aria-label = "footer navigation" >
2019-03-01 09:02:33 +00:00
< a href = "../03_Implement_a_service/" class = "btn btn-neutral float-right" title = "Implementing a Service" > Next < span class = "icon icon-circle-arrow-right" > < / span > < / a >
2022-08-28 11:42:37 +00:00
< a href = "../01_Concept_of_the_extractor/" class = "btn btn-neutral" title = "Concept of the Extractor" > < span class = "icon icon-circle-arrow-left" > < / span > Previous< / a >
2018-09-01 13:48:12 +00:00
< / div >
2022-08-28 11:42:37 +00:00
2018-09-01 13:48:12 +00:00
< hr / >
< div role = "contentinfo" >
<!-- Copyright etc -->
2022-08-28 11:42:37 +00:00
2018-09-01 13:48:12 +00:00
< / div >
2022-08-28 11:42:37 +00:00
Built with < a href = "https://www.mkdocs.org/" > MkDocs< / a > using a < a href = "https://github.com/snide/sphinx_rtd_theme" > theme< / a > provided by < a href = "https://readthedocs.org" > Read the Docs< / a > .
2018-09-01 13:48:12 +00:00
< / footer >
2022-08-28 11:42:37 +00:00
2018-09-01 13:48:12 +00:00
< / div >
< / div >
< / section >
< / div >
2022-08-28 11:42:37 +00:00
< div class = "rst-versions" role = "note" aria-label = "versions" >
2021-10-20 23:09:50 +00:00
< span class = "rst-current-version" data-toggle = "rst-current-version" >
< span > < a href = "../01_Concept_of_the_extractor/" style = "color: #fcfcfc" > « Previous< / a > < / span >
< span > < a href = "../03_Implement_a_service/" style = "color: #fcfcfc" > Next » < / a > < / span >
< / span >
2018-09-01 13:48:12 +00:00
< / div >
< script > var base _url = '..' ; < / script >
2021-10-20 23:09:50 +00:00
< script src = "../js/theme_extra.js" defer > < / script >
2018-09-01 13:48:12 +00:00
< script src = "../js/theme.js" defer > < / script >
< script src = "../search/main.js" defer > < / script >
2020-08-13 00:02:52 +00:00
< script defer >
window.onload = function () {
SphinxRtdTheme.Navigation.enable(true);
};
< / script >
2018-09-01 13:48:12 +00:00
< / body >
< / html >