Skip to content

Commit

Permalink
fix music search TLs
Browse files Browse the repository at this point in the history
  • Loading branch information
NeloBlivion authored Dec 27, 2024
1 parent 7f4d884 commit 20f86f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/components/media/CommentSongParser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ export default {
methods: {
async getAutocomplete(query) {
// this.isLoading = true;
const res = await this.searchAutocomplete(query, "ja_jp");
const resEn = await this.searchAutocomplete(query, "en_us");
const res = await this.searchAutocompleteAlternative(query, "JP");
const resEn = await this.searchAutocompleteAlternative(query, "US");
// const res = await this.searchAutocomplete(query, "ja_jp");
// const resEn = await this.searchAutocomplete(query, "en_us");
const lookupEn = resEn.results || [];
console.log(lookupEn);
const fnLookupFn = (id, name, altName) => {
const foundEn = lookupEn.find((x) => x.trackId === id);
if (!foundEn) return altName || name;
const possibleNames = [foundEn.trackCensoredName?.toUpperCase(), foundEn.trackName.toUpperCase()];
if (foundEn && !possibleNames.includes(name.toUpperCase()) && compareTwoStrings(foundEn.trackName, name) < 0.75) {
return `${name} / ${foundEn.trackCensoredName || foundEn.trackName}`;
Expand Down Expand Up @@ -253,6 +256,16 @@ export default {
});
},
async searchAutocompleteAlternative(query, country = "JP") {
return jsonp("https://itunes.apple.com/search", {
term: query,
entity: "musicTrack",
country,
limit: 3,
lang: "ja_jp",
});
},
async tryLooking({ /* index, */ start_time, end_time, tokens }, token, idx) {
console.log(tokens);
Expand Down
21 changes: 19 additions & 2 deletions src/components/media/SongSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ export default {
this.isLoading = true;
const [md, res, resEn] = await Promise.all([
this.searchMusicdex(query),
this.searchRegions(query, "ja_jp"),
this.searchRegions(query, "en_us"),
this.searchRegionsAlternative(query, "JP"), // this.searchRegions(query, "ja_jp"),
this.searchRegionsAlternative(query, "US"), // this.searchRegions(query, "en_us"),
]);
const lookupEn = resEn || [];
console.log(lookupEn);
const fnLookupFn = (id, name, altName) => {
const foundEn = lookupEn.find((x) => x.trackId === id);
if (!foundEn) return altName || name;
const possibleNames = [
foundEn.trackCensoredName?.toUpperCase(),
foundEn.trackName.toUpperCase(),
Expand Down Expand Up @@ -236,6 +237,22 @@ export default {
};
return regionSongs;
},
async searchRegionsAlternative(query, lang = "JP", regions: Array<String> = ["ja_jp", 'en_us']) {
// Order langs by highest to lowest priority; missing IDs will merge in.
const regionSongs = [];
let parsedIDs = [];
for (const r of regions) {
const queryed = await this.searchAutocomplete(query, r, lang);
const currentSongs = queryed.results || [];
for (const song of currentSongs) {
if (!parsedIDs.includes(song.trackId)) {
parsedIDs.push(song.trackId)
regionSongs.push(song)
}
}
};
return regionSongs;
},
async searchMusicdex(query) {
try {
const resp = await axiosInstance({
Expand Down

0 comments on commit 20f86f5

Please sign in to comment.