Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
Added auto better source getting
Browse files Browse the repository at this point in the history
  • Loading branch information
vhaudiquet committed May 11, 2018
1 parent 009ae09 commit b0d19ec
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
Binary file added app/blade-0.3.apk
Binary file not shown.
Binary file removed app/blade-indev.apk
Binary file not shown.
46 changes: 45 additions & 1 deletion app/src/main/java/v/blade/library/UserLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public void run()
System.out.println("[BLADE-DEBUG] Spotify songs registered.");

sortLibrary();

registerSongBetterSources();
}
};
webLoaderThread.setName("webLoaderThread");
Expand Down Expand Up @@ -552,7 +554,49 @@ public static void registerDeezerSongs()
*/
public static void registerSongBetterSources()
{
//TODO
if(!REGISTER_SONGS_BETTER_SOURCES) return;

SongSources.Source bestSource = SongSources.SOURCE_DEEZER.getPriority() > SongSources.SOURCE_SPOTIFY.getPriority() ? SongSources.SOURCE_DEEZER : SongSources.SOURCE_SPOTIFY;

if(bestSource == SongSources.SOURCE_SPOTIFY)
{
//search all deezer songs on spotify
synchronized (songs)
{
for(Song s : songs)
{
if(s.getSources().getSourceByPriority(0).getSource() == SongSources.SOURCE_DEEZER)
{
//query spotify for this song
HashMap<String, Object> args = new HashMap<>();
args.put("limit", 1);
List<Track> t = spotifyApi.getService().searchTracks(s.getTitle() + " album:" + s.getAlbum().getName() + " artist:" + s.getArtist().getName()).tracks.items;
if(t != null && t.size() > 0 && t.get(0) != null) s.getSources().addSource(new SongSources.SongSource(t.get(0).id, SongSources.SOURCE_SPOTIFY));
}
}
}
}
else if(bestSource == SongSources.SOURCE_DEEZER)
{
//search all spotify songs on deezer
synchronized (songs)
{
for(Song s : songs)
{
if(s.getSources().getSourceByPriority(0).getSource() == SongSources.SOURCE_SPOTIFY)
{
//query deezer for this song
DeezerRequest search = DeezerRequestFactory.requestSearchTracks("track:\"" + s.getTitle() + "\" album:\"" + s.getAlbum().getName() + "\" artist:\"" + s.getArtist().getName() + "\"");
try
{
com.deezer.sdk.model.Track t = ((List<com.deezer.sdk.model.Track>) JsonUtils.deserializeJson(deezerApi.requestSync(search))).get(0);
if(t != null) s.getSources().addSource(new SongSources.SongSource(t.getId(), SongSources.SOURCE_DEEZER));
}
catch(Exception e) {} //ignored
}
}
}
}
}

public static void sortLibrary()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:defaultValue="false"
android:singleLineTitle="false"/>
<CheckBoxPreference android:title="Chercher une meilleure source"
android:summary="Blade tentera pour tous vos sons provenant de service web de les trouver sur le meilleur service web en fonction de sa priorité"
android:summary="Blade tentera pour tous vos sons provenant de services web de les trouver sur le meilleur service web en fonction de sa priorité"
android:key="register_better_sources"
android:defaultValue="true"
android:singleLineTitle="false"/>
Expand Down

0 comments on commit b0d19ec

Please sign in to comment.