Skip to content

Commit 9e7d9ee

Browse files
committed
merged commits from origin
2 parents 2fc2fa5 + 586bad3 commit 9e7d9ee

8 files changed

Lines changed: 104 additions & 41 deletions

File tree

app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public VideoResultReturnedRunnable(VideoInfo videoInfo) {
127127
}
128128
@Override
129129
public void run() {
130+
//todo: fix expired thread error:
131+
// If the thread calling this runnable is expired, the following function will crash.
130132
updateInfo(videoInfo);
131133
}
132134
}
@@ -201,11 +203,13 @@ public void updateInfo(VideoInfo info) {
201203
.getViewByVideoInfoItem(null, nextVideoFrame, info.nextVideo);
202204
nextVideoFrame.addView(nextVideoView);
203205
Button nextVideoButton = (Button) activity.findViewById(R.id.detailNextVideoButton);
206+
Button similarVideosButton = (Button) activity.findViewById(R.id.detailShowSimilarButton);
204207

205208
contentMainView.setVisibility(View.VISIBLE);
206209
progressBar.setVisibility(View.GONE);
207210
if(!showNextVideoItem) {
208211
nextVideoRootFrame.setVisibility(View.GONE);
212+
similarVideosButton.setVisibility(View.GONE);
209213
}
210214

211215
switch (info.videoAvailableStatus) {

app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,45 @@ public static String resolveResolutionString(int itag) {
9191
}
9292
}
9393

94-
private String decryptionCode = "";
94+
95+
// static values
9596
private static final String DECRYPTION_FUNC_NAME="decrypt";
9697

98+
// cached values
99+
private static volatile String decryptionCode = "";
100+
101+
public void initService(String site) {
102+
// The Youtube service needs to be initialized by downloading the
103+
// js-Youtube-player. This is done in order to get the algorithm
104+
// for decrypting cryptic signatures inside certain stream urls.
105+
106+
// Star Wars Kid is used as a dummy video, in order to download the youtube player.
107+
//String site = Downloader.download("https://www.youtube.com/watch?v=HPPj6viIBmU");
108+
//-------------------------------------
109+
// extracting form player args
110+
//-------------------------------------
111+
try {
112+
String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", site);
113+
JSONObject jsonObj = new JSONObject(jsonString);
114+
115+
//----------------------------------
116+
// load an parse description code
117+
//----------------------------------
118+
if (decryptionCode.isEmpty()) {
119+
JSONObject ytAssets = jsonObj.getJSONObject("assets");
120+
String playerUrl = ytAssets.getString("js");
121+
if (playerUrl.startsWith("//")) {
122+
playerUrl = "https:" + playerUrl;
123+
}
124+
decryptionCode = loadDecryptionCode(playerUrl);
125+
}
126+
127+
} catch (Exception e){
128+
Log.d(TAG, "Could not initialize the extractor of the Youtube service.");
129+
e.printStackTrace();
130+
}
131+
}
132+
97133
@Override
98134
public String getVideoId(String videoUrl) {
99135
try {
@@ -147,18 +183,18 @@ public VideoInfo getVideoInfo(String siteUrl) {
147183
videoInfo.age_limit = 0;
148184
videoInfo.webpage_url = siteUrl;
149185

186+
187+
initService(site);
188+
150189
//-------------------------------------
151190
// extracting form player args
152191
//-------------------------------------
153192
JSONObject playerArgs = null;
154-
JSONObject ytAssets = null;
155-
String dashManifest;
156193
{
157194
try {
158195
String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", site);
159196
JSONObject jsonObj = new JSONObject(jsonString);
160197
playerArgs = jsonObj.getJSONObject("args");
161-
ytAssets = jsonObj.getJSONObject("assets");
162198
}
163199
catch (Exception e) {
164200
e.printStackTrace();
@@ -168,31 +204,31 @@ public VideoInfo getVideoInfo(String siteUrl) {
168204
}
169205
}
170206

207+
//-----------------------
208+
// load and extract audio
209+
//-----------------------
210+
try {
211+
String dashManifest = playerArgs.getString("dashmpd");
212+
videoInfo.audioStreams = parseDashManifest(dashManifest, decryptionCode);
213+
214+
} catch (NullPointerException e) {
215+
Log.e(TAG, "Could not find \"dashmpd\" upon the player args (maybe no dash manifest available).");
216+
} catch (Exception e) {
217+
e.printStackTrace();
218+
}
219+
171220
try {
221+
//--------------------------------------------
222+
// extract general information about the video
223+
//--------------------------------------------
224+
172225
videoInfo.uploader = playerArgs.getString("author");
173226
videoInfo.title = playerArgs.getString("title");
174227
//first attempt gating a small image version
175228
//in the html extracting part we try to get a thumbnail with a higher resolution
176229
videoInfo.thumbnail_url = playerArgs.getString("thumbnail_url");
177230
videoInfo.duration = playerArgs.getInt("length_seconds");
178231
videoInfo.average_rating = playerArgs.getString("avg_rating");
179-
String playerUrl = ytAssets.getString("js");
180-
if(playerUrl.startsWith("//")) {
181-
playerUrl = "https:" + playerUrl;
182-
}
183-
if(decryptionCode.isEmpty()) {
184-
decryptionCode = loadDecryptionCode(playerUrl);
185-
}
186-
187-
// extract audio
188-
try {
189-
dashManifest = playerArgs.getString("dashmpd");
190-
videoInfo.audioStreams = parseDashManifest(dashManifest, decryptionCode);
191-
} catch (Exception e) {
192-
//todo: check if the following statement is true
193-
Log.e(TAG, "Dash manifest doesn't seem to be available.");
194-
e.printStackTrace();
195-
}
196232

197233
//------------------------------------
198234
// extract video stream url
@@ -211,9 +247,6 @@ public VideoInfo getVideoInfo(String siteUrl) {
211247

212248
// if video has a signature: decrypt it and add it to the url
213249
if(tags.get("s") != null) {
214-
if(decryptionCode.isEmpty()) {
215-
decryptionCode = loadDecryptionCode(playerUrl);
216-
}
217250
streamUrl = streamUrl + "&signature=" + decryptSignature(tags.get("s"), decryptionCode);
218251
}
219252

@@ -231,9 +264,9 @@ public VideoInfo getVideoInfo(String siteUrl) {
231264
e.printStackTrace();
232265
}
233266

234-
//-------------------------------
235-
// extracting from html page
236-
//-------------------------------
267+
//---------------------------------------
268+
// extracting information from html page
269+
//---------------------------------------
237270

238271

239272
// Determine what went wrong when the Video is not available

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<item>Audio</item>
4747
</string-array>
4848
<string name="nextVideoTitle">Nächstes Video</string>
49-
<string name="showNextVideoTitle">Zeige \"Nächstes Video\" Auswahl.</string>
49+
<string name="showNextAndSimilarTitle">Zeige nächstes und änliche Videos.</string>
5050
<string name="urlNotSupportedText">Url wird nicht unterstützt.</string>
5151
<string name="showSimilarVideosButtonText">Ähnliche Videos</string>
5252
</resources>
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version='1.0' encoding='utf-8'?>
22
<resources>
33
<string name="app_name">NewPipe</string>
44
<string name="title_videoitem_detail">NewPipe</string>
55
<string name="nothingFound">No se ha encontrado nada</string>
66
<string name="viewSufix">visitas</string>
77
<string name="uploadDatePrefix">Subido desde: </string>
88
<string name="noPlayerFound">No se ha encontrado ningún reproductor de vídeo. Quizás quieras instalar alguno.</string>
9-
<string name="installStreamPlayer">Instalar</string>
9+
<string name="installStreamPlayer">Instalarlo</string>
1010
<string name="cancel">Cancelar</string>
1111
<string name="fdroidVLCurl">https://f-droid.org/repository/browse/?fdfilter=vlc&amp;fdid=org.videolan.vlc</string>
12-
<string name="open_in_browser">Abrir en navegador</string>
12+
<string name="open_in_browser">Abrir en el navegador</string>
1313
<string name="share">Compartir</string>
1414
<string name="play">Reproducir</string>
1515
<string name="download">Descargar</string>
1616
<string name="search">Buscar</string>
1717
<string name="settings">Ajustes</string>
1818
<string name="sendWith">Enviar con</string>
19-
<string name="didYouMean">Querias decir: </string>
19+
<string name="didYouMean">"¿Querías decir?: "</string>
2020
<string name="searchPage">Buscar página: </string>
2121
<string name="shareDialogTitle">Compartir con:</string>
2222
<string name="chooseBrowser">Selecciona navegador:</string>
2323
<string name="screenRotation">rotación</string>
2424
<string name="title_activity_settings">Ajustes</string>
2525
<string name="useExternalPlayerTitle">Usar reproductor externo</string>
2626
<string name="downloadLocation">Descargar en...</string>
27-
<string name="downloadLocationSummary">Donde se guardarán los vídeos descargados.</string>
27+
<string name="downloadLocationSummary">Ruta donde guardar los vídeos descargados.</string>
2828
<string name="downloadLocationDialogTitle">Localización del directorio de descargas</string>
2929
<string name="autoPlayThroughIntentTitle">Reproducción automática</string>
30-
<string name="autoPlayThroughIntentSummary">Reproduce los vídeos automaticamente cuando la llamada viene de otra aplicación.</string>
30+
<string name="autoPlayThroughIntentSummary">Reproducir los vídeos automaticamente cuando se llama desde otra aplicación.</string>
3131
<string name="defaultResolutionPreferenceTitle">Resolución por defecto</string>
3232
<string name="playWithKodiTitle">Reproducir con Kodi</string>
3333
<string name="koreNotFound">Aplicación Kore no encontrada. Kore es necesario para reproducir vídeos con Kodi media center.</string>
3434
<string name="installeKore">Instalar Kore</string>
3535
<string name="fdroidKoreUrl">https://f-droid.org/repository/browse/?fdfilter=Kore&amp;fdid=org.xbmc.kore</string>
3636
<string name="showPlayWithKodiTitle">Mostrar la opción \"Reproducir con Kodi\"</string>
37-
<string name="showPlayWithKodiSummary">Muestra una opción para reproducir vídeo vía Kodi media center.</string>
37+
<string name="showPlayWithKodiSummary">Muestra una opción para reproducir el vídeo con Kodi media center.</string>
38+
<string name="leftPlayButtonTitle">Mostrar el botón de reproducir en el lado izquierdo.</string>
39+
<string name="playAudio">Audio</string>
40+
<string name="defaultAudioFormatTitle">Formato de audio por defecto</string>
41+
<string name="webMAudioDescription">WebM - formato libre</string>
42+
<string name="m4aAudioDescription">m4a - mejor calidad</string>
43+
<string name="downloadDialogTitle">Descargar</string>
44+
<string name="nextVideoTitle">Siguiente vídeo</string>
45+
<string name="showNextVideoTitle">Mostrar la opción \"Siguiente vídeo\".</string>
46+
<string name="urlNotSupportedText">Url no soportada.</string>
47+
<string name="showSimilarVideosButtonText">Vídeos similares</string>
48+
<string name="contentCountryTitle">País del contenido del vídeo</string>
3849
</resources>

app/src/main/res/values-hu/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@
4848
<string name="nextVideoTitle">Következő videó</string>
4949
<string name="showNextVideoTitle">\"Következő videó\" elem mutatása</string>
5050
<string name="urlNotSupportedText">A webcím nem támogatott.</string>
51-
</resources>
51+
<string name="showSimilarVideosButtonText">Hasonló videók</string>
52+
</resources>

app/src/main/res/values-nl/strings.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<string name="nothingFound">Geen resultaten</string>
66
<string name="viewSufix">keer bekeken</string>
77
<string name="uploadDatePrefix">Geüpload op: </string>
8-
<string name="noPlayerFound">Geen speler met streaming ondersteuning gevonden. Je wilt er misschien een installeren.</string>
8+
<string name="noPlayerFound">Geen speler met streaming ondersteuning gevonden. Misschien wil je er een installeren</string>
99
<string name="installStreamPlayer">Installeer speler</string>
1010
<string name="cancel">Annuleer</string>
1111
<string name="fdroidVLCurl">https://f-droid.org/repository/browse/?fdfilter=vlc&amp;fdid=org.videolan.vlc</string>
@@ -35,4 +35,15 @@
3535
<string name="fdroidKoreUrl">https://f-droid.org/repository/browse/?fdfilter=Kore&amp;fdid=org.xbmc.kore</string>
3636
<string name="showPlayWithKodiTitle">Toon \"Speel af met Kodi\" optie</string>
3737
<string name="showPlayWithKodiSummary">Toont een optie om een video op een Kodi media center af te spelen.</string>
38-
</resources>
38+
<string name="contentCountryTitle">Video inhoud land</string>
39+
<string name="leftPlayButtonTitle">Afspeel knop aan de linker kant weergeven</string>
40+
<string name="playAudio">Audio</string>
41+
<string name="defaultAudioFormatTitle">Standaard audio formaat</string>
42+
<string name="webMAudioDescription">Webam - open formaat</string>
43+
<string name="m4aAudioDescription">m4a - betere kwaliteit</string>
44+
<string name="downloadDialogTitle">Download</string>
45+
<string name="nextVideoTitle">Volgende video</string>
46+
<string name="showNextVideoTitle">\"Volgende video\" weergeven</string>
47+
<string name="urlNotSupportedText">Url wordt niet ondersteund</string>
48+
<string name="showSimilarVideosButtonText">Vergelijkbare videos</string>
49+
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<item>Audio</item>
4747
</string-array>
4848
<string name="nextVideoTitle">Next Video</string>
49-
<string name="showNextVideoTitle">Show \"Next video\" item.</string>
49+
<string name="showNextAndSimilarTitle">Show next and similar Videos.</string>
5050
<string name="urlNotSupportedText">Url not Supported.</string>
5151
<string name="showSimilarVideosButtonText">Similar Videos</string>
5252
<string name="searchLanguageTitle">Video Search Language</string>

app/src/main/res/xml/settings_screen.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@
4848

4949
<CheckBoxPreference
5050
android:key="@string/showNextVideo"
51-
android:title="@string/showNextVideoTitle"
51+
android:title="@string/showNextAndSimilarTitle"
5252
android:defaultValue="true" />
5353

54+
<!-- This function is not yet available
5455
<ListPreference
5556
android:key="@string/searchLanguage"
5657
android:title="@string/searchLanguageTitle"
5758
android:entries="@array/languageNames"
5859
android:entryValues="@array/languageCodes"
59-
android:defaultValue="" /> <!-- default will include no country code in URL-->
60+
android:defaultValue="en" />
61+
62+
-->
6063
</PreferenceScreen>

0 commit comments

Comments
 (0)