[Bug] Ytmusic SAPISIDHASH guard/timestamp bugs and silent getMixedForYou failure cause HTTP 401 & infinite loading

オープン
#62 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@AnhNgoo がすでに取り組んでいます。

2026年11月23日 から。

  • #63 @AnhNgoo による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
32/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
kotlin
領域
api

調査の方向性

Read service/kotlinYtmusicScraper/src/commonMain/kotlin/com/maxrave/kotlinytmusicscraper/Ytmusic.kt around lines 254-260 and 270-275, where the SAPISIDHASH guard, timestamp and Authorization header are built; compare against how InnerTube builds the same header for WEB_REMIX. Then read getMixedForYou() in data/src/commonMain/kotlin/com/maxrave/data/repository/PlaylistRepositoryImpl.kt (lines 677-742) next to getLibraryPlaylist() (lines 634-674) to see the missing failure path. Done means the header carries a current Unix-seconds timestamp with the available __Secure-1PAPISID/__Secure-3PAPISID cookies, and the mixed-for-you Flow emits on failure instead of hanging. Note a pull request (#63) is already open, so coordinate before starting.

索引モデルが issue の本文から書いたものです。

説明

Summary

While investigating why the Mix for you (FEmusic_mixed_for_you) tab in SimpMusic v2.6.0 fails with HTTP 401 and hangs on an infinite loading spinner, we traced two bugs in core (multiplatform @ c834002):

1. Broken SAPISIDHASH guard & timestamp in Ytmusic.kt (lines 254-260 & 270-275)

In service/kotlinYtmusicScraper/src/commonMain/kotlin/com/maxrave/kotlinytmusicscraper/Ytmusic.kt:

if ("SAPISID" !in cookieMap || "__Secure-3PAPISID" !in cookieMap) return@let
val currentTime = now().toInstant(TimeZone.currentSystemDefault()).epochSeconds / 1000
val sapisidCookie = cookieMap["SAPISID"] ?: cookieMap["__Secure-3PAPISID"]
val sapisidHash = sha1("$currentTime $sapisidCookie https://music.youtube.com")
append("Authorization", "SAPISIDHASH ${currentTime}_$sapisidHash")
  • Inverted boolean guard (|| instead of &&): Line 256 falls back from SAPISID to __Secure-3PAPISID, but line 254 (and line 270 in getAuthorizationHeader()) aborts with return@let if either cookie is absent. Modern Chromium/Firefox YouTube sessions frequently carry __Secure-3PAPISID (and/or __Secure-1PAPISID) without legacy SAPISID, causing ytClient to omit the Authorization header completely.
  • epochSeconds / 1000 divides seconds by 1000: Instant.epochSeconds is already in Unix seconds (~1.79e9), so dividing by 1000 produces ~1,795,000 (January 1970). When both cookies are present, InnerTube rejects the stale timestamp on strict endpoints like FEmusic_mixed_for_you with HTTP 401 UNAUTHENTICATED.
  • Modern WEB_REMIX requests also send SAPISID1PHASH and SAPISID3PHASH alongside SAPISIDHASH when __Secure-1PAPISID / __Secure-3PAPISID are present.
2. Missing .onFailure in PlaylistRepositoryImpl.getMixedForYou() (lines 677-742)

In data/src/commonMain/kotlin/com/maxrave/data/repository/PlaylistRepositoryImpl.kt:

  • Unlike getLibraryPlaylist() right above it (lines 634-674), getMixedForYou() only chains .onSuccess { ... } on youTube.getMixedForYou() and has no .onFailure { emit(null) } handler (and indexes tabs?.get(0) / contents?.get(0) rather than firstOrNull()).
  • Whenever youTube.getMixedForYou() fails (HTTP 401, offline, or timeout), the Flow completes with zero emissions, causing LibraryViewModel.getYouTubeMixedForYou() in SimpMusic to remain stuck in LocalResource.Loading() indefinitely.
主要言語
Kotlin
スター
25
フォーク
104
平均マージ
1分
マージ済み PR(30日)
2

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。