add basic extractor/collector pattern

This commit is contained in:
Christian Schabesberger 2018-02-22 19:17:23 +01:00
parent a858d42041
commit b3d1bbc44d
2 changed files with 36 additions and 3 deletions

View File

@ -1,8 +1,8 @@
# Prepare everything
Welcome to the NewPipe tutorial. This tutorial will guide you through the process of creating your own NewPipeExtractor service
with which NewPipe will gain support for a dedicated streaming service like YouTube, Vimeo or SournCloud.
Let's dive right. ;D
Welcome to the NewPipe tutorial. This tutorial will guide you through the process of creating your own NewPipeExtractor
service with which NewPipe will gain support for a dedicated streaming service like YouTube, Vimeo or SournCloud. Let's
dive right. ;D
## Setup your dev environment

View File

@ -0,0 +1,33 @@
# Basic Concept of the Extractor
## Collector/Extractor pattern
Before we can start coding our own service we need to understand the basic concept of the extractor. There is a pattern
you will find all over the code. It is called to __extractor/collector__ pattern. The idea behind this pattern is that
the [extractor](https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/Extractor.html)
would produce single peaces of data, and the collector would take it and form usable data for the front end out of it.
The collector also controls the parsing process, and takes care about error handling. So if the extractor fails at any
point the collector will decide weather it should continue parsing or not. This requires the extractor to be made out of
many small methods. One method for every data field the collector wants to have. The collectors are provided by NewPipe.
You need to take care of the extractors.
### Usage in the front end
So typical call for retrieving data from a website would look like this:
```java
Info info;
try {
Extractor extractor = new Extractor(ome_meta_info); // Create a new Extractor with a given context provided as parameter.
info = Info.getInfo(extractor); // Retrieves the data form extractor and builds info package.
} catch(Exception e) {
// handler errors when collector decided to break up extraction
}
```