Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b8918d45d | ||
|
|
9bab0d6a24 | ||
|
|
d8d6ef4196 | ||
|
|
661d7ee72c | ||
|
|
5ae9bc4431 |
@@ -26,10 +26,18 @@ mit Hintergrundwiedergabe und Discord Rich Presence. Ohne YouTube-Tab und ohne S
|
|||||||
Über den zweiten runden Knopf am rechten Rand einen Jam starten (der gerade laufende Song wird der
|
Über den zweiten runden Knopf am rechten Rand einen Jam starten (der gerade laufende Song wird der
|
||||||
erste) oder per Code beitreten; einladen über „Link teilen“. Einladungslinks
|
erste) oder per Code beitreten; einladen über „Link teilen“. Einladungslinks
|
||||||
`https://jam.fojadrachi.de/<CODE>` und `playtube://jam/<CODE>` öffnen direkt die App; YouTube-Links
|
`https://jam.fojadrachi.de/<CODE>` und `playtube://jam/<CODE>` öffnen direkt die App; YouTube-Links
|
||||||
aus anderen Apps über „Teilen › Jam“ hinzufügen. Gespielt wird in der YouTube-Music-Ansicht der App,
|
aus anderen Apps über „Teilen › Jam“ hinzufügen – auch ganze Playlists und Alben (Playlist-Link);
|
||||||
|
mehrere Songs laufen automatisch nacheinander. Gespielt wird in der YouTube-Music-Ansicht der App,
|
||||||
die sich mit dem Jam abgleicht ([JamSync.kt](app/src/main/java/de/fojadrachi/playtube/JamSync.kt),
|
die sich mit dem Jam abgleicht ([JamSync.kt](app/src/main/java/de/fojadrachi/playtube/JamSync.kt),
|
||||||
[JamHub.kt](app/src/main/java/de/fojadrachi/playtube/JamHub.kt)). Mitspielen können Playtube am PC
|
[JamHub.kt](app/src/main/java/de/fojadrachi/playtube/JamHub.kt)). Mitspielen können Playtube am PC
|
||||||
(ab 2.2.0) und Freunde im Browser; der Dienst liegt im Projekt `playtube-jam`.
|
(ab 2.2.0) und Freunde im Browser; der Dienst liegt im Projekt `playtube-jam`.
|
||||||
|
- **Diagnosedaten** (standardmäßig an, abschaltbar über das Zahnrad am rechten Rand; beim ersten
|
||||||
|
Start erscheint ein Hinweis): Abstürze und Verbindungsfehler landen in einem kleinen eigenen Log
|
||||||
|
(`files/diag.log`), das die App kurz nach dem Start höchstens alle 6 Stunden gefiltert an den
|
||||||
|
Playtube-Dienst schickt (`/api/diag` im Projekt `playtube-jam`, 30 Tage gespeichert). Ohne Cookies,
|
||||||
|
Anmeldedaten, Suchanfragen, Songtitel oder Video-IDs
|
||||||
|
([DiagReport.kt](app/src/main/java/de/fojadrachi/playtube/DiagReport.kt),
|
||||||
|
[Diagnostics.kt](app/src/main/java/de/fojadrachi/playtube/Diagnostics.kt)).
|
||||||
- **Links** zu `music.youtube.com` öffnen sich in Playtube.
|
- **Links** zu `music.youtube.com` öffnen sich in Playtube.
|
||||||
- **Updates** aus den eigenen Releases (Tag `vX.Y.Z-android`), kein GitHub, kein Play Store.
|
- **Updates** aus den eigenen Releases (Tag `vX.Y.Z-android`), kein GitHub, kein Play Store.
|
||||||
|
|
||||||
@@ -121,6 +129,7 @@ von Playtube fragen ein anderes Repo ab und sehen sie nie.
|
|||||||
| `NowPlaying.kt` | Datensatz „läuft gerade" |
|
| `NowPlaying.kt` | Datensatz „läuft gerade" |
|
||||||
| `UpdateChecker.kt` | Update-Prüfung über die Gitea-Releases |
|
| `UpdateChecker.kt` | Update-Prüfung über die Gitea-Releases |
|
||||||
| `DiscordPresence.kt`, `PresencePlan.kt`, `cpp/` | Discord Rich Presence: was angezeigt wird, und die Brücke zum SDK |
|
| `DiscordPresence.kt`, `PresencePlan.kt`, `cpp/` | Discord Rich Presence: was angezeigt wird, und die Brücke zum SDK |
|
||||||
|
| `Diagnostics.kt`, `DiagReport.kt` | Diagnose-Log, Absturz-Handler, Filter und Versand an `/api/diag` |
|
||||||
| `UserAgent.kt` | macht die WebView-Kennung zu einer normalen Chrome-Kennung (Google-Anmeldung) |
|
| `UserAgent.kt` | macht die WebView-Kennung zu einer normalen Chrome-Kennung (Google-Anmeldung) |
|
||||||
| `PcRemote.kt`, `PcSession.kt`, `PcRemoteService.kt`, `PcRemoteActivity.kt`, `ImageCache.kt` | „PC steuern“: Protokoll, dauerhafte Verbindung (Vordergrunddienst), Fernbedienung, Cover-Cache |
|
| `PcRemote.kt`, `PcSession.kt`, `PcRemoteService.kt`, `PcRemoteActivity.kt`, `ImageCache.kt` | „PC steuern“: Protokoll, dauerhafte Verbindung (Vordergrunddienst), Fernbedienung, Cover-Cache |
|
||||||
|
|
||||||
@@ -137,3 +146,13 @@ von Playtube fragen ein anderes Repo ab und sehen sie nie.
|
|||||||
App-Aktivität).
|
App-Aktivität).
|
||||||
- Kein Like-/Wiederholen-/Zufalls-Knopf in der Benachrichtigung; die Bedienung der Seite selbst
|
- Kein Like-/Wiederholen-/Zufalls-Knopf in der Benachrichtigung; die Bedienung der Seite selbst
|
||||||
funktioniert normal.
|
funktioniert normal.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## English
|
||||||
|
|
||||||
|
**Diagnostics** (on by default, can be turned off via the gear button on the right edge; a notice is
|
||||||
|
shown on first start): crashes and connection errors are written to a small app log
|
||||||
|
(`files/diag.log`) that the app sends, filtered, to the Playtube service (`/api/diag` in the
|
||||||
|
`playtube-jam` project) shortly after start and at most every 6 hours. Reports are kept for 30 days.
|
||||||
|
No cookies, sign-in data, searches, song titles or video IDs are sent.
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ android {
|
|||||||
applicationId = "de.fojadrachi.playtube"
|
applicationId = "de.fojadrachi.playtube"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 7
|
versionCode = 10
|
||||||
versionName = "1.4.0"
|
versionName = "1.6.0"
|
||||||
|
|
||||||
// Update-Quelle: eigener Gitea-Server (kein GitHub/Google Play).
|
// Update-Quelle: eigener Gitea-Server (kein GitHub/Google Play).
|
||||||
buildConfigField("String", "UPDATE_SERVER", "\"https://git.fojadrachi.de\"")
|
buildConfigField("String", "UPDATE_SERVER", "\"https://git.fojadrachi.de\"")
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import org.json.JSONArray
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reine Logik fuer Diagnoseberichte (ohne Android, mit Unit-Tests): Logzeilen filtern und
|
||||||
|
* den Bericht fuer `POST /api/diag` (playtube-jam) bauen. Versand und Log-Datei: [Diagnostics].
|
||||||
|
*
|
||||||
|
* Nicht gesendet werden Cookies, Tokens, Anmeldedaten, Suchanfragen, Songtitel, Video-IDs,
|
||||||
|
* E-Mail-Adressen und URL-Parameter.
|
||||||
|
*/
|
||||||
|
object DiagReport {
|
||||||
|
const val MAX_LINES = 300
|
||||||
|
const val MAX_LINE_CHARS = 480
|
||||||
|
|
||||||
|
private val COOKIE = Regex("(?i)\\b(cookie|set-cookie|authorization)\\b.*")
|
||||||
|
private val BEARER = Regex("(?i)\\bbearer\\s+\\S+")
|
||||||
|
private val SECRET = Regex("(?i)\\b(\\w*token|\\w*key|secret|password|passwort|sapisid)(\\s*[\"']?\\s*[:=]\\s*[\"']?)[^\\s\"'&,;]+")
|
||||||
|
private val EMAIL = Regex("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}")
|
||||||
|
private val URL_QUERY = Regex("(?i)(https?://[^\\s?#\"']+)[?#][^\\s\"']*")
|
||||||
|
private val WORD = Regex("[A-Za-z0-9_-]+")
|
||||||
|
private val CONTROL = Regex("[\\u0000-\\u0008\\u000b-\\u001f\\u007f\\u202a-\\u202e\\u2066-\\u2069]")
|
||||||
|
|
||||||
|
/** YouTube-Video-ID: 11 Zeichen, Gross- und Kleinbuchstaben gemischt plus Ziffer, `_` oder `-`. */
|
||||||
|
fun looksLikeVideoId(word: String): Boolean =
|
||||||
|
word.length == 11 &&
|
||||||
|
word.all { it.isLetterOrDigit() && it.code < 128 || it == '_' || it == '-' } &&
|
||||||
|
word.any { it in 'A'..'Z' } && word.any { it in 'a'..'z' } &&
|
||||||
|
word.any { it.isDigit() || it == '_' || it == '-' }
|
||||||
|
|
||||||
|
private fun looksLikeSecret(word: String): Boolean =
|
||||||
|
word.length >= 20 && word.any { it.isDigit() } && word.any { it.isLetter() }
|
||||||
|
|
||||||
|
fun sanitize(line: String): String {
|
||||||
|
var text = CONTROL.replace(line, " ")
|
||||||
|
text = COOKIE.replace(text) { "${it.groupValues[1].lowercase()} [entfernt]" }
|
||||||
|
text = BEARER.replace(text, "Bearer [entfernt]")
|
||||||
|
text = SECRET.replace(text) { "${it.groupValues[1]}${it.groupValues[2]}[entfernt]" }
|
||||||
|
text = EMAIL.replace(text, "[e-mail]")
|
||||||
|
text = URL_QUERY.replace(text) { "${it.groupValues[1]}?[…]" }
|
||||||
|
text = WORD.replace(text) {
|
||||||
|
when {
|
||||||
|
looksLikeVideoId(it.value) -> "[video]"
|
||||||
|
looksLikeSecret(it.value) -> "[id]"
|
||||||
|
else -> it.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return text.trim().take(MAX_LINE_CHARS)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Collected(val lines: List<String>, val latest: Long)
|
||||||
|
|
||||||
|
/** Zeilen `[secs] text` nach `since` (Unix-Sekunden), gefiltert, hoechstens [MAX_LINES] neueste. */
|
||||||
|
fun collect(logText: String, since: Long): Collected {
|
||||||
|
var latest = since
|
||||||
|
val lines = ArrayList<String>()
|
||||||
|
for (raw in logText.lineSequence()) {
|
||||||
|
if (!raw.startsWith("[")) continue
|
||||||
|
val end = raw.indexOf("] ")
|
||||||
|
if (end < 0) continue
|
||||||
|
val secs = raw.substring(1, end).toLongOrNull() ?: continue
|
||||||
|
if (secs <= since) continue
|
||||||
|
latest = maxOf(latest, secs)
|
||||||
|
lines += "[$secs] ${sanitize(raw.substring(end + 2))}"
|
||||||
|
}
|
||||||
|
return Collected(lines.takeLast(MAX_LINES), latest)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isError(line: String): Boolean {
|
||||||
|
val lower = line.lowercase()
|
||||||
|
return listOf("absturz", "exception", "error", "fehler", "fehlgeschlagen", "failed").any { it in lower }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun build(installId: String, version: String, androidVersion: String, device: String, lines: List<String>, note: String = ""): JSONObject =
|
||||||
|
JSONObject()
|
||||||
|
.put("app", "android")
|
||||||
|
.put("version", version)
|
||||||
|
.put("platform", "android-$androidVersion")
|
||||||
|
.put("os", device)
|
||||||
|
.put("installId", installId)
|
||||||
|
.put("lines", JSONArray(lines))
|
||||||
|
.put("errors", JSONArray(lines.filter(::isError)))
|
||||||
|
.put("note", note)
|
||||||
|
.put("includesTitles", false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import java.io.File
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
import java.net.URL
|
||||||
|
import java.security.SecureRandom
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diagnosedaten: kleines eigenes Log (Abstuerze, Verbindungsfehler) in `files/diag.log`, das
|
||||||
|
* Playtube kurz nach dem Start und hoechstens alle 6 Stunden an den Playtube-Server schickt
|
||||||
|
* (`POST /api/diag`). Standardmaessig an, abschaltbar im Einstellungsdialog.
|
||||||
|
*/
|
||||||
|
object Diagnostics {
|
||||||
|
private const val PREFS = "playtube"
|
||||||
|
private const val KEY_ENABLED = "diag_enabled"
|
||||||
|
private const val KEY_INSTALL_ID = "diag_install_id"
|
||||||
|
private const val KEY_LAST_SENT = "diag_last_sent"
|
||||||
|
private const val KEY_LAST_TRY = "diag_last_try"
|
||||||
|
private const val KEY_NOTICE = "diag_notice_shown"
|
||||||
|
private const val MAX_LOG_BYTES = 256 * 1024
|
||||||
|
private const val INTERVAL_MS = 6 * 3600 * 1000L
|
||||||
|
private const val TIMEOUT_MS = 10_000
|
||||||
|
|
||||||
|
private var appContext: Context? = null
|
||||||
|
private val main = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
|
fun init(context: Context) {
|
||||||
|
if (appContext != null) return
|
||||||
|
appContext = context.applicationContext
|
||||||
|
val previous = Thread.getDefaultUncaughtExceptionHandler()
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler { thread, error ->
|
||||||
|
// Absturz sofort ins Log - gesendet wird beim naechsten Start.
|
||||||
|
line("Absturz in ${thread.name}: ${error.stackTraceToString().take(3000)}")
|
||||||
|
previous?.uncaughtException(thread, error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun prefs(context: Context) = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
fun isEnabled(context: Context): Boolean = prefs(context).getBoolean(KEY_ENABLED, true)
|
||||||
|
|
||||||
|
fun setEnabled(context: Context, enabled: Boolean) {
|
||||||
|
prefs(context).edit().putBoolean(KEY_ENABLED, enabled).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Einmaliger Hinweis, dass Diagnosedaten gesendet werden (Opt-out). */
|
||||||
|
fun needsNotice(context: Context): Boolean = !prefs(context).getBoolean(KEY_NOTICE, false)
|
||||||
|
|
||||||
|
fun noticeShown(context: Context) {
|
||||||
|
prefs(context).edit().putBoolean(KEY_NOTICE, true).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun installId(context: Context): String {
|
||||||
|
val prefs = prefs(context)
|
||||||
|
prefs.getString(KEY_INSTALL_ID, null)?.takeIf { it.isNotBlank() }?.let { return it }
|
||||||
|
val bytes = ByteArray(12).also { SecureRandom().nextBytes(it) }
|
||||||
|
val id = bytes.joinToString("") { "%02x".format(it) }
|
||||||
|
prefs.edit().putString(KEY_INSTALL_ID, id).apply()
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun logFile(context: Context) = File(context.filesDir, "diag.log")
|
||||||
|
|
||||||
|
/** Zeile ins Diagnose-Log schreiben (thread-sicher, auch ohne Versand-Erlaubnis lokal). */
|
||||||
|
@Synchronized
|
||||||
|
fun line(text: String) {
|
||||||
|
val context = appContext ?: return
|
||||||
|
runCatching {
|
||||||
|
val file = logFile(context)
|
||||||
|
if (file.length() > MAX_LOG_BYTES) {
|
||||||
|
// Aeltere Haelfte verwerfen.
|
||||||
|
val keep = file.readText().takeLast(MAX_LOG_BYTES / 2)
|
||||||
|
file.writeText(keep.substring(keep.indexOf('\n') + 1))
|
||||||
|
}
|
||||||
|
file.appendText("[${System.currentTimeMillis() / 1000}] ${text.replace('\n', ' ')}\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Automatisch senden (Start): nur wenn an, neue Zeilen da und der letzte Versuch >= 6 h her ist. */
|
||||||
|
fun sendIfDue(context: Context) {
|
||||||
|
if (!isEnabled(context)) return
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
if (now - prefs(context).getLong(KEY_LAST_TRY, 0) < INTERVAL_MS) return
|
||||||
|
send(context) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Senden; [done] bekommt (null = nichts Neues, true/false = Erfolg) auf dem Hauptthread. */
|
||||||
|
fun send(context: Context, done: (Boolean?) -> Unit) {
|
||||||
|
val ctx = context.applicationContext
|
||||||
|
Thread {
|
||||||
|
val prefs = prefs(ctx)
|
||||||
|
val text = runCatching { logFile(ctx).readText() }.getOrDefault("")
|
||||||
|
val collected = DiagReport.collect(text, prefs.getLong(KEY_LAST_SENT, 0))
|
||||||
|
if (collected.lines.isEmpty()) {
|
||||||
|
main.post { done(null) }
|
||||||
|
return@Thread
|
||||||
|
}
|
||||||
|
prefs.edit().putLong(KEY_LAST_TRY, System.currentTimeMillis()).apply()
|
||||||
|
val body = DiagReport.build(
|
||||||
|
installId(ctx),
|
||||||
|
BuildConfig.VERSION_NAME,
|
||||||
|
Build.VERSION.RELEASE ?: "?",
|
||||||
|
"${Build.MANUFACTURER} ${Build.MODEL}".take(80),
|
||||||
|
collected.lines,
|
||||||
|
)
|
||||||
|
val ok = post("${BuildConfig.JAM_SERVER}/api/diag", body.toString())
|
||||||
|
if (ok) prefs.edit().putLong(KEY_LAST_SENT, collected.latest).apply()
|
||||||
|
main.post { done(ok) }
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun post(url: String, json: String): Boolean =
|
||||||
|
try {
|
||||||
|
val connection = URL(url).openConnection() as HttpURLConnection
|
||||||
|
connection.connectTimeout = TIMEOUT_MS
|
||||||
|
connection.readTimeout = TIMEOUT_MS
|
||||||
|
connection.requestMethod = "POST"
|
||||||
|
connection.doOutput = true
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json")
|
||||||
|
connection.setRequestProperty("User-Agent", "Playtube-Android/${BuildConfig.VERSION_NAME}")
|
||||||
|
try {
|
||||||
|
connection.outputStream.use { it.write(json.toByteArray()) }
|
||||||
|
connection.responseCode == HttpURLConnection.HTTP_OK
|
||||||
|
} finally {
|
||||||
|
connection.disconnect()
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -140,7 +140,17 @@ class JamActivity : AppCompatActivity() {
|
|||||||
if (nameInput.text.isNotBlank()) joinJam(code) else nameInput.requestFocus()
|
if (nameInput.text.isNotBlank()) joinJam(code) else nameInput.requestFocus()
|
||||||
}
|
}
|
||||||
Intent.ACTION_SEND -> {
|
Intent.ACTION_SEND -> {
|
||||||
val videoId = JamSync.videoIdFromSharedText(intent.getStringExtra(Intent.EXTRA_TEXT)) ?: return
|
val shared = intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||||
|
val playlistId = JamSync.playlistIdFromSharedText(shared)
|
||||||
|
if (playlistId != null && JamHub.active) {
|
||||||
|
JamHub.addPlaylist(playlistId)
|
||||||
|
Toast.makeText(this, R.string.jam_playlist_adding, Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val videoId = JamSync.videoIdFromSharedText(shared) ?: run {
|
||||||
|
if (playlistId != null) status.setText(R.string.jam_share_no_jam)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (JamHub.active) {
|
if (JamHub.active) {
|
||||||
JamHub.addVideo(videoId)
|
JamHub.addVideo(videoId)
|
||||||
Toast.makeText(this, R.string.jam_added_shared, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.jam_added_shared, Toast.LENGTH_SHORT).show()
|
||||||
@@ -186,6 +196,13 @@ class JamActivity : AppCompatActivity() {
|
|||||||
val text = addInput.text.toString().trim()
|
val text = addInput.text.toString().trim()
|
||||||
if (text.isEmpty()) return
|
if (text.isEmpty()) return
|
||||||
val videoId = JamSync.parseVideoId(text)
|
val videoId = JamSync.parseVideoId(text)
|
||||||
|
val playlistId = if (videoId == null) JamSync.parsePlaylistId(text) else null
|
||||||
|
if (playlistId != null) {
|
||||||
|
JamHub.addPlaylist(playlistId)
|
||||||
|
addInput.setText("")
|
||||||
|
status.setText(R.string.jam_playlist_adding)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (videoId != null) {
|
if (videoId != null) {
|
||||||
JamHub.addVideo(videoId)
|
JamHub.addVideo(videoId)
|
||||||
addInput.setText("")
|
addInput.setText("")
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ object JamHub {
|
|||||||
private var pendingLoad: Pair<String, Long>? = null
|
private var pendingLoad: Pair<String, Long>? = null
|
||||||
private var stuckSince: Pair<String, Long>? = null
|
private var stuckSince: Pair<String, Long>? = null
|
||||||
private var diverge = 0
|
private var diverge = 0
|
||||||
|
/** Song beim Beitreten ("" = keiner) - zaehlt nicht als Wunsch; beim Starten null = noch offen. */
|
||||||
|
private var baseline: String? = null
|
||||||
|
private val picked = HashSet<String>()
|
||||||
var lastDuration = 0.0
|
var lastDuration = 0.0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@@ -101,9 +104,15 @@ object JamHub {
|
|||||||
val body = JSONObject().put("name", displayName).put("client", "android").toString()
|
val body = JSONObject().put("name", displayName).put("client", "android").toString()
|
||||||
val request = Request.Builder().url("$server/api/jam").post(body.toRequestBody("application/json".toMediaType())).build()
|
val request = Request.Builder().url("$server/api/jam").post(body.toRequestBody("application/json".toMediaType())).build()
|
||||||
http.newCall(request).enqueue(object : Callback {
|
http.newCall(request).enqueue(object : Callback {
|
||||||
override fun onFailure(call: Call, e: IOException) { main.post { setStatus(str(R.string.jam_status_failed)) } }
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
|
Diagnostics.line("jam: Anlegen fehlgeschlagen: $e")
|
||||||
|
main.post { setStatus(str(R.string.jam_status_failed)) }
|
||||||
|
}
|
||||||
override fun onResponse(call: Call, response: Response) {
|
override fun onResponse(call: Call, response: Response) {
|
||||||
val text = response.use { if (it.isSuccessful) it.body?.string() else null }
|
val text = response.use {
|
||||||
|
if (!it.isSuccessful) Diagnostics.line("jam: Anlegen fehlgeschlagen: HTTP ${it.code}")
|
||||||
|
if (it.isSuccessful) it.body?.string() else null
|
||||||
|
}
|
||||||
main.post {
|
main.post {
|
||||||
val json = text?.let { runCatching { JSONObject(it) }.getOrNull() }
|
val json = text?.let { runCatching { JSONObject(it) }.getOrNull() }
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
@@ -131,9 +140,13 @@ object JamHub {
|
|||||||
setStatus(str(R.string.jam_status_joining))
|
setStatus(str(R.string.jam_status_joining))
|
||||||
val request = Request.Builder().url("$server/api/jam/$joinCode").build()
|
val request = Request.Builder().url("$server/api/jam/$joinCode").build()
|
||||||
http.newCall(request).enqueue(object : Callback {
|
http.newCall(request).enqueue(object : Callback {
|
||||||
override fun onFailure(call: Call, e: IOException) { main.post { setStatus(str(R.string.jam_status_failed)) } }
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
|
Diagnostics.line("jam: Beitreten fehlgeschlagen: $e")
|
||||||
|
main.post { setStatus(str(R.string.jam_status_failed)) }
|
||||||
|
}
|
||||||
override fun onResponse(call: Call, response: Response) {
|
override fun onResponse(call: Call, response: Response) {
|
||||||
val status = response.use { it.code }
|
val status = response.use { it.code }
|
||||||
|
if (status != 200 && status != 404) Diagnostics.line("jam: Beitreten fehlgeschlagen: HTTP $status")
|
||||||
main.post {
|
main.post {
|
||||||
when (status) {
|
when (status) {
|
||||||
200 -> {
|
200 -> {
|
||||||
@@ -160,6 +173,8 @@ object JamHub {
|
|||||||
state = null
|
state = null
|
||||||
unplayable.clear()
|
unplayable.clear()
|
||||||
reported.clear()
|
reported.clear()
|
||||||
|
picked.clear()
|
||||||
|
baseline = null
|
||||||
pendingLoad = null
|
pendingLoad = null
|
||||||
stuckSince = null
|
stuckSince = null
|
||||||
prefs().edit().putString(KEY_CODE, joinCode).putString(KEY_TOKEN, savedToken ?: "").apply()
|
prefs().edit().putString(KEY_CODE, joinCode).putString(KEY_TOKEN, savedToken ?: "").apply()
|
||||||
@@ -190,6 +205,7 @@ object JamHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
||||||
|
Diagnostics.line("jam: Verbindung fehlgeschlagen: $t")
|
||||||
main.post { if (socket === webSocket) lost() }
|
main.post { if (socket === webSocket) lost() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +251,10 @@ object JamHub {
|
|||||||
"ended" -> close(endedText(msg.optString("reason")), forget = true)
|
"ended" -> close(endedText(msg.optString("reason")), forget = true)
|
||||||
"error" -> when (val error = msg.optString("error")) {
|
"error" -> when (val error = msg.optString("error")) {
|
||||||
"not_found", "kicked", "full" -> close(endedText(error), forget = true)
|
"not_found", "kicked", "full" -> close(endedText(error), forget = true)
|
||||||
else -> setStatus(errorText(error))
|
else -> {
|
||||||
|
Diagnostics.line("jam: Server meldet Fehler $error")
|
||||||
|
setStatus(errorText(error))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,6 +275,7 @@ object JamHub {
|
|||||||
"not_allowed" -> str(R.string.jam_error_not_allowed)
|
"not_allowed" -> str(R.string.jam_error_not_allowed)
|
||||||
"queue_full" -> str(R.string.jam_error_queue_full)
|
"queue_full" -> str(R.string.jam_error_queue_full)
|
||||||
"bad_video" -> str(R.string.jam_error_bad_video)
|
"bad_video" -> str(R.string.jam_error_bad_video)
|
||||||
|
"playlist_not_found" -> str(R.string.jam_error_playlist)
|
||||||
"rate_limited" -> str(R.string.jam_error_rate_limited)
|
"rate_limited" -> str(R.string.jam_error_rate_limited)
|
||||||
else -> str(R.string.jam_error_other, error)
|
else -> str(R.string.jam_error_other, error)
|
||||||
}
|
}
|
||||||
@@ -308,6 +328,11 @@ object JamHub {
|
|||||||
send(msg)
|
send(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Ganze Playlist / ganzes Album: der Jam-Server holt die Songs. */
|
||||||
|
fun addPlaylist(playlistId: String) {
|
||||||
|
send(JSONObject().put("t", "addPlaylist").put("playlistId", playlistId))
|
||||||
|
}
|
||||||
|
|
||||||
data class SearchResult(val videoId: String, val title: String, val artist: String, val thumb: String)
|
data class SearchResult(val videoId: String, val title: String, val artist: String, val thumb: String)
|
||||||
|
|
||||||
fun search(query: String, done: (List<SearchResult>?) -> Unit) {
|
fun search(query: String, done: (List<SearchResult>?) -> Unit) {
|
||||||
@@ -366,8 +391,20 @@ object JamHub {
|
|||||||
val duration = probe.optDouble("d", 0.0)
|
val duration = probe.optDouble("d", 0.0)
|
||||||
val scripts = ArrayList<String>()
|
val scripts = ArrayList<String>()
|
||||||
var load: String? = null
|
var load: String? = null
|
||||||
val pause = MediaScripts.forCommand(PlayerCommand.Pause)
|
val pause = JamSync.playScript(false)
|
||||||
val matches = want != null && local.videoId == want.videoId
|
val matches = want != null && local.videoId == want.videoId
|
||||||
|
// In YouTube Music selbst einen Song gestartet: ab in den Jam (wie bei Spotify Jam).
|
||||||
|
if (baseline == null) baseline = local.videoId ?: ""
|
||||||
|
if (!probe.optBoolean("ad")) {
|
||||||
|
JamSync.userPick(s, want, local, baseline)?.let { id ->
|
||||||
|
if (picked.add(id)) {
|
||||||
|
val title = probe.optString("title").takeIf { it.isNotEmpty() && !probe.isNull("title") }
|
||||||
|
val artist = probe.optString("artist").takeIf { it.isNotEmpty() && !probe.isNull("artist") }
|
||||||
|
addVideo(id, title, artist)
|
||||||
|
setStatus(str(R.string.jam_added, title ?: id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (matches) {
|
if (matches) {
|
||||||
pendingLoad = null
|
pendingLoad = null
|
||||||
if (duration > 0) lastDuration = duration
|
if (duration > 0) lastDuration = duration
|
||||||
@@ -430,11 +467,11 @@ object JamHub {
|
|||||||
}
|
}
|
||||||
is JamSync.Step.Seek -> {
|
is JamSync.Step.Seek -> {
|
||||||
expectUntil = now + 3000
|
expectUntil = now + 3000
|
||||||
scripts.add(MediaScripts.forCommand(PlayerCommand.SeekTo((step.pos * 1000).toLong())))
|
scripts.add(JamSync.seekScript(step.pos))
|
||||||
}
|
}
|
||||||
JamSync.Step.Play -> {
|
JamSync.Step.Play -> {
|
||||||
expectUntil = now + 3000
|
expectUntil = now + 3000
|
||||||
scripts.add(MediaScripts.forCommand(PlayerCommand.Play))
|
scripts.add(JamSync.playScript(true))
|
||||||
}
|
}
|
||||||
JamSync.Step.Pause -> {
|
JamSync.Step.Pause -> {
|
||||||
expectUntil = now + 3000
|
expectUntil = now + 3000
|
||||||
|
|||||||
@@ -88,6 +88,28 @@ object JamSync {
|
|||||||
return id?.takeIf { VIDEO_ID.matches(it) }
|
return id?.takeIf { VIDEO_ID.matches(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val PLAYLIST_ID = Regex("^(PL|OLAK5uy_|RD|LL|UU|FL|OL|LM)[A-Za-z0-9_-]{0,80}$")
|
||||||
|
|
||||||
|
/** Playlist-/Album-ID aus einer ID oder einem Link mit `list=`, sonst null. */
|
||||||
|
fun parsePlaylistId(input: String?): String? {
|
||||||
|
val text = input?.trim() ?: return null
|
||||||
|
val raw = if (text.contains("youtube.com") || text.contains("youtu.be") || text.contains("://")) {
|
||||||
|
val rest = text.substringAfter("://", text)
|
||||||
|
val host = rest.substringBefore('/').lowercase().removePrefix("www.").removePrefix("m.").removePrefix("music.")
|
||||||
|
if (host != "youtube.com" && host != "youtu.be") return null
|
||||||
|
rest.substringAfter('?', "").substringBefore('#').split('&')
|
||||||
|
.firstOrNull { it.startsWith("list=") }?.removePrefix("list=") ?: return null
|
||||||
|
} else text
|
||||||
|
val id = raw.removePrefix("VL")
|
||||||
|
return id.takeIf { PLAYLIST_ID.matches(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Playlist-Link (ohne einzelnes Video) aus einem geteilten Text. */
|
||||||
|
fun playlistIdFromSharedText(text: String?): String? =
|
||||||
|
text?.split(Regex("\\s+"))?.firstNotNullOfOrNull { word ->
|
||||||
|
if (parseVideoId(word) == null) parsePlaylistId(word) else null
|
||||||
|
}
|
||||||
|
|
||||||
/** Sucht in einem geteilten Text (z. B. aus der YouTube-App) den ersten YouTube-Link. */
|
/** Sucht in einem geteilten Text (z. B. aus der YouTube-App) den ersten YouTube-Link. */
|
||||||
fun videoIdFromSharedText(text: String?): String? =
|
fun videoIdFromSharedText(text: String?): String? =
|
||||||
text?.split(Regex("\\s+"))?.firstNotNullOfOrNull { parseVideoId(it) }
|
text?.split(Regex("\\s+"))?.firstNotNullOfOrNull { parseVideoId(it) }
|
||||||
@@ -220,25 +242,71 @@ object JamSync {
|
|||||||
fun reachedEnd(local: Local, duration: Double, ended: Boolean): Boolean =
|
fun reachedEnd(local: Local, duration: Double, ended: Boolean): Boolean =
|
||||||
ended || (duration > 0 && local.pos >= duration - 0.6)
|
ended || (duration > 0 && local.pos >= duration - 0.6)
|
||||||
|
|
||||||
/** JavaScript: Stand des Players auf music.youtube.com (wie jam_probe.js am PC). */
|
/**
|
||||||
|
* JavaScript: Stand des Players auf music.youtube.com (wie jam_probe.js am PC). Video-ID, Zeit und
|
||||||
|
* Laenge kommen von der Player-API - so darf man in YouTube Music weiter stoebern, und von
|
||||||
|
* mehreren <video>-Elementen wird nicht das falsche gelesen.
|
||||||
|
*/
|
||||||
const val PROBE = """
|
const val PROBE = """
|
||||||
(function () {
|
(function () {
|
||||||
var video = document.querySelector('video');
|
var player = document.getElementById('movie_player');
|
||||||
|
function api(fn) { return player && typeof player[fn] === 'function'; }
|
||||||
|
var video = (player && player.querySelector('video')) || document.querySelector('video');
|
||||||
var id = null;
|
var id = null;
|
||||||
try { if (location.pathname === '/watch') { id = new URL(location.href).searchParams.get('v'); } } catch (e) { id = null; }
|
try { var data = api('getVideoData') ? player.getVideoData() : null; id = data && data.video_id ? data.video_id : null; } catch (e) { id = null; }
|
||||||
|
if (!id) { try { if (location.pathname === '/watch') { id = new URL(location.href).searchParams.get('v'); } } catch (e) { id = null; } }
|
||||||
|
var state = api('getPlayerState') ? player.getPlayerState() : null;
|
||||||
|
var session = navigator.mediaSession ? navigator.mediaSession.playbackState : 'none';
|
||||||
|
var paused;
|
||||||
|
if (state === 1 || state === 3) { paused = false; }
|
||||||
|
else if (state === 2) { paused = true; }
|
||||||
|
else if (session === 'playing' || session === 'paused') { paused = session === 'paused'; }
|
||||||
|
else { paused = video ? video.paused : true; }
|
||||||
|
var meta = navigator.mediaSession ? navigator.mediaSession.metadata : null;
|
||||||
var ad = !!document.querySelector('.ad-showing, .ad-interrupting');
|
var ad = !!document.querySelector('.ad-showing, .ad-interrupting');
|
||||||
var error = !!document.querySelector('.ytp-error, yt-playability-error-supported-renderers:not([hidden]) .reason');
|
var error = !!document.querySelector('.ytp-error, yt-playability-error-supported-renderers:not([hidden]) .reason');
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
id: id,
|
id: id,
|
||||||
t: video ? video.currentTime : 0,
|
t: api('getCurrentTime') ? player.getCurrentTime() : (video ? video.currentTime : 0),
|
||||||
d: (video && isFinite(video.duration)) ? video.duration : 0,
|
d: api('getDuration') && player.getDuration() > 0 ? player.getDuration() : ((video && isFinite(video.duration)) ? video.duration : 0),
|
||||||
paused: video ? video.paused : true,
|
paused: paused,
|
||||||
ended: video ? video.ended : false,
|
ended: state === 0 || (video ? video.ended : false),
|
||||||
ad: ad,
|
ad: ad,
|
||||||
error: error
|
error: error,
|
||||||
|
title: meta && meta.title ? meta.title : null,
|
||||||
|
artist: meta && meta.artist ? meta.artist : null
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
/** Abspielen/Pausieren/Spulen ueber die Player-API (Rueckfall: das <video> des Players). */
|
||||||
|
fun playScript(play: Boolean): String {
|
||||||
|
val method = if (play) "playVideo" else "pauseVideo"
|
||||||
|
val prop = if (play) "play" else "pause"
|
||||||
|
return "(function(){var p=document.getElementById('movie_player');" +
|
||||||
|
"if(p&&typeof p.$method==='function'){p.$method();return;}" +
|
||||||
|
"var v=p&&p.querySelector('video')||document.querySelector('video');if(v){v.$prop();}})();"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun seekScript(seconds: Double): String {
|
||||||
|
val s = if (seconds.isFinite()) max(0.0, seconds) else 0.0
|
||||||
|
return "(function(){var p=document.getElementById('movie_player');var s=$s;" +
|
||||||
|
"if(p&&typeof p.seekTo==='function'){p.seekTo(s,true);return;}" +
|
||||||
|
"var v=p&&p.querySelector('video')||document.querySelector('video');if(v){v.currentTime=s;}})();"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hat man in YouTube Music selbst einen anderen Song gestartet? Dann kommt er wie bei Spotify Jam
|
||||||
|
* in den Jam. Nicht dazu zaehlen: der Song beim Beitreten ([baseline]), Autoplay am Titelende,
|
||||||
|
* der Start-Vorlauf und Songs, die der Jam schon kennt.
|
||||||
|
*/
|
||||||
|
fun userPick(state: State, want: Target?, local: Local, baseline: String?): String? {
|
||||||
|
val id = local.videoId ?: return null
|
||||||
|
if (local.paused || id == baseline || !VIDEO_ID.matches(id)) return null
|
||||||
|
if (want != null && (want.videoId == id || want.pos < 0 || (want.dur != null && want.pos > want.dur - 3))) return null
|
||||||
|
val known = (listOfNotNull(state.current) + state.queue + state.history).any { it.videoId == id }
|
||||||
|
return if (known) null else id
|
||||||
|
}
|
||||||
|
|
||||||
fun watchUrl(videoId: String): String = "https://music.youtube.com/watch?v=$videoId"
|
fun watchUrl(videoId: String): String = "https://music.youtube.com/watch?v=$videoId"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ import android.os.Bundle
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.CheckBox
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import android.webkit.PermissionRequest
|
import android.webkit.PermissionRequest
|
||||||
import android.webkit.WebChromeClient
|
import android.webkit.WebChromeClient
|
||||||
@@ -58,12 +62,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
Diagnostics.init(this)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
webView = findViewById(R.id.webView)
|
webView = findViewById(R.id.webView)
|
||||||
progress = findViewById(R.id.progress)
|
progress = findViewById(R.id.progress)
|
||||||
keepContentBetweenSystemBars()
|
keepContentBetweenSystemBars()
|
||||||
findViewById<View>(R.id.pcRemoteButton).setOnClickListener { PcRemoteActivity.start(this) }
|
findViewById<View>(R.id.pcRemoteButton).setOnClickListener { PcRemoteActivity.start(this) }
|
||||||
findViewById<View>(R.id.jamButton).setOnClickListener { JamActivity.start(this) }
|
findViewById<View>(R.id.jamButton).setOnClickListener { JamActivity.start(this) }
|
||||||
|
findViewById<View>(R.id.settingsButton).setOnClickListener { showSettings() }
|
||||||
JamHub.init(this)
|
JamHub.init(this)
|
||||||
|
|
||||||
configureWebView()
|
configureWebView()
|
||||||
@@ -91,6 +97,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
handler.post(probeLoop)
|
handler.post(probeLoop)
|
||||||
handler.post(jamLoop)
|
handler.post(jamLoop)
|
||||||
checkForUpdate()
|
checkForUpdate()
|
||||||
|
showDiagnosticsNotice()
|
||||||
|
// Kurz nach dem Start: Absturz vom letzten Mal o. ä. senden (höchstens alle 6 Stunden).
|
||||||
|
handler.postDelayed({ Diagnostics.sendIfDue(this) }, DIAG_DELAY_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
@@ -227,6 +236,58 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Einstellungen / Diagnose
|
||||||
|
|
||||||
|
/** Einmaliger Hinweis: Diagnosedaten sind an (Opt-out) und lassen sich hier abschalten. */
|
||||||
|
private fun showDiagnosticsNotice() {
|
||||||
|
if (!Diagnostics.needsNotice(this)) return
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.diag_notice_title)
|
||||||
|
.setMessage(R.string.diag_notice_message)
|
||||||
|
.setPositiveButton(R.string.diag_notice_ok) { _, _ -> Diagnostics.noticeShown(this) }
|
||||||
|
.setNegativeButton(R.string.diag_notice_off) { _, _ ->
|
||||||
|
Diagnostics.setEnabled(this, false)
|
||||||
|
Diagnostics.noticeShown(this)
|
||||||
|
}
|
||||||
|
.setOnCancelListener { Diagnostics.noticeShown(this) }
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showSettings() {
|
||||||
|
val pad = (20 * resources.displayMetrics.density).toInt()
|
||||||
|
val box = CheckBox(this).apply {
|
||||||
|
setText(R.string.diag_enabled)
|
||||||
|
isChecked = Diagnostics.isEnabled(this@MainActivity)
|
||||||
|
setOnCheckedChangeListener { _, checked -> Diagnostics.setEnabled(this@MainActivity, checked) }
|
||||||
|
}
|
||||||
|
val hint = TextView(this).apply {
|
||||||
|
text = getString(R.string.diag_hint) + "\n\n" + getString(R.string.diag_install_id, Diagnostics.installId(this@MainActivity))
|
||||||
|
setTextIsSelectable(true)
|
||||||
|
alpha = 0.75f
|
||||||
|
}
|
||||||
|
val content = LinearLayout(this).apply {
|
||||||
|
orientation = LinearLayout.VERTICAL
|
||||||
|
setPadding(pad, pad / 2, pad, 0)
|
||||||
|
addView(box)
|
||||||
|
addView(hint)
|
||||||
|
}
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.settings_title)
|
||||||
|
.setView(content)
|
||||||
|
.setPositiveButton(R.string.diag_done, null)
|
||||||
|
.setNeutralButton(R.string.diag_send_now) { _, _ ->
|
||||||
|
Diagnostics.send(this) { ok ->
|
||||||
|
val text = when (ok) {
|
||||||
|
null -> R.string.diag_nothing
|
||||||
|
true -> R.string.diag_sent
|
||||||
|
false -> R.string.diag_failed
|
||||||
|
}
|
||||||
|
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
private fun showUpdateDialog(release: UpdateChecker.Release) {
|
private fun showUpdateDialog(release: UpdateChecker.Release) {
|
||||||
val prefs = getSharedPreferences(PREFS, MODE_PRIVATE)
|
val prefs = getSharedPreferences(PREFS, MODE_PRIVATE)
|
||||||
if (prefs.getString(KEY_DISMISSED_UPDATE, null) == release.tag) return
|
if (prefs.getString(KEY_DISMISSED_UPDATE, null) == release.tag) return
|
||||||
@@ -251,6 +312,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private const val HOME_URL = "https://music.youtube.com/"
|
private const val HOME_URL = "https://music.youtube.com/"
|
||||||
private const val PROBE_INTERVAL_MS = 1500L
|
private const val PROBE_INTERVAL_MS = 1500L
|
||||||
private const val JAM_INTERVAL_MS = 700L
|
private const val JAM_INTERVAL_MS = 700L
|
||||||
|
private const val DIAG_DELAY_MS = 30_000L
|
||||||
private const val PREFS = "playtube"
|
private const val PREFS = "playtube"
|
||||||
private const val KEY_DISMISSED_UPDATE = "dismissed_update"
|
private const val KEY_DISMISSED_UPDATE = "dismissed_update"
|
||||||
|
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ object PcSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
Diagnostics.line("pc: Verbinden fehlgeschlagen: $e")
|
||||||
main.post {
|
main.post {
|
||||||
if (gen != generation) return@post
|
if (gen != generation) return@post
|
||||||
reset()
|
reset()
|
||||||
@@ -293,6 +294,7 @@ object PcSession {
|
|||||||
} catch (e: PcRemote.RemoteException) {
|
} catch (e: PcRemote.RemoteException) {
|
||||||
main.post { done(Result.failure(e)) } // Befehl abgelehnt - Verbindung bleibt
|
main.post { done(Result.failure(e)) } // Befehl abgelehnt - Verbindung bleibt
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
Diagnostics.line("pc: Verbindung verloren: $e")
|
||||||
closeConnection()
|
closeConnection()
|
||||||
main.post {
|
main.post {
|
||||||
if (gen == generation) onConnectionLost()
|
if (gen == generation) onConnectionLost()
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Einstellungen (Material "settings") -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z" />
|
||||||
|
</vector>
|
||||||
@@ -49,4 +49,19 @@
|
|||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:scaleType="fitCenter"
|
android:scaleType="fitCenter"
|
||||||
android:src="@drawable/ic_jam" />
|
android:src="@drawable/ic_jam" />
|
||||||
|
|
||||||
|
<!-- Einstellungen (Diagnosedaten): unter dem Jam-Knopf, etwas kleiner. -->
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/settingsButton"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_gravity="end|center_vertical"
|
||||||
|
android:layout_marginTop="108dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:alpha="0.7"
|
||||||
|
android:background="@drawable/bg_play_button"
|
||||||
|
android:contentDescription="@string/settings_open"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:src="@drawable/ic_settings" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|||||||
@@ -100,8 +100,10 @@
|
|||||||
<string name="jam_remove">Entfernen</string>
|
<string name="jam_remove">Entfernen</string>
|
||||||
<string name="jam_added">Hinzugefügt: %1$s</string>
|
<string name="jam_added">Hinzugefügt: %1$s</string>
|
||||||
<string name="jam_added_shared">Zum Jam hinzugefügt.</string>
|
<string name="jam_added_shared">Zum Jam hinzugefügt.</string>
|
||||||
|
<string name="jam_playlist_adding">Playlist wird hinzugefügt …</string>
|
||||||
|
<string name="jam_error_playlist">Diese Playlist ist nicht öffentlich oder existiert nicht.</string>
|
||||||
<string name="jam_share_no_jam">Du bist gerade in keinem Jam. Starte einen oder tritt einem bei.</string>
|
<string name="jam_share_no_jam">Du bist gerade in keinem Jam. Starte einen oder tritt einem bei.</string>
|
||||||
<string name="jam_play_hint">Die Musik läuft im Player von Playtube. Mit Steuerrecht wirken Play/Pause und Weiter dort und in der Benachrichtigung für alle.</string>
|
<string name="jam_play_hint">Die Musik läuft im Player von Playtube. Du kannst dort weiter in YouTube Music stöbern: Tippst du einen Song an, landet er wie bei Spotify im Jam. Mit Steuerrecht wirken Play/Pause und Weiter dort und in der Benachrichtigung für alle.</string>
|
||||||
<string name="jam_status_creating">Jam wird gestartet …</string>
|
<string name="jam_status_creating">Jam wird gestartet …</string>
|
||||||
<string name="jam_status_joining">Verbinde …</string>
|
<string name="jam_status_joining">Verbinde …</string>
|
||||||
<string name="jam_status_connected">Verbunden.</string>
|
<string name="jam_status_connected">Verbunden.</string>
|
||||||
@@ -143,4 +145,20 @@
|
|||||||
<item name="colorPrimary">@color/brand_from</item>
|
<item name="colorPrimary">@color/brand_from</item>
|
||||||
<item name="colorAccent">@color/brand_to</item>
|
<item name="colorAccent">@color/brand_to</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- Einstellungen / Diagnose -->
|
||||||
|
<string name="settings_open">Einstellungen</string>
|
||||||
|
<string name="settings_title">Playtube-Einstellungen</string>
|
||||||
|
<string name="diag_enabled">Diagnosedaten senden (hilft, Fehler zu finden)</string>
|
||||||
|
<string name="diag_hint">Gesendet werden Fehlermeldungen und Abstürze aus dem Playtube-Log, App- und Android-Version sowie das Gerätemodell mit einer zufälligen Kennung – keine Cookies, Anmeldedaten, Suchanfragen, Songtitel oder Video-IDs. Gespeichert 30 Tage. Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag</string>
|
||||||
|
<string name="diag_install_id">Kennung dieser Installation: %1$s</string>
|
||||||
|
<string name="diag_send_now">Jetzt senden</string>
|
||||||
|
<string name="diag_done">Fertig</string>
|
||||||
|
<string name="diag_sent">Diagnosedaten gesendet.</string>
|
||||||
|
<string name="diag_nothing">Keine neuen Einträge seit dem letzten Bericht.</string>
|
||||||
|
<string name="diag_failed">Senden fehlgeschlagen.</string>
|
||||||
|
<string name="diag_notice_title">Diagnosedaten</string>
|
||||||
|
<string name="diag_notice_message">Damit Fehler schneller behoben werden, sendet Playtube Fehlermeldungen und Abstürze (ohne Cookies, Anmeldedaten, Suchanfragen oder Songtitel) an den Playtube-Server. Du kannst das jederzeit über das Zahnrad abschalten.</string>
|
||||||
|
<string name="diag_notice_ok">OK</string>
|
||||||
|
<string name="diag_notice_off">Abschalten</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class DiagReportTest {
|
||||||
|
@Test
|
||||||
|
fun removesPrivateData() {
|
||||||
|
val cases = mapOf(
|
||||||
|
"Cookie: SAPISID=abc; HSID=def" to "cookie [entfernt]",
|
||||||
|
"jam: lade dQw4w9WgXcQ" to "jam: lade [video]",
|
||||||
|
"GET https://music.youtube.com/search?q=lieblingssong ok" to "GET https://music.youtube.com/search?[…] ok",
|
||||||
|
"token=abcdef123 weiter" to "token=[entfernt] weiter",
|
||||||
|
"{\"last_token\":\"xyz\"}" to "{\"last_token\":\"[entfernt]\"}",
|
||||||
|
"Mail [email protected]" to "Mail [e-mail]",
|
||||||
|
"Playlist PLabcdefghij1234567890XYZ" to "Playlist [id]",
|
||||||
|
"Sende Bearer eyJhbGciOiJIUzI1NiJ9" to "Sende Bearer [entfernt]",
|
||||||
|
)
|
||||||
|
for ((input, expected) in cases) assertEquals(input, expected, DiagReport.sanitize(input))
|
||||||
|
assertEquals("Jam: Verbindung fehlgeschlagen", DiagReport.sanitize("Jam: Verbindung fehlgeschlagen"))
|
||||||
|
assertEquals("a b", DiagReport.sanitize("a\u0000b"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun recognizesVideoIds() {
|
||||||
|
assertTrue(DiagReport.looksLikeVideoId("dQw4w9WgXcQ"))
|
||||||
|
assertFalse(DiagReport.looksLikeVideoId("Verbindunge"))
|
||||||
|
assertFalse(DiagReport.looksLikeVideoId("12345678901"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun collectsOnlyNewLines() {
|
||||||
|
val log = "[100] alt\n[200] Jam: Verbindung fehlgeschlagen\nkaputt\n[202] neu\n"
|
||||||
|
val collected = DiagReport.collect(log, 100)
|
||||||
|
assertEquals(listOf("[200] Jam: Verbindung fehlgeschlagen", "[202] neu"), collected.lines)
|
||||||
|
assertEquals(202L, collected.latest)
|
||||||
|
assertTrue(DiagReport.collect(log, 202).lines.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun keepsTheNewestLines() {
|
||||||
|
val log = (1..1000).joinToString("\n") { "[$it] Zeile $it" }
|
||||||
|
val lines = DiagReport.collect(log, 0).lines
|
||||||
|
assertEquals(DiagReport.MAX_LINES, lines.size)
|
||||||
|
assertEquals("[701] Zeile 701", lines.first())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun buildsReport() {
|
||||||
|
val lines = listOf("[1] Absturz in main: java.lang.IllegalStateException", "[2] ok")
|
||||||
|
val report = DiagReport.build("abc123abc123", "1.6.0", "15", "Google Pixel 9", lines)
|
||||||
|
assertEquals("android", report.getString("app"))
|
||||||
|
assertEquals("android-15", report.getString("platform"))
|
||||||
|
assertEquals(1, report.getJSONArray("errors").length())
|
||||||
|
assertFalse(report.getBoolean("includesTitles"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,6 +42,18 @@ class JamSyncTest {
|
|||||||
assertNull(JamSync.videoIdFromSharedText("kein Link hier"))
|
assertNull(JamSync.videoIdFromSharedText("kein Link hier"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `liest Playlist-Links`() {
|
||||||
|
assertEquals("PLabc_1", JamSync.parsePlaylistId("https://music.youtube.com/playlist?list=PLabc_1"))
|
||||||
|
assertEquals("RDxyz", JamSync.parsePlaylistId("https://www.youtube.com/watch?v=dQw4w9WgXcQ&list=RDxyz"))
|
||||||
|
assertEquals("OLAK5uy_abc", JamSync.parsePlaylistId("OLAK5uy_abc"))
|
||||||
|
assertEquals("PLabc", JamSync.parsePlaylistId("VLPLabc"))
|
||||||
|
assertNull(JamSync.parsePlaylistId("https://evil.example/playlist?list=PLabc"))
|
||||||
|
assertNull(JamSync.parsePlaylistId("queen"))
|
||||||
|
assertEquals("PLabc", JamSync.playlistIdFromSharedText("Hör mal: https://music.youtube.com/playlist?list=PLabc"))
|
||||||
|
assertNull(JamSync.playlistIdFromSharedText("https://youtu.be/dQw4w9WgXcQ?list=PLabc"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `liest den Zustand des Servers`() {
|
fun `liest den Zustand des Servers`() {
|
||||||
val state = JamSync.parseState(
|
val state = JamSync.parseState(
|
||||||
@@ -110,6 +122,33 @@ class JamSyncTest {
|
|||||||
assertFalse(JamSync.reachedEnd(local("a", 150.0, false), 200.0, false))
|
assertFalse(JamSync.reachedEnd(local("a", 150.0, false), 200.0, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `in YouTube Music gestartete Songs kommen in den Jam`() {
|
||||||
|
val item = { id: String, video: String -> JamSync.Item(id, video, "", "", "", 200.0, "", "") }
|
||||||
|
val state = JamSync.State(
|
||||||
|
"ABC234", "m1", "m1", false, true, false, emptyList(),
|
||||||
|
current = item("i1", "aaaaaaaaaaa"), queue = emptyList(), history = listOf(item("i0", "hhhhhhhhhhh")),
|
||||||
|
playback = JamSync.Playback(false, 30.0, 0.0), serverNow = 0.0,
|
||||||
|
)
|
||||||
|
val w = want(30.0)
|
||||||
|
assertEquals("bbbbbbbbbbb", JamSync.userPick(state, w, local("bbbbbbbbbbb", 1.0, false), ""))
|
||||||
|
assertNull(JamSync.userPick(state, w, local("aaaaaaaaaaa", 30.0, false), ""))
|
||||||
|
assertNull(JamSync.userPick(state, w, local("hhhhhhhhhhh", 1.0, false), ""))
|
||||||
|
assertNull(JamSync.userPick(state, w, local("bbbbbbbbbbb", 1.0, true), ""))
|
||||||
|
assertNull(JamSync.userPick(state, w, local("bbbbbbbbbbb", 1.0, false), "bbbbbbbbbbb"))
|
||||||
|
assertNull(JamSync.userPick(state, want(198.5), local("zzzzzzzzzzz", 1.0, false), ""))
|
||||||
|
val empty = state.copy(current = null, history = emptyList())
|
||||||
|
assertEquals("bbbbbbbbbbb", JamSync.userPick(empty, null, local("bbbbbbbbbbb", 1.0, false), ""))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Steuerskripte nutzen die Player-API`() {
|
||||||
|
assertTrue(JamSync.playScript(true).contains("p.playVideo()"))
|
||||||
|
assertTrue(JamSync.playScript(false).contains("p.pauseVideo()"))
|
||||||
|
assertTrue(JamSync.seekScript(12.5).contains("var s=12.5;"))
|
||||||
|
assertTrue(JamSync.seekScript(-4.0).contains("var s=0.0;"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `formatiert Zeit und Code`() {
|
fun `formatiert Zeit und Code`() {
|
||||||
assertEquals("0:00", JamSync.formatTime(0.0))
|
assertEquals("0:00", JamSync.formatTime(0.0))
|
||||||
|
|||||||
@@ -1,10 +1,21 @@
|
|||||||
## Playtube für Android 1.4.0
|
## Playtube für Android 1.6.0
|
||||||
|
|
||||||
- **Playtube Jam:** Gemeinsam hören wie bei Spotify Jam. Über den neuen runden Knopf (zwei Personen) am rechten
|
- **Diagnosedaten:** Damit Fehler schneller behoben werden, schickt Playtube Abstürze und Verbindungsfehler
|
||||||
Rand einen Jam starten – der gerade laufende Song wird der erste – oder per Code beitreten. Freunde einladen
|
(ohne Cookies, Anmeldedaten, Suchanfragen, Songtitel oder Video-IDs) an den Playtube-Server; gespeichert
|
||||||
über „Link teilen“; sie machen mit Playtube für Android, Playtube am PC (ab 2.2.0) oder im Browser mit.
|
wird 30 Tage. Beim ersten Start erscheint ein Hinweis, abschalten geht jederzeit über das neue
|
||||||
Jeder hört synchron auf dem eigenen Gerät, alle wünschen sich Songs (Link einfügen oder in der YouTube-App
|
**Zahnrad** am rechten Rand. Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag
|
||||||
„Teilen › Jam“). Der Host steuert, auf Wunsch dürfen alle steuern. Einladungslinks öffnen direkt die App.
|
|
||||||
|
|
||||||
Alles Weitere wie bisher: YouTube Music, Hintergrundwiedergabe, Sperrbildschirm-Steuerung, PC steuern,
|
Alles Weitere wie in 1.5.0 (Playlists und Alben im Jam, Songs laufen automatisch weiter). Voraussetzung:
|
||||||
Discord Rich Presence, Updates über diese Releases. Voraussetzung: Android 8.0 oder neuer.
|
Android 8.0 oder neuer.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Playtube for Android 1.6.0
|
||||||
|
|
||||||
|
- **Diagnostic data:** to fix bugs faster, Playtube sends crashes and connection errors (no cookies, sign-in data,
|
||||||
|
searches, song titles or video IDs) to the Playtube server; reports are kept for 30 days. A notice is shown on
|
||||||
|
first start, and you can turn it off at any time via the new **gear** button on the right edge.
|
||||||
|
Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag
|
||||||
|
|
||||||
|
Everything else as in 1.5.0 (playlists and albums in the jam, songs continue automatically). Requires Android
|
||||||
|
8.0 or newer.
|
||||||
|
|||||||
Reference in New Issue
Block a user