Skip to content

Commit 9005105

Browse files
committed
initial commit
0 parents  commit 9005105

44 files changed

Lines changed: 4749 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AbstractStreamInfo.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
/**
4+
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
5+
* AbstractStreamInfo.java is part of NewPipe.
6+
*
7+
* NewPipe is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* NewPipe is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
/**Common properties between StreamInfo and StreamInfoItem.*/
22+
public abstract class AbstractStreamInfo {
23+
public enum StreamType {
24+
NONE, // placeholder to check if stream type was checked or not
25+
VIDEO_STREAM,
26+
AUDIO_STREAM,
27+
LIVE_STREAM,
28+
AUDIO_LIVE_STREAM,
29+
FILE
30+
}
31+
32+
public StreamType stream_type;
33+
public int service_id = -1;
34+
public String id = "";
35+
public String title = "";
36+
public String uploader = "";
37+
public String thumbnail_url = "";
38+
public String webpage_url = "";
39+
public String upload_date = "";
40+
public long view_count = -1;
41+
}

DashMpdParser.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
4+
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
5+
import org.schabi.newpipe.extractor.stream_info.AudioStream;
6+
import org.w3c.dom.Document;
7+
import org.w3c.dom.Element;
8+
import org.w3c.dom.NodeList;
9+
10+
import java.io.ByteArrayInputStream;
11+
import java.io.IOException;
12+
import java.io.InputStream;
13+
import java.util.List;
14+
import java.util.Vector;
15+
16+
import javax.xml.parsers.DocumentBuilder;
17+
import javax.xml.parsers.DocumentBuilderFactory;
18+
19+
/**
20+
* Created by Christian Schabesberger on 02.02.16.
21+
*
22+
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
23+
* DashMpdParser.java is part of NewPipe.
24+
*
25+
* NewPipe is free software: you can redistribute it and/or modify
26+
* it under the terms of the GNU General Public License as published by
27+
* the Free Software Foundation, either version 3 of the License, or
28+
* (at your option) any later version.
29+
*
30+
* NewPipe is distributed in the hope that it will be useful,
31+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
32+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33+
* GNU General Public License for more details.
34+
*
35+
* You should have received a copy of the GNU General Public License
36+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
37+
*/
38+
39+
public class DashMpdParser {
40+
41+
private DashMpdParser() {
42+
}
43+
44+
static class DashMpdParsingException extends ParsingException {
45+
DashMpdParsingException(String message, Exception e) {
46+
super(message, e);
47+
}
48+
}
49+
50+
public static List<AudioStream> getAudioStreams(String dashManifestUrl)
51+
throws DashMpdParsingException, ReCaptchaException {
52+
String dashDoc;
53+
Downloader downloader = NewPipe.getDownloader();
54+
try {
55+
dashDoc = downloader.download(dashManifestUrl);
56+
} catch(IOException ioe) {
57+
throw new DashMpdParsingException("Could not get dash mpd: " + dashManifestUrl, ioe);
58+
} catch (ReCaptchaException e) {
59+
throw new ReCaptchaException("reCaptcha Challenge needed");
60+
}
61+
Vector<AudioStream> audioStreams = new Vector<>();
62+
63+
try {
64+
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
65+
DocumentBuilder builder = factory.newDocumentBuilder();
66+
InputStream stream = new ByteArrayInputStream(dashDoc.getBytes());
67+
68+
Document doc = builder.parse(stream);
69+
NodeList adaptationSetList = doc.getElementsByTagName("AdaptationSet");
70+
for(int i = 0; i < adaptationSetList.getLength(); i++) {
71+
Element adaptationSet = (Element) adaptationSetList.item(i);
72+
String memeType = adaptationSet.getAttribute("mimeType");
73+
if(memeType.contains("audio")) {
74+
Element representation = (Element) adaptationSet.getElementsByTagName("Representation").item(0);
75+
String url = representation.getElementsByTagName("BaseURL").item(0).getTextContent();
76+
int bandwidth = Integer.parseInt(representation.getAttribute("bandwidth"));
77+
int samplingRate = Integer.parseInt(representation.getAttribute("audioSamplingRate"));
78+
int format = -1;
79+
if(memeType.equals(MediaFormat.WEBMA.mimeType)) {
80+
format = MediaFormat.WEBMA.id;
81+
} else if(memeType.equals(MediaFormat.M4A.mimeType)) {
82+
format = MediaFormat.M4A.id;
83+
}
84+
audioStreams.add(new AudioStream(url, format, bandwidth, samplingRate));
85+
}
86+
}
87+
}
88+
catch(Exception e) {
89+
throw new DashMpdParsingException("Could not parse Dash mpd", e);
90+
}
91+
return audioStreams;
92+
}
93+
}

Downloader.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
4+
5+
import java.io.IOException;
6+
import java.util.Map;
7+
8+
/**
9+
* Created by Christian Schabesberger on 28.01.16.
10+
*
11+
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
12+
* Downloader.java is part of NewPipe.
13+
*
14+
* NewPipe is free software: you can redistribute it and/or modify
15+
* it under the terms of the GNU General Public License as published by
16+
* the Free Software Foundation, either version 3 of the License, or
17+
* (at your option) any later version.
18+
*
19+
* NewPipe is distributed in the hope that it will be useful,
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
* GNU General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU General Public License
25+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
28+
public interface Downloader {
29+
30+
/**Download the text file at the supplied URL as in download(String),
31+
* but set the HTTP header field "Accept-Language" to the supplied string.
32+
* @param siteUrl the URL of the text file to return the contents of
33+
* @param language the language (usually a 2-character code) to set as the preferred language
34+
* @return the contents of the specified text file
35+
* @throws IOException*/
36+
String download(String siteUrl, String language) throws IOException, ReCaptchaException;
37+
38+
/**Download the text file at the supplied URL as in download(String),
39+
* but set the HTTP header field "Accept-Language" to the supplied string.
40+
* @param siteUrl the URL of the text file to return the contents of
41+
* @param customProperties set request header properties
42+
* @return the contents of the specified text file
43+
* @throws IOException*/
44+
String download(String siteUrl, Map<String, String> customProperties) throws IOException, ReCaptchaException;
45+
46+
/**Download (via HTTP) the text file located at the supplied URL, and return its contents.
47+
* Primarily intended for downloading web pages.
48+
* @param siteUrl the URL of the text file to download
49+
* @return the contents of the specified text file
50+
* @throws IOException*/
51+
String download(String siteUrl) throws IOException, ReCaptchaException;
52+
}

InfoItem.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
/**
4+
* Created by the-scrabi on 11.02.17.
5+
*
6+
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
7+
* InfoItem.java is part of NewPipe.
8+
*
9+
* NewPipe is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* NewPipe is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
public interface InfoItem {
24+
public enum InfoType {
25+
STREAM,
26+
PLAYLIST,
27+
CHANNEL
28+
}
29+
30+
InfoType infoType();
31+
String getTitle();
32+
String getLink();
33+
}

InfoItemCollector.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
4+
5+
import java.util.List;
6+
import java.util.Vector;
7+
8+
/**
9+
* Created by Christian Schabesberger on 12.02.17.
10+
*
11+
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
12+
* InfoItemCollector.java is part of NewPipe.
13+
*
14+
* NewPipe is free software: you can redistribute it and/or modify
15+
* it under the terms of the GNU General Public License as published by
16+
* the Free Software Foundation, either version 3 of the License, or
17+
* (at your option) any later version.
18+
*
19+
* NewPipe is distributed in the hope that it will be useful,
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
* GNU General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU General Public License
25+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
28+
public class InfoItemCollector {
29+
private List<InfoItem> itemList = new Vector<>();
30+
private List<Throwable> errors = new Vector<>();
31+
private int serviceId = -1;
32+
33+
public InfoItemCollector(int serviceId) {
34+
this.serviceId = serviceId;
35+
}
36+
37+
public List<InfoItem> getItemList() {
38+
return itemList;
39+
}
40+
public List<Throwable> getErrors() {
41+
return errors;
42+
}
43+
protected void addFromCollector(InfoItemCollector otherC) throws ExtractionException {
44+
if(serviceId != otherC.serviceId) {
45+
throw new ExtractionException("Service Id does not equal: "
46+
+ NewPipe.getNameOfService(serviceId)
47+
+ " and " + NewPipe.getNameOfService(otherC.serviceId));
48+
}
49+
errors.addAll(otherC.errors);
50+
itemList.addAll(otherC.itemList);
51+
}
52+
protected void addError(Exception e) {
53+
errors.add(e);
54+
}
55+
protected void addItem(InfoItem item) {
56+
itemList.add(item);
57+
}
58+
protected int getServiceId() {
59+
return serviceId;
60+
}
61+
}

0 commit comments

Comments
 (0)