Skip to content

Commit b30f9e1

Browse files
committed
Fix compilation albums artist reading
1 parent 4e68121 commit b30f9e1

File tree

6 files changed

+56
-17
lines changed

6 files changed

+56
-17
lines changed

src/core/BeatSaberCore.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ export class BeatSaberCore {
9999

100100
if (BeatSaber.Settings.bsaberUsername && BeatSaber.Settings) {
101101
Spicetify.showNotification("Syncing bookmarks...")
102-
const keys = await BeatSaber.Api.getBookmarkKeys(BeatSaber.Settings.bsaberUsername)
103-
const storedKeys = await BeatSaber.Storage.Map.getKeys(MapCategory.BOOKMARKED)
102+
const keys = await BeatSaber.Api.getBookmarkKeys(
103+
BeatSaber.Settings.bsaberUsername
104+
)
105+
const storedKeys = await BeatSaber.Storage.Map.getKeys(
106+
MapCategory.BOOKMARKED
107+
)
104108
const missingPages = new Set<number>()
105109

106110
keys.forEach((key, index) => {
@@ -111,16 +115,24 @@ export class BeatSaberCore {
111115

112116
for (const page of missingPages) {
113117
Spicetify.showNotification(`Getting bookmarks page ${page}...`)
114-
const bookmarks = await BeatSaber.Api.getBookmarks(BeatSaber.Settings.bsaberUsername, page)
115-
await BeatSaber.Storage.Map.put(MapCategory.BOOKMARKED, ...bookmarks)
118+
const bookmarks = await BeatSaber.Api.getBookmarks(
119+
BeatSaber.Settings.bsaberUsername,
120+
page
121+
)
122+
await BeatSaber.Storage.Map.put(
123+
MapCategory.BOOKMARKED,
124+
...bookmarks
125+
)
116126
}
117127
}
118128

119129
Spicetify.showNotification("Syncing downloads...")
120130
const downloads = await BeatSaber.Api.getDownloads()
121131
await BeatSaber.Storage.Map.put(MapCategory.DOWNLOADED, ...downloads)
122132

123-
Spicetify.showNotification(`Added ${bookmarkCount || "no"} new bookmarks`)
133+
Spicetify.showNotification(
134+
`Added ${bookmarkCount || "no"} new bookmarks`
135+
)
124136
}
125137

126138
public initializeSubApp(window: Window) {

src/core/api/ApiUtils.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export class ApiUtils {
1717
BeastSaber = new BeastSaber()
1818

1919
constructor() {
20-
this.BeastSaber.setRequestHandler(new BackendRequestHandler("bsaber.com"))
20+
this.BeastSaber.setRequestHandler(
21+
new BackendRequestHandler("bsaber.com")
22+
)
2123
}
2224

2325
async getTrackMetadata(uri: Spicetify.URI): Promise<BridgeTrack> {
@@ -51,8 +53,11 @@ export class ApiUtils {
5153
}
5254

5355
private async login() {
54-
if (!await this.BeastSaber.isLoggedIn()) {
55-
await this.BeastSaber.login(BeatSaber.Settings.bsaberLogin, BeatSaber.Settings.bsaberPassword)
56+
if (!(await this.BeastSaber.isLoggedIn())) {
57+
await this.BeastSaber.login(
58+
BeatSaber.Settings.bsaberLogin,
59+
BeatSaber.Settings.bsaberPassword
60+
)
5661
}
5762
}
5863

src/core/queue/requests/MapsRequest.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { SortOrder } from "beatsaver-api/lib/api/search"
21
import { Track, TrackState } from "../../models/Track"
32
import { TrackQueueRequest } from "../base/TrackQueueRequest"
43

src/ui/watchers/AlbumWatcher.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ export class AlbumWatcher extends BaseWatcher<HTMLDivElement> {
1111
mount(child: Element): BaseWatcher<Element> {
1212
if (!isHTMLDiv(child)) return
1313

14+
const stickyHeaderRow = <HTMLTableRowElement>(
15+
child.querySelector("table.Table__sticky-header-table > thead > tr")
16+
)
17+
if (!stickyHeaderRow.querySelector(".TableCellBeatSaber")) {
18+
stickyHeaderRow.insertCell(2).className = "TableCellBeatSaber"
19+
}
20+
1421
const artists = []
1522
child
1623
.querySelectorAll(".AlbumMetaInfo__artists a")
@@ -19,14 +26,16 @@ export class AlbumWatcher extends BaseWatcher<HTMLDivElement> {
1926
artists.push(artist.textContent.trim())
2027
})
2128

22-
const stickyHeaderRow = <HTMLTableRowElement>(
23-
child.querySelector("table.Table__sticky-header-table > thead > tr")
24-
)
25-
if (!stickyHeaderRow.querySelector(".TableCellBeatSaber")) {
26-
stickyHeaderRow.insertCell(2).className = "TableCellBeatSaber"
29+
const table = <HTMLTableElement>child.querySelector(".Table > table")
30+
31+
if (!artists.length && child.querySelector(".AlbumMetaInfo__artists")) {
32+
// probably a compilation
33+
return new TracklistWatcher(
34+
table,
35+
TracklistTypes.ALBUM_REACT_COMPILATION
36+
)
2737
}
2838

29-
const table = <HTMLTableElement>child.querySelector(".Table > table")
3039
return new TracklistWatcher(table, TracklistTypes.ALBUM_REACT, artists)
3140
}
3241
}

src/ui/watchers/TrackWatcher.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class TrackWatcher extends BaseWatcher<HTMLTableRowElement> {
5151
const uri = Spicetify.URI.fromString(
5252
this.root.getAttribute(this.type.uriAttribute)
5353
)
54-
const artists = this.artists ? [...this.artists] : []
54+
let artists = this.artists ? [...this.artists] : []
5555
const title = this.root
5656
.querySelector(this.type.titleQuery)
5757
?.textContent?.trim()
@@ -64,7 +64,9 @@ export class TrackWatcher extends BaseWatcher<HTMLTableRowElement> {
6464
artists.push(artist.textContent.trim())
6565
})
6666

67-
if (!uri || !artists || !title) return
67+
artists = artists.filter((artist) => !!artist)
68+
69+
if (!uri || !artists.length || !title) return
6870

6971
if (!Spicetify.URI.isTrack(uri)) return
7072

src/ui/watchers/TracklistType.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,16 @@ export class TracklistTypes {
6363
artistsQuery: ".TableCellSong__featuredArtists a",
6464
artistsQueryUnavailable: ".TableCellSong__featuredArtists span",
6565
}
66+
static readonly ALBUM_REACT_COMPILATION: TracklistType = {
67+
hasHeader: true,
68+
uriAttribute: "data-ta-uri",
69+
headerClass: "TableHeaderRow",
70+
cellIndex: 2,
71+
cellQuery: ".TableCellBeatSaber",
72+
cellClass: "TableCell TableCellBeatSaber",
73+
cellHeaderClass: "TableCellBeatSaber",
74+
titleQuery: ".TableCellSong__track-name",
75+
artistsQuery: ".TableCellArtists > span a",
76+
artistsQueryUnavailable: ".TableCellArtists > span span",
77+
}
6678
}

0 commit comments

Comments
 (0)