-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add songlink based track matching for youtube and open song lin…
…k button songlink.com will provide accurate match verified by community for most spotify tracks improving overall match accuracy for Youtube audio source
- Loading branch information
Showing
14 changed files
with
565 additions
and
19 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,19 @@ | ||
part of './song_link.dart'; | ||
|
||
@freezed | ||
class SongLink with _$SongLink { | ||
const factory SongLink({ | ||
required String displayName, | ||
required String linkId, | ||
required String platform, | ||
required bool show, | ||
required String? uniqueId, | ||
required String? country, | ||
required String? url, | ||
required String? nativeAppUriMobile, | ||
required String? nativeAppUriDesktop, | ||
}) = _SongLink; | ||
|
||
factory SongLink.fromJson(Map<String, dynamic> json) => | ||
_$SongLinkFromJson(json); | ||
} |
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,47 @@ | ||
library song_link; | ||
|
||
import 'dart:convert'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:html/parser.dart'; | ||
|
||
part 'model.dart'; | ||
|
||
part 'song_link.freezed.dart'; | ||
part 'song_link.g.dart'; | ||
|
||
abstract class SongLinkService { | ||
static Future<List<SongLink>> links(String spotifyId) async { | ||
final dio = Dio(); | ||
|
||
final res = await dio.get( | ||
"https://song.link/s/$spotifyId", | ||
options: Options( | ||
headers: { | ||
"Accept": | ||
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", | ||
"User-Agent": | ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36" | ||
}, | ||
responseType: ResponseType.plain, | ||
), | ||
); | ||
|
||
final document = parse(res.data); | ||
|
||
final script = document.getElementById("__NEXT_DATA__")?.text; | ||
|
||
if (script == null) { | ||
return <SongLink>[]; | ||
} | ||
|
||
final pageProps = jsonDecode(script) as Map<String, dynamic>; | ||
final songLinks = | ||
pageProps["props"]["pageProps"]["pageData"]["sections"].firstWhere( | ||
(section) => section["sectionId"] == "section|auto|links|listen", | ||
)["links"] as List; | ||
|
||
return songLinks.map((link) => SongLink.fromJson(link)).toList(); | ||
} | ||
} |
Oops, something went wrong.