Skip to content

Commit

Permalink
Fixed #298
Browse files Browse the repository at this point in the history
  • Loading branch information
anandnet committed Oct 13, 2024
1 parent 5f15c42 commit eb6cbdb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/services/background_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ Future<List<dynamic>?> getStreamInfo(String songId) async {
if (songId.substring(0, 4) == "MPED") {
songId = songId.substring(4);
}
final playerResponse = (await PlayerResponse.fetch(songId));
final playerResponse = (await PlayerResponse.fetch(songId,option: 1));
return playerResponse?.hmStreamingData;
}
34 changes: 20 additions & 14 deletions lib/services/music_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MusicServices extends getx.GetxService {
};

final appPrefsBox = Hive.box('AppPrefs');
hlCode = appPrefsBox.get('contentLanguage') ?? "en";
if (appPrefsBox.containsKey('visitorId')) {
final visitorData = appPrefsBox.get("visitorId");
if (visitorData != null && !isExpired(epoch: visitorData['exp'])) {
Expand All @@ -71,20 +72,23 @@ class MusicServices extends getx.GetxService {
}
}

final visitorId = await genrateVisitorId();
if (visitorId != null) {
_headers['X-Goog-Visitor-Id'] = visitorId;
printINFO("New Visitor id generated ($visitorId)");
appPrefsBox.put("visitorId", {
'id': visitorId,
'exp': DateTime.now().millisecondsSinceEpoch ~/ 1000 + 2592000
});
return;
}
// not able to generate in that case
_headers['X-Goog-Visitor-Id'] =
visitorId ?? "CgttN24wcmd5UzNSWSi2lvq2BjIKCgJKUBIEGgAgYQ%3D%3D";

final visitorId = await genrateVisitorId();
if (visitorId != null) {
_headers['X-Goog-Visitor-Id'] = visitorId;
printINFO("New Visitor id generated ($visitorId)");
appPrefsBox.put("visitorId", {
'id': visitorId,
'exp': DateTime.now().millisecondsSinceEpoch ~/ 1000 + 2592000
});
return;
}
// not able to generate in that case
_headers['X-Goog-Visitor-Id'] =
visitorId ?? "CgttN24wcmd5UzNSWSi2lvq2BjIKCgJKUBIEGgAgYQ%3D%3D";
}

set hlCode(String code) {
_context['context']['client']['hl'] = code;
}

Future<String?> genrateVisitorId() async {
Expand Down Expand Up @@ -528,6 +532,7 @@ class MusicServices extends getx.GetxService {
int limit = 30,
bool ignoreSpelling = false}) async {
final data = Map.of(_context);
data['context']['client']["hl"] = 'en';
data['query'] = query;

final Map<String, dynamic> searchResults = {};
Expand Down Expand Up @@ -694,6 +699,7 @@ class MusicServices extends getx.GetxService {
channelId = channelId.substring(4);
}
final data = Map.from(_context);
data['context']['client']["hl"] = 'en';
data['browseId'] = channelId;
dynamic response = (await _sendRequest("browse", data)).data;
dynamic results = nav(response, [...single_column_tab, ...section_list]);
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/screens/Settings/settings_screen_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class SettingsScreenController extends GetxController {

void setAppLanguage(String? val) {
Get.updateLocale(Locale(val!));
Get.find<MusicServices>().hlCode = val;
Get.find<HomeScreenController>().loadContentFromNetwork(silent: true);
currentAppLanguageCode.value = val;
setBox.put('currentAppLanguageCode', val);
}
Expand Down

0 comments on commit eb6cbdb

Please sign in to comment.