mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-06 07:29:42 +00:00
Compare commits
3 Commits
59f298a935
...
95e09ffc94
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95e09ffc94 | ||
|
|
968fd09eb3 | ||
|
|
1a32264bc7 |
@ -5,7 +5,7 @@ import 'dart:io';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:dio_http2_adapter/dio_http2_adapter.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart'
|
||||
hide X509Certificate;
|
||||
@ -19,6 +19,7 @@ import 'package:spotube/utils/platform.dart';
|
||||
import 'package:otp_util/otp_util.dart';
|
||||
// ignore: implementation_imports
|
||||
import 'package:otp_util/src/utils/generic_util.dart';
|
||||
import 'package:spotube/utils/service_utils.dart';
|
||||
|
||||
extension ExpirationAuthenticationTableData on AuthenticationTableData {
|
||||
bool get isExpired => DateTime.now().isAfter(expiration);
|
||||
@ -34,13 +35,17 @@ extension ExpirationAuthenticationTableData on AuthenticationTableData {
|
||||
|
||||
class AuthenticationNotifier extends AsyncNotifier<AuthenticationTableData?> {
|
||||
static final Dio dio = () {
|
||||
final dio = Dio();
|
||||
|
||||
(dio.httpClientAdapter as IOHttpClientAdapter)
|
||||
.createHttpClient = () => HttpClient()
|
||||
..badCertificateCallback = (X509Certificate cert, String host, int port) {
|
||||
return host.endsWith("spotify.com") && port == 443;
|
||||
final dio = Dio()
|
||||
..httpClientAdapter = Http2Adapter(
|
||||
ConnectionManager(
|
||||
idleTimeout: const Duration(seconds: 10),
|
||||
onClientCreate: (uri, clientSettings) {
|
||||
clientSettings.onBadCertificate = (X509Certificate cert) {
|
||||
return uri.host.endsWith("spotify.com");
|
||||
};
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return dio;
|
||||
}();
|
||||
@ -163,7 +168,18 @@ class AuthenticationNotifier extends AsyncNotifier<AuthenticationTableData?> {
|
||||
|
||||
final secret = base32FromBytes(secretBytes, secretSauce);
|
||||
|
||||
final res = await dio.get("https://open.spotify.com/server-time");
|
||||
final res = await dio.get(
|
||||
"https://open.spotify.com/server-time",
|
||||
options: Options(
|
||||
headers: {
|
||||
"Host": "open.spotify.com",
|
||||
"User-Agent": ServiceUtils.randomUserAgent(
|
||||
kIsDesktop ? UserAgentDevice.desktop : UserAgentDevice.mobile,
|
||||
),
|
||||
"accept": "*/*",
|
||||
},
|
||||
),
|
||||
);
|
||||
final serverTimeSeconds = res.data["serverTime"] as int;
|
||||
|
||||
final totp = TOTP(
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
|
||||
@ -28,6 +28,11 @@ import 'package:spotube/collections/env.dart';
|
||||
|
||||
import 'package:version/version.dart';
|
||||
|
||||
enum UserAgentDevice {
|
||||
desktop,
|
||||
mobile,
|
||||
}
|
||||
|
||||
abstract class ServiceUtils {
|
||||
static final _englishMatcherRegex = RegExp(
|
||||
"^[a-zA-Z0-9\\s!\"#\$%&\\'()*+,-.\\/:;<=>?@\\[\\]^_`{|}~]*\$",
|
||||
@ -417,4 +422,16 @@ abstract class ServiceUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static int randomNumber(int min, int max) {
|
||||
return min + Random().nextInt(max - min);
|
||||
}
|
||||
|
||||
static String randomUserAgent(UserAgentDevice type) {
|
||||
if (type == UserAgentDevice.desktop) {
|
||||
return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_${randomNumber(11, 15)}_${randomNumber(4, 9)}) AppleWebKit/${randomNumber(530, 537)}.${randomNumber(30, 37)} (KHTML, like Gecko) Chrome/${randomNumber(80, 105)}.0.${randomNumber(3000, 4500)}.${randomNumber(60, 125)} Safari/${randomNumber(530, 537)}.${randomNumber(30, 36)}";
|
||||
} else {
|
||||
return "Mozilla/5.0 (Linux; Android ${randomNumber(8, 13)}) AppleWebKit/${randomNumber(530, 537)}.${randomNumber(30, 36)} (KHTML, like Gecko) Chrome/${randomNumber(101, 116)}.0.${randomNumber(3000, 6000)}.${randomNumber(60, 125)} Mobile Safari/${randomNumber(530, 537)}.${randomNumber(30, 36)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
pubspec.lock
16
pubspec.lock
@ -544,6 +544,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.7.0"
|
||||
dio_http2_adapter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dio_http2_adapter
|
||||
sha256: b8bd5d587fd228a461711f8b82f378ccd4bf1fbf7802e7663ca60d7b5ce0e3aa
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.6.0"
|
||||
dio_web_adapter:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1186,6 +1194,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.2"
|
||||
http2:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http2
|
||||
sha256: "382d3aefc5bd6dc68c6b892d7664f29b5beb3251611ae946a98d35158a82bbfa"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.1"
|
||||
http_methods:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@ -141,6 +141,7 @@ dependencies:
|
||||
http_parser: ^4.1.2
|
||||
collection: any
|
||||
otp_util: ^1.0.2
|
||||
dio_http2_adapter: ^2.6.0
|
||||
|
||||
dev_dependencies:
|
||||
build_runner: ^2.4.13
|
||||
|
||||
Loading…
Reference in New Issue
Block a user