-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow multiple playlist directories. Always add the BeatDrop playlist folder. Playlist show in order defined in the playlist file. Handle bad or unknown base64 data for now.
- Loading branch information
Showing
16 changed files
with
773 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SongBrowserPlugin.DataAccess | ||
{ | ||
public class Playlist | ||
{ | ||
public String playlistTitle { get; set; } | ||
public String playlistAuthor { get; set; } | ||
public string image { get; set; } | ||
public List<PlaylistSong> songs { get; set; } | ||
|
||
public String playlistPath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using SimpleJSON; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SongBrowserPlugin.DataAccess | ||
{ | ||
public class PlaylistsReader | ||
{ | ||
private static Logger _log = new Logger("PlaylistReader"); | ||
|
||
private List<String> _PlaylistsDirectories = new List<string>(); | ||
|
||
private List<Playlist> _CachedPlaylists; | ||
|
||
public List<Playlist> Playlists | ||
{ | ||
get | ||
{ | ||
return _CachedPlaylists; | ||
} | ||
} | ||
|
||
public PlaylistsReader(String playlistsDirectory) | ||
{ | ||
_PlaylistsDirectories.Add(playlistsDirectory); | ||
|
||
// Hack, add beatdrop location | ||
String localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | ||
String beatDropPlaylistPath = Path.Combine(localAppDataPath, "Programs", "BeatDrop", "playlists"); | ||
|
||
_PlaylistsDirectories.Add(beatDropPlaylistPath); | ||
} | ||
|
||
public void UpdatePlaylists() | ||
{ | ||
_CachedPlaylists = new List<Playlist>(); | ||
|
||
foreach (String path in _PlaylistsDirectories) | ||
{ | ||
_log.Debug("Reading playlists located at: {0}", path); | ||
if (!Directory.Exists(path)) | ||
{ | ||
_log.Info("Playlist path does not exist: {0}", path); | ||
continue; | ||
} | ||
|
||
string[] files = Directory.GetFiles(path); | ||
foreach (string file in files) | ||
{ | ||
_log.Debug("Checking file {0}", file); | ||
if (Path.GetExtension(file) == ".json") | ||
{ | ||
Playlist p = ParsePlaylist(file); | ||
_CachedPlaylists.Add(p); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static Playlist ParsePlaylist(String path) | ||
{ | ||
try | ||
{ | ||
if (!File.Exists(path)) | ||
{ | ||
_log.Debug("Playlist file no longer exists: {0}", path); | ||
return null; | ||
} | ||
|
||
_log.Debug("Parsing playlist at {0}", path); | ||
String json = File.ReadAllText(path); | ||
Playlist playlist = new Playlist(); | ||
|
||
JSONNode playlistNode = JSON.Parse(json); | ||
|
||
playlist.image = playlistNode["image"]; | ||
playlist.playlistTitle = playlistNode["playlistTitle"]; | ||
playlist.playlistAuthor = playlistNode["playlistAuthor"]; | ||
playlist.songs = new List<PlaylistSong>(); | ||
|
||
foreach (JSONNode node in playlistNode["songs"].AsArray) | ||
{ | ||
PlaylistSong song = new PlaylistSong(); | ||
song.key = node["key"]; | ||
song.songName = node["songName"]; | ||
|
||
playlist.songs.Add(song); | ||
} | ||
|
||
playlist.playlistPath = path; | ||
return playlist; | ||
} | ||
catch (Exception e) | ||
{ | ||
_log.Exception("Exception parsing playlist: ", e); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SongBrowserPlugin.DataAccess | ||
{ | ||
public class PlaylistSong | ||
{ | ||
public int key { get; set; } | ||
public String songName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.