mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-17 01:15:17 +00:00

Configuration File Removals: .vscode/c_cpp_properties.json: Removed the entire configuration for C/C++ properties. .vscode/launch.json: Removed the Dart launch configurations for different environments and modes. .vscode/settings.json: Removed settings related to CMake, spell checking, file nesting, and Dart Flutter SDK path. .vscode/snippets.code-snippets: Removed code snippets for Dart, including PaginatedState and PaginatedNotifier templates. .vscode/tasks.json: Removed the tasks configuration file. Documentation Updates: CONTRIBUTION.md: Removed heart emoji from the introductory text. README.md: Updated the logo image and made minor text adjustments, including removing emojis and updating section titles. [1] [2] [3] [4] [5] Asset Removals: lib/collections/assets.gen.dart: Removed multiple unused asset references, including images related to Spotube logos and banners. [1] [2] [3] Minor Code Cleanups: cli/commands/build/linux.dart, cli/commands/build/windows.dart, cli/commands/translated.dart, cli/commands/untranslated.dart: Adjusted import statements for consistency. [1] [2] [3] [4] integration_test/app_test.dart: Removed an unnecessary blank line. lib/collections/routes.dart: Commented out the TrackRoute configuration.
54 lines
1.6 KiB
Dart
54 lines
1.6 KiB
Dart
library song_link;
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
import 'package:html/parser.dart';
|
|
import 'package:spotube/services/logger/logger.dart';
|
|
|
|
part 'model.dart';
|
|
part 'song_link.freezed.dart';
|
|
part 'song_link.g.dart';
|
|
|
|
abstract class SongLinkService {
|
|
static final dio = Dio();
|
|
static Future<List<SongLink>> links(String spotifyId) async {
|
|
try {
|
|
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() ??
|
|
<SongLink>[];
|
|
} catch (e, stackTrace) {
|
|
AppLogger.reportError(e, stackTrace);
|
|
return <SongLink>[];
|
|
}
|
|
}
|
|
}
|