mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 02:53:09 +01:00
impofed performance and made similar video button hidable
This commit is contained in:
parent
4a938b81df
commit
33e332f105
@ -127,6 +127,8 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
//todo: fix expired thread error:
|
||||||
|
// If the thread calling this runnable is expired, the following function will crash.
|
||||||
updateInfo(videoInfo);
|
updateInfo(videoInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,11 +203,13 @@ public class VideoItemDetailFragment extends Fragment {
|
|||||||
.getViewByVideoInfoItem(null, nextVideoFrame, info.nextVideo);
|
.getViewByVideoInfoItem(null, nextVideoFrame, info.nextVideo);
|
||||||
nextVideoFrame.addView(nextVideoView);
|
nextVideoFrame.addView(nextVideoView);
|
||||||
Button nextVideoButton = (Button) activity.findViewById(R.id.detailNextVideoButton);
|
Button nextVideoButton = (Button) activity.findViewById(R.id.detailNextVideoButton);
|
||||||
|
Button similarVideosButton = (Button) activity.findViewById(R.id.detailShowSimilarButton);
|
||||||
|
|
||||||
contentMainView.setVisibility(View.VISIBLE);
|
contentMainView.setVisibility(View.VISIBLE);
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
if(!showNextVideoItem) {
|
if(!showNextVideoItem) {
|
||||||
nextVideoRootFrame.setVisibility(View.GONE);
|
nextVideoRootFrame.setVisibility(View.GONE);
|
||||||
|
similarVideosButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (info.videoAvailableStatus) {
|
switch (info.videoAvailableStatus) {
|
||||||
|
@ -91,9 +91,46 @@ public class YoutubeExtractor implements Extractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String decryptionCode = "";
|
|
||||||
|
// static values
|
||||||
private static final String DECRYPTION_FUNC_NAME="decrypt";
|
private static final String DECRYPTION_FUNC_NAME="decrypt";
|
||||||
|
|
||||||
|
// cached values
|
||||||
|
private static volatile String decryptionCode = "";
|
||||||
|
|
||||||
|
public void initService(String site) {
|
||||||
|
// The Youtube service needs to be initialized by downloading the
|
||||||
|
// js-Youtube-player. This is done in order to get the algorithm
|
||||||
|
// for decrypting cryptic signatures inside certain stream urls.
|
||||||
|
|
||||||
|
// Star Wars Kid is used as a dummy video, in order to download the youtube player.
|
||||||
|
//String site = Downloader.download("https://www.youtube.com/watch?v=HPPj6viIBmU");
|
||||||
|
//-------------------------------------
|
||||||
|
// extracting form player args
|
||||||
|
//-------------------------------------
|
||||||
|
try {
|
||||||
|
String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", site);
|
||||||
|
JSONObject jsonObj = new JSONObject(jsonString);
|
||||||
|
|
||||||
|
//----------------------------------
|
||||||
|
// load an parse description code
|
||||||
|
//----------------------------------
|
||||||
|
if (decryptionCode.isEmpty()) {
|
||||||
|
JSONObject ytAssets = jsonObj.getJSONObject("assets");
|
||||||
|
String playerUrl = ytAssets.getString("js");
|
||||||
|
if (playerUrl.startsWith("//")) {
|
||||||
|
playerUrl = "https:" + playerUrl;
|
||||||
|
}
|
||||||
|
Log.d(TAG, playerUrl);
|
||||||
|
decryptionCode = loadDecryptionCode(playerUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e){
|
||||||
|
Log.d(TAG, "Could not initialize the extractor of the Youtube service.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVideoId(String videoUrl) {
|
public String getVideoId(String videoUrl) {
|
||||||
try {
|
try {
|
||||||
@ -147,18 +184,18 @@ public class YoutubeExtractor implements Extractor {
|
|||||||
videoInfo.age_limit = 0;
|
videoInfo.age_limit = 0;
|
||||||
videoInfo.webpage_url = siteUrl;
|
videoInfo.webpage_url = siteUrl;
|
||||||
|
|
||||||
|
|
||||||
|
initService(site);
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
// extracting form player args
|
// extracting form player args
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
JSONObject playerArgs = null;
|
JSONObject playerArgs = null;
|
||||||
JSONObject ytAssets = null;
|
|
||||||
String dashManifest;
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", site);
|
String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", site);
|
||||||
JSONObject jsonObj = new JSONObject(jsonString);
|
JSONObject jsonObj = new JSONObject(jsonString);
|
||||||
playerArgs = jsonObj.getJSONObject("args");
|
playerArgs = jsonObj.getJSONObject("args");
|
||||||
ytAssets = jsonObj.getJSONObject("assets");
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -168,7 +205,24 @@ public class YoutubeExtractor implements Extractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------
|
||||||
|
// load and extract audio
|
||||||
|
//-----------------------
|
||||||
try {
|
try {
|
||||||
|
String dashManifest = playerArgs.getString("dashmpd");
|
||||||
|
videoInfo.audioStreams = parseDashManifest(dashManifest, decryptionCode);
|
||||||
|
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
Log.e(TAG, "Could not find \"dashmpd\" upon the player args (maybe no dash manifest available).");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
//--------------------------------------------
|
||||||
|
// extract general information about the video
|
||||||
|
//--------------------------------------------
|
||||||
|
|
||||||
videoInfo.uploader = playerArgs.getString("author");
|
videoInfo.uploader = playerArgs.getString("author");
|
||||||
videoInfo.title = playerArgs.getString("title");
|
videoInfo.title = playerArgs.getString("title");
|
||||||
//first attempt gating a small image version
|
//first attempt gating a small image version
|
||||||
@ -176,23 +230,6 @@ public class YoutubeExtractor implements Extractor {
|
|||||||
videoInfo.thumbnail_url = playerArgs.getString("thumbnail_url");
|
videoInfo.thumbnail_url = playerArgs.getString("thumbnail_url");
|
||||||
videoInfo.duration = playerArgs.getInt("length_seconds");
|
videoInfo.duration = playerArgs.getInt("length_seconds");
|
||||||
videoInfo.average_rating = playerArgs.getString("avg_rating");
|
videoInfo.average_rating = playerArgs.getString("avg_rating");
|
||||||
String playerUrl = ytAssets.getString("js");
|
|
||||||
if(playerUrl.startsWith("//")) {
|
|
||||||
playerUrl = "https:" + playerUrl;
|
|
||||||
}
|
|
||||||
if(decryptionCode.isEmpty()) {
|
|
||||||
decryptionCode = loadDecryptionCode(playerUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
// extract audio
|
|
||||||
try {
|
|
||||||
dashManifest = playerArgs.getString("dashmpd");
|
|
||||||
videoInfo.audioStreams = parseDashManifest(dashManifest, decryptionCode);
|
|
||||||
} catch (Exception e) {
|
|
||||||
//todo: check if the following statement is true
|
|
||||||
Log.e(TAG, "Dash manifest doesn't seem to be available.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------
|
//------------------------------------
|
||||||
// extract video stream url
|
// extract video stream url
|
||||||
@ -211,9 +248,6 @@ public class YoutubeExtractor implements Extractor {
|
|||||||
|
|
||||||
// if video has a signature: decrypt it and add it to the url
|
// if video has a signature: decrypt it and add it to the url
|
||||||
if(tags.get("s") != null) {
|
if(tags.get("s") != null) {
|
||||||
if(decryptionCode.isEmpty()) {
|
|
||||||
decryptionCode = loadDecryptionCode(playerUrl);
|
|
||||||
}
|
|
||||||
streamUrl = streamUrl + "&signature=" + decryptSignature(tags.get("s"), decryptionCode);
|
streamUrl = streamUrl + "&signature=" + decryptSignature(tags.get("s"), decryptionCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,9 +265,9 @@ public class YoutubeExtractor implements Extractor {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------
|
//---------------------------------------
|
||||||
// extracting from html page
|
// extracting information from html page
|
||||||
//-------------------------------
|
//---------------------------------------
|
||||||
|
|
||||||
|
|
||||||
// Determine what went wrong when the Video is not available
|
// Determine what went wrong when the Video is not available
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
<item>Audio</item>
|
<item>Audio</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string name="nextVideoTitle">Nächstes Video</string>
|
<string name="nextVideoTitle">Nächstes Video</string>
|
||||||
<string name="showNextVideoTitle">Zeige \"Nächstes Video\" Auswahl.</string>
|
<string name="showNextAndSimilarTitle">Zeige nächstes und änliche Videos.</string>
|
||||||
<string name="urlNotSupportedText">Url wird nicht unterstützt.</string>
|
<string name="urlNotSupportedText">Url wird nicht unterstützt.</string>
|
||||||
<string name="showSimilarVideosButtonText">Ähnliche Videos</string>
|
<string name="showSimilarVideosButtonText">Ähnliche Videos</string>
|
||||||
</resources>
|
</resources>
|
@ -46,7 +46,7 @@
|
|||||||
<item>Audio</item>
|
<item>Audio</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string name="nextVideoTitle">Next Video</string>
|
<string name="nextVideoTitle">Next Video</string>
|
||||||
<string name="showNextVideoTitle">Show \"Next video\" item.</string>
|
<string name="showNextAndSimilarTitle">Show next and similar Videos.</string>
|
||||||
<string name="urlNotSupportedText">Url not Supported.</string>
|
<string name="urlNotSupportedText">Url not Supported.</string>
|
||||||
<string name="showSimilarVideosButtonText">Similar Videos</string>
|
<string name="showSimilarVideosButtonText">Similar Videos</string>
|
||||||
<string name="contentCountryTitle">Video Content Country</string>
|
<string name="contentCountryTitle">Video Content Country</string>
|
||||||
|
@ -48,13 +48,15 @@
|
|||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="@string/showNextVideo"
|
android:key="@string/showNextVideo"
|
||||||
android:title="@string/showNextVideoTitle"
|
android:title="@string/showNextAndSimilarTitle"
|
||||||
android:defaultValue="true" />
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<!-- This function is not yet available
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="@string/contentCountry"
|
android:key="@string/contentCountry"
|
||||||
android:title="@string/contentCountryTitle"
|
android:title="@string/contentCountryTitle"
|
||||||
android:entries="@array/countryNames"
|
android:entries="@array/countryNames"
|
||||||
android:entryValues="@array/countryCodes"
|
android:entryValues="@array/countryCodes"
|
||||||
android:defaultValue="" /> <!-- default will include no country code in URL-->
|
android:defaultValue="" /> <!- default will include no country code in URL-->
|
||||||
|
-->
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user