Skip to content

Commit

Permalink
Song preview.(Not playable)
Browse files Browse the repository at this point in the history
Added feedback when creating playlist
Som GUI elements to support SoundClou(Disabled)
  • Loading branch information
vicsufer committed May 30, 2017
1 parent 55c75ff commit 237ad39
Show file tree
Hide file tree
Showing 11 changed files with 463 additions and 37 deletions.
10 changes: 8 additions & 2 deletions Logic/BeatmapLittle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ public class BeatmapLittle
{

public string title, artist;
public string songTags;
public int beatmapId, beatmapSetID;
public BeatmapLittle(BeatmapEntry bm)
{
title = bm.Title;
artist = bm.Artist;
songTags = bm.SongTags;
beatmapId = bm.BeatmapId;
beatmapSetID = bm.BeatmapSetId;
}
public BeatmapLittle(String str)
{
Expand All @@ -28,11 +33,12 @@ public override string ToString()
}
public string searchString()
{
return artist + " " + title;
return artist +"+"+ title;
}

public string ToListBoxString()
{
return title + " - " + artist;
return beatmapSetID + ": " + title + " - " + artist;
}

}
Expand Down
1 change: 1 addition & 0 deletions Logic/Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="BeatmapLittle.cs" />
<Compile Include="MainFrame.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SoundCloud.cs" />
<Compile Include="Spotify.cs" />
<Compile Include="SpotifyException.cs" />
</ItemGroup>
Expand Down
30 changes: 27 additions & 3 deletions Logic/MainFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Logic
public class MainFrame
{
Spotify sp;
SoundCloud sc;

public CollectionDb collections_db;
public OsuDb osu_db;
Expand All @@ -26,22 +27,45 @@ public MainFrame(string path = "")
osu_db = OsuDb.Read(Osu_path + "osu!.db");
}

public async Task CreatePlaylistAsync(string clientID, string playlistName, IEnumerable<string> collection = null, bool mode = true)
public async Task<int> CreateSpotifyPlaylistAsync(string clientID, string playlistName, IEnumerable<string> collection = null, bool mode = true)
{
sp = new Spotify(clientID);
sp.CreatePlaylistByCollection(playlistName, GetBeatmapsByNamesList(collection) ,true);
int numberOfSongs;
sp.CreatePlaylistByCollection(playlistName, GetBeatmapsByNamesList(collection) ,out numberOfSongs, true);
return numberOfSongs;
}


public IEnumerable<BeatmapLittle> GetBeatmapsByNamesList(IEnumerable<string> names)
{
List<BeatmapLittle> beatmaps = new List<BeatmapLittle>();
Parallel.ForEach(names, name =>
{
var beatmap = osu_db.Beatmaps.Find( x => x.Title.Equals(name));
var beatmap = osu_db.Beatmaps.Find(x => x.Title.ToLower().Equals(name.ToLower()));
lock (beatmaps) { beatmaps.Add(new BeatmapLittle(name)); }
});
return beatmaps;
}


public IEnumerable<BeatmapLittle> GetBeatmapsBySetIDList(IEnumerable<int> list)
{
List<BeatmapLittle> beatmaps = new List<BeatmapLittle>();
Parallel.ForEach(list, id =>
{
var beatmap = GetBeatmapBySetID(id);
lock (beatmaps) { beatmaps.Add(new BeatmapLittle(beatmap)); }
});
return beatmaps;
}

public BeatmapEntry GetBeatmapBySetID(int set_id)
{

return osu_db.Beatmaps.Find( x => x.BeatmapSetId == set_id);
}


public IEnumerable<BeatmapLittle> GetCollectionBeatmaps(string collectionName)
{
if (collectionName.ToLower().Equals("all"))
Expand Down
12 changes: 12 additions & 0 deletions Logic/SoundCloud.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Logic
{
class SoundCloud
{
}
}
12 changes: 6 additions & 6 deletions Logic/Spotify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Logic
public class Spotify
{
private readonly SpotifyWebAPI _spotify;
int apiSleepTime = 200;
int apiSleepTime = 250;
public Spotify(string clientID)
{
_spotify = new SpotifyWebAPI();
Expand Down Expand Up @@ -62,7 +62,7 @@ public FullPlaylist CreatePlaylist(string name, bool mode)
{
Thread.Sleep(apiSleepTime);
Console.WriteLine("Error Status: " + playlist.Error.Status);
Console.WriteLine("Error Msg: " + playlist.Error.Message);
Console.WriteLine("Error Msg: CreatePlayList" + playlist.Error.Message);
}
return playlist;
}
Expand All @@ -75,7 +75,7 @@ public FullTrack FindTrackByBeatmap(BeatmapLittle beatmap)
while (item.HasError())
{
Console.WriteLine("Error Status: " + item.Error.Status);
Console.WriteLine("Error Msg: " + item.Error.Message);
Console.WriteLine("Error Msg: FindTrackByBeatmap " + item.Error.Message);

Thread.Sleep(apiSleepTime);

Expand All @@ -101,20 +101,20 @@ public List<FullTrack> FindTracksByCollection(IEnumerable<BeatmapLittle> collect
return aux;
}

public void CreatePlaylistByCollection(string name, IEnumerable<BeatmapLittle> collection, bool mode = true)
public void CreatePlaylistByCollection(string name, IEnumerable<BeatmapLittle> collection, out int numberOfSongs, bool mode = true)
{
var tracks = FindTracksByCollection(collection).Select( x => x.Uri).ToList();
var playlist = CreatePlaylist(name, mode);
var user = _spotify.GetPrivateProfile();
while (user.HasError())
{
Console.WriteLine("Error Status: " + user.Error.Status);
Console.WriteLine("Error Msg: " + user.Error.Message);
Console.WriteLine("Error Msg: CreatePlayListByCollection" + user.Error.Message);
Thread.Sleep(20);
user = _spotify.GetPrivateProfile();
}
_spotify.AddPlaylistTracks(user.Id, playlist.Id, tracks );

numberOfSongs = tracks.Count();
}
}
}
80 changes: 71 additions & 9 deletions SpotOsu/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 237ad39

Please sign in to comment.