-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Merged manually from PipePipe (https://codeberg.org/NullPointerException/PipePipeClient/commit/f0cb4e33ab8f46d23642137b47ab5436296c7a9f#diff-f57d0ffc8afaa16442bbe82ca85dd5c8b7c8f120)
- Loading branch information
Showing
8 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/java/org/schabi/newpipe/settings/YouTubeAccountSettingsFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.schabi.newpipe.settings; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import androidx.preference.Preference; | ||
import org.schabi.newpipe.R; | ||
import org.schabi.newpipe.views.YouTubeLoginWebViewActivity; | ||
|
||
import static android.app.Activity.RESULT_OK; | ||
|
||
public class YouTubeAccountSettingsFragment extends BasePreferenceFragment { | ||
private static final int REQUEST_LOGIN = 1; | ||
|
||
@Override | ||
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { | ||
addPreferencesFromResource(R.xml.account_settings_youtube); | ||
Preference login = findPreference(getString(R.string.login_key)); | ||
Preference logout = findPreference(getString(R.string.logout_key)); | ||
login.setOnPreferenceClickListener(preference -> { | ||
// Open a webview to login and then get cookies | ||
// and save them to the shared preferences | ||
Intent intent = new Intent(this.getContext(), YouTubeLoginWebViewActivity.class); | ||
startActivityForResult(intent, REQUEST_LOGIN); | ||
return true; | ||
}); | ||
logout.setOnPreferenceClickListener(preference -> { | ||
// Clear cookies | ||
defaultPreferences.edit().putString(getString(R.string.youtube_cookies_key), "").apply(); | ||
// defaultPreferences.edit().putString(getString(R.string.youtube_po_token), "").apply(); | ||
return true; | ||
}); | ||
if (defaultPreferences.getString(getString(R.string.youtube_cookies_key), "").equals("")) { | ||
logout.setEnabled(false); | ||
} else { | ||
login.setEnabled(false); | ||
} | ||
|
||
// Preference override_cookies_niconico_value = findPreference(getString(R.string.override_cookies_youtube_value_key)); | ||
// override_cookies_niconico_value.setEnabled(defaultPreferences.getBoolean(getString(R.string.override_cookies_youtube_key), false)); | ||
} | ||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
if (requestCode == REQUEST_LOGIN && resultCode == RESULT_OK) { | ||
String cookies = data.getStringExtra("cookies"); | ||
String pot = data.getStringExtra("pot"); | ||
// save cookies to shared preferences | ||
defaultPreferences.edit().putString(getString(R.string.youtube_cookies_key), cookies).apply(); | ||
// defaultPreferences.edit().putString(getString(R.string.youtube_po_token), pot).apply(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
app/src/main/java/org/schabi/newpipe/views/YouTubeLoginWebViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.schabi.newpipe.views; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.webkit.*; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import org.schabi.newpipe.R; | ||
|
||
public class YouTubeLoginWebViewActivity extends AppCompatActivity { | ||
WebView webView; | ||
String cookies; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.login_webview); | ||
|
||
WebView webView = findViewById(R.id.login_webview); | ||
this.webView = webView; | ||
WebSettings webSettings = webView.getSettings(); | ||
webSettings.setJavaScriptEnabled(true); | ||
webSettings.setUserAgentString("Mozilla/5.0 (Linux; Android 10; Mobile) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36"); | ||
|
||
webView.setWebViewClient(new MyWebViewClient()); | ||
webView.loadUrl("https://www.youtube.com/signin"); | ||
} | ||
|
||
private class MyWebViewClient extends WebViewClient { | ||
@Override | ||
public void onPageFinished(WebView view, String url) { | ||
super.onPageFinished(view, url); | ||
if (url.equals("https://m.youtube.com/?noapp=1") || url.equals("https://m.youtube.com/")) { | ||
setCookies(CookieManager.getInstance().getCookie(url)); | ||
webView.loadUrl("https://music.youtube.com/watch?v=09839DpTctU"); | ||
} | ||
} | ||
|
||
@Override | ||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { | ||
String url = request.getUrl().toString(); | ||
// Filter specific requests | ||
if (url.contains("googlevideo.com/videoplayback")) { | ||
Uri uri = Uri.parse(url); | ||
String pot = uri.getQueryParameter("pot"); | ||
Intent intent = new Intent(); | ||
intent.putExtra("cookies", cookies); | ||
intent.putExtra("pot", pot); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} | ||
// Return null to allow the WebView to load the request as usual | ||
return null; | ||
} | ||
} | ||
|
||
// private void showNonDismissableDialog() { | ||
// AlertDialog.Builder builder = new AlertDialog.Builder(this); | ||
// builder.setTitle(getString(R.string.continue_title)); | ||
// builder.setMessage(getString(R.string.youtube_login_instruction)); | ||
// builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { | ||
// @Override | ||
// public void onClick(DialogInterface dialog, int which) { | ||
// webView.loadUrl("https://music.youtube.com/watch?v=09839DpTctU"); | ||
// } | ||
// }); | ||
// AlertDialog dialog = builder.create(); | ||
// dialog.setCancelable(false); // This makes the dialog non-dismissable | ||
// dialog.setCanceledOnTouchOutside(false); // Prevents dismissal when touching outside | ||
// dialog.show(); | ||
// } | ||
|
||
public void setCookies(String cookies) { | ||
this.cookies = cookies; | ||
} | ||
|
||
public String getCookies() { | ||
return cookies; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:key="general_preferences" | ||
android:title="@string/settings"> | ||
<PreferenceScreen | ||
android:fragment="org.schabi.newpipe.settings.YouTubeAccountSettingsFragment" | ||
android:title="YouTube" | ||
app:iconSpaceReserved="false" /> | ||
</PreferenceScreen> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:title="@string/settings_category_youtube_account_title"> | ||
<Preference | ||
android:key="@string/login_key" | ||
android:summary="@string/login_warning" | ||
android:title="@string/login_title" | ||
app:singleLineTitle="false" | ||
app:iconSpaceReserved="false" /> | ||
<Preference | ||
android:key="@string/logout_key" | ||
android:title="@string/logout_title" | ||
app:singleLineTitle="false" | ||
app:iconSpaceReserved="false" /> | ||
<!-- <SwitchPreferenceCompat--> | ||
<!-- android:defaultValue="false"--> | ||
<!-- android:key="@string/override_cookies_youtube_key"--> | ||
<!-- android:summary="@string/override_cookies_summary"--> | ||
<!-- android:title="@string/override_cookies_title"--> | ||
<!-- app:singleLineTitle="false"--> | ||
<!-- app:iconSpaceReserved="false" />--> | ||
<!-- <EditTextPreference--> | ||
<!-- android:defaultValue=""--> | ||
<!-- android:inputType="text"--> | ||
<!-- android:key="@string/override_cookies_youtube_value_key"--> | ||
<!-- android:title="@string/override_cookies_value_title"--> | ||
<!-- app:singleLineTitle="false"--> | ||
<!-- app:iconSpaceReserved="false" />--> | ||
</PreferenceScreen> |