0.5.10 - Download fixes, translations, search history fix, bigger buffer

This commit is contained in:
exttex 2020-10-17 21:20:26 +02:00
parent 5adc854e46
commit bcf709e56d
9 changed files with 60 additions and 21 deletions

View file

@ -166,6 +166,9 @@ public class Deezer {
URL url = new URL(getTrackUrl(trackId, md5origin, mediaVersion, originalQuality));
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("HEAD");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36");
connection.setRequestProperty("Accept-Language", "*");
connection.setRequestProperty("Accept", "*/*");
int rc = connection.getResponseCode();
//Track not available
if (rc > 400) {
@ -293,7 +296,6 @@ public class Deezer {
isFlac = false;
}
Tag tag = f.getTag();
tag.setEncoding("utf-8");
tag.setField(FieldKey.TITLE, publicTrack.getString("title"));
tag.setField(FieldKey.ALBUM, publicTrack.getJSONObject("album").getString("title"));

View file

@ -313,13 +313,41 @@ public class DownloadService extends Service {
return;
}
//Quality fallback
int newQuality;
try {
newQuality = deezer.qualityFallback(download.trackId, download.md5origin, download.mediaVersion, download.quality);
} catch (Exception e) {
logger.error("Quality fallback failed: " + e.toString(), download);
download.state = Download.DownloadState.ERROR;
exit();
return;
}
//TrackID Fallback
try {
if (newQuality == -1 && !download.isUserUploaded() && privateJson.has("FALLBACK")) {
logger.warn("TrackID Fallback!", download);
String fallbackId = privateJson.getJSONObject("FALLBACK").getString("SNG_ID");
JSONObject newPrivate = deezer.callGWAPI("song.getListData", "{\"sng_ids\": [" + fallbackId + "]}");
JSONObject trackData = newPrivate.getJSONObject("results").getJSONArray("data").getJSONObject(0);
download.trackId = trackData.getString("SNG_ID");
download.md5origin = trackData.getString("MD5_ORIGIN");
download.mediaVersion = trackData.getString("MEDIA_VERSION");
run();
return;
}
} catch (Exception e) {
logger.error("ID fallback failed: " + e.toString(), download);
}
//ISRC Fallback
try {
if (!download.isUserUploaded() && trackJson.has("available_countries") && trackJson.getJSONArray("available_countries").length() == 0) {
if (newQuality == -1 && !download.isUserUploaded()) {
logger.warn("ISRC Fallback!", download);
JSONObject newTrackJson = Deezer.callPublicAPI("track", "isrc:" + trackJson.getString("isrc"));
//Same track check
if (newTrackJson.getJSONArray("available_countries").length() == 0 || newTrackJson.getInt("id") == trackJson.getInt("id")) throw new Exception("No more to fallback!");
if (newTrackJson.getInt("id") == trackJson.getInt("id")) throw new Exception("No more to fallback!");
//Get private data
JSONObject privateJson = deezer.callGWAPI("song.getListData", "{\"sng_ids\": [" + newTrackJson.getInt("id") + "]}");
JSONObject trackData = privateJson.getJSONObject("results").getJSONArray("data").getJSONObject(0);
@ -336,17 +364,6 @@ public class DownloadService extends Service {
return;
}
//Quality fallback
int newQuality;
try {
newQuality = deezer.qualityFallback(download.trackId, download.md5origin, download.mediaVersion, download.quality);
} catch (Exception e) {
logger.error("Quality fallback failed: " + e.toString(), download);
download.state = Download.DownloadState.ERROR;
exit();
return;
}
//No quality available
if (newQuality == -1) {
logger.error("No available quality!", download);

@ -1 +1 @@
Subproject commit ae319b96899fe42a69c57c2f4a17691d90596f98
Subproject commit 0ef1be20848b9553bc1191f5d119f768d6ce5ea5

View file

@ -49,7 +49,7 @@ class Cache {
@JsonKey(ignore: true)
StreamSubscription sleepTimer;
@JsonKey(defaultValue: const [])
@JsonKey(defaultValue: [])
List<String> searchHistory;
//If download threads warning was shown

File diff suppressed because one or more lines are too long

View file

@ -21,6 +21,7 @@ const supportedLocales = [
const Locale('id', 'ID'),
const Locale('fa', 'IR'),
const Locale('pl', 'PL'),
const Locale('uk', 'UA'),
const Locale('fil', 'PH')
];

View file

@ -771,6 +771,21 @@ class QueueScreen extends StatefulWidget {
class _QueueScreenState extends State<QueueScreen> {
StreamSubscription _queueSub;
@override
void initState() {
_queueSub = AudioService.queueStream.listen((event) {setState((){});});
super.initState();
}
@override
void dispose() {
if (_queueSub != null)
_queueSub.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(

View file

@ -66,7 +66,10 @@ class _SearchScreenState extends State<SearchScreen> {
//Add to search history
try {cache.searchHistory.remove(_query);} catch (_) {}
cache.searchHistory.add(_query);
if (cache.searchHistory == null)
cache.searchHistory = [];
cache.searchHistory.insert(0, _query);
cache.save();
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => SearchResultsScreen(_query, offline: _offline,))
@ -75,6 +78,7 @@ class _SearchScreenState extends State<SearchScreen> {
@override
void initState() {
print(cache.searchHistory);
//Check for connectivity and enable offline mode
Connectivity().checkConnectivity().then((res) {
if (res == ConnectivityResult.none) setState(() {
@ -165,9 +169,9 @@ class _SearchScreenState extends State<SearchScreen> {
Divider(),
//History
if (cache.searchHistory.length > 0 && (_query??'').length == 0)
if (cache.searchHistory != null && cache.searchHistory.length > 0 && (_query??'').length == 0)
...List.generate(cache.searchHistory.length > 10 ? 10 : cache.searchHistory.length, (int i) => ListTile(
title: Text(cache.searchHistory[i]),
title: Text(cache.searchHistory[i]??''),
leading: Icon(Icons.history),
onTap: () {
setState(() => _query = cache.searchHistory[i]);

View file

@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.5.9+1
version: 0.5.10+1
environment:
sdk: ">=2.8.0 <3.0.0"