1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

add support for attribution_link links

This commit is contained in:
Christian Schabesberger 2016-02-17 20:29:31 +01:00
parent 80482c0578
commit b15a0b92f9
4 changed files with 40 additions and 36 deletions

View File

@ -49,6 +49,7 @@
<data android:host="www.youtube.com" /> <data android:host="www.youtube.com" />
<data android:pathPrefix="/v/" /> <data android:pathPrefix="/v/" />
<data android:pathPrefix="/watch" /> <data android:pathPrefix="/watch" />
<data android:pathPrefix="/attribution_link" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />

View File

@ -50,6 +50,16 @@ import java.util.Vector;
public class YoutubeStreamExtractor implements StreamExtractor { public class YoutubeStreamExtractor implements StreamExtractor {
// Sometimes if the html page of youtube is already downloaded, youtube web page will internally
// download the /get_video_info page. Since a certain date dashmpd url is only available over
// this /get_video_info page, so we always need to download this one to.
// %%video_id%% will be replaced by the actual video id
// $$el_type$$ will be replaced by the actual el_type (se the declarations below)
private static final String GET_VIDEO_INFO_URL =
"https://www.youtube.com/get_video_info?video_id=%%video_id%%$$el_type$$&ps=default&eurl=&gl=US&hl=en";
// eltype is nececeary for the url aboth
private static final String EL_INFO = "el=info";
public enum ItagType { public enum ItagType {
AUDIO, AUDIO,
VIDEO, VIDEO,
@ -131,16 +141,6 @@ public class YoutubeStreamExtractor implements StreamExtractor {
throw new ParsingException("itag=" + Integer.toString(itag) + " not supported"); throw new ParsingException("itag=" + Integer.toString(itag) + " not supported");
} }
// Sometimes if the html page of youtube is already downloaded, youtube web page will internally
// download the /get_video_info page. Since a certain date dashmpd url is only available over
// this /get_video_info page, so we always need to download this one to.
// %%video_id%% will be replaced by the actual video id
// $$el_type$$ will be replaced by the actual el_type (se the declarations below)
private static final String GET_VIDEO_INFO_URL =
"https://www.youtube.com/get_video_info?video_id=%%video_id%%$$el_type$$&ps=default&eurl=&gl=US&hl=en";
// eltype is nececeary for the url aboth
private static final String EL_INFO = "el=info";
public class DecryptException extends ParsingException { public class DecryptException extends ParsingException {
DecryptException(Throwable cause) { DecryptException(Throwable cause) {
super(cause); super(cause);
@ -163,7 +163,7 @@ public class YoutubeStreamExtractor implements StreamExtractor {
private static final String TAG = YoutubeStreamExtractor.class.toString(); private static final String TAG = YoutubeStreamExtractor.class.toString();
private final Document doc; private final Document doc;
private JSONObject playerArgs; private JSONObject playerArgs;
private Map<String, String> videoInfoPage; //private Map<String, String> videoInfoPage;
// static values // static values
private static final String DECRYPTION_FUNC_NAME="decrypt"; private static final String DECRYPTION_FUNC_NAME="decrypt";
@ -206,6 +206,9 @@ public class YoutubeStreamExtractor implements StreamExtractor {
} }
/* not yet nececeary
// get videoInfo page // get videoInfo page
try { try {
//Parser.unescapeEntities(url_data_str, true).split("&") //Parser.unescapeEntities(url_data_str, true).split("&")
@ -215,6 +218,7 @@ public class YoutubeStreamExtractor implements StreamExtractor {
} catch(Exception e) { } catch(Exception e) {
throw new ParsingException("Could not load video info page.", e); throw new ParsingException("Could not load video info page.", e);
} }
*/
//---------------------------------- //----------------------------------
// load and parse description code, if it isn't already initialised // load and parse description code, if it isn't already initialised
@ -337,24 +341,6 @@ public class YoutubeStreamExtractor implements StreamExtractor {
@Override @Override
public String getDashMpdUrl() throws ParsingException { public String getDashMpdUrl() throws ParsingException {
/* /*
try {
String dashManifest = playerArgs.getString("dashmpd");
if(!dashManifest.contains("/signature/")) {
String encryptedSig = Parser.matchGroup1("/s/([a-fA-F0-9\\.]+)", dashManifest);
String decryptedSig;
decryptedSig = decryptSignature(encryptedSig, decryptionCode);
dashManifest = dashManifest.replace("/s/" + encryptedSig, "/signature/" + decryptedSig);
}
return dashManifest;
} catch(JSONException je) {
throw new ParsingException(
"Could not find \"dashmpd\" upon the player args (maybe no dash manifest available).", je);
} catch (Exception e) {
throw new ParsingException(e);
}
*/
try { try {
String dashManifestUrl = videoInfoPage.get("dashmpd"); String dashManifestUrl = videoInfoPage.get("dashmpd");
if(!dashManifestUrl.contains("/signature/")) { if(!dashManifestUrl.contains("/signature/")) {
@ -369,6 +355,8 @@ public class YoutubeStreamExtractor implements StreamExtractor {
throw new ParsingException( throw new ParsingException(
"Could not get \"dashmpd\" maybe VideoInfoPage is broken.", e); "Could not get \"dashmpd\" maybe VideoInfoPage is broken.", e);
} }
*/
return "";
} }

View File

@ -1,9 +1,15 @@
package org.schabi.newpipe.crawler.services.youtube; package org.schabi.newpipe.crawler.services.youtube;
import android.util.Log;
import org.schabi.newpipe.crawler.Parser; import org.schabi.newpipe.crawler.Parser;
import org.schabi.newpipe.crawler.ParsingException; import org.schabi.newpipe.crawler.ParsingException;
import org.schabi.newpipe.crawler.VideoUrlIdHandler; import org.schabi.newpipe.crawler.VideoUrlIdHandler;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Map;
/** /**
* Created by Christian Schabesberger on 02.02.16. * Created by Christian Schabesberger on 02.02.16.
* *
@ -34,20 +40,29 @@ public class YoutubeVideoUrlIdHandler implements VideoUrlIdHandler {
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
@Override @Override
public String getVideoId(String url) throws ParsingException { public String getVideoId(String url) throws ParsingException {
String id; String id = "";
String pat;
if(url.contains("youtube")) { if(url.contains("youtube")) {
pat = "youtube\\.com/watch\\?v=([\\-a-zA-Z0-9_]{11})"; if(url.contains("attribution_link")) {
try {
String escapedQuery = Parser.matchGroup1("u=(.[^&|$]*)", url);
String query = URLDecoder.decode(escapedQuery, "UTF-8");
id = Parser.matchGroup1("v=([\\-a-zA-Z0-9_]{11})", query);
} catch(UnsupportedEncodingException uee) {
throw new ParsingException("Could not parse attribution_link", uee);
}
} else {
id = Parser.matchGroup1("youtube\\.com/watch\\?v=([\\-a-zA-Z0-9_]{11})", url);
}
} }
else if(url.contains("youtu.be")) { else if(url.contains("youtu.be")) {
pat = "youtu\\.be/([a-zA-Z0-9_-]{11})"; id = Parser.matchGroup1("youtu\\.be/([a-zA-Z0-9_-]{11})", url);
} }
else { else {
throw new ParsingException("Error no suitable url: " + url); throw new ParsingException("Error no suitable url: " + url);
} }
id = Parser.matchGroup1(pat, url);
if(!id.isEmpty()){ if(!id.isEmpty()){
//Log.i(TAG, "string \""+url+"\" matches!"); //Log.i(TAG, "string \""+url+"\" matches!");
return id; return id;

View File

@ -56,7 +56,7 @@
<string name="use_tor_title">Benutze TOR</string> <string name="use_tor_title">Benutze TOR</string>
<string name="use_tor_summary">Erzwinge das Herunterladen durch TOR für verbesserte Privatsphäre (Videostream noch nicht unterstützt)</string> <string name="use_tor_summary">Erzwinge das Herunterladen durch TOR für verbesserte Privatsphäre (Videostream noch nicht unterstützt)</string>
<string name="background_player_name">NewPipe Hintergrundwiedergabe</string> <string name="background_player_name">NewPipe Hintergrundwiedergabe</string>
<string name="network_error">Netzwerkfehler</string> <string name="network_error">Netzwerkfehler</string>
<string name="download_path_audio_title">Downloadverzeichnis für Musik</string> <string name="download_path_audio_title">Downloadverzeichnis für Musik</string>
@ -71,7 +71,7 @@
<string name="settings_category_other_title">Andere</string> <string name="settings_category_other_title">Andere</string>
<string name="err_dir_create">Kann Downloadverzeichnis nicht anlegen \'%1$s\'</string> <string name="err_dir_create">Kann Downloadverzeichnis nicht anlegen \'%1$s\'</string>
<string name="info_dir_created">Downloadverzeichnis \'%1$s\' erstellt</string> <string name="info_dir_created">Downloadverzeichnis \'%1$s\' erstellt</string>
<string name="general_error">Fehler</string> <string name="general_error">Fehler</string>
<string name="could_not_load_thumbnails">Konnte nicht alle Vorschaubilder laden</string> <string name="could_not_load_thumbnails">Konnte nicht alle Vorschaubilder laden</string>
<string name="youtube_signature_decryption_error">Konnte Video-URL-Signatur nicht entschlüsseln.</string> <string name="youtube_signature_decryption_error">Konnte Video-URL-Signatur nicht entschlüsseln.</string>
<string name="parsing_error">Konnte Webseite nicht parsen.</string> <string name="parsing_error">Konnte Webseite nicht parsen.</string>