Permalink
Browse files

Playr.Web coming together!

  • Loading branch information...
osbornm committed Aug 16, 2012
1 parent 3fb0635 commit 5837b06d84356dae93ee0ba19c30930f82e201a8
Showing with 293 additions and 352 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 Playr.Api/Controller/ControlController.cs
  3. +26 −12 Playr.Api/Controller/InfoController.cs
  4. +0 −19 Playr.Api/Controller/UsersController.cs
  5. +12 −2 Playr.Api/Helpers.cs
  6. +1 −0 Playr.Api/Models/Song.cs
  7. +0 −1 Playr.Api/Program.cs
  8. BIN Playr.Web/App_Data/PlayrWeb.sdf
  9. +5 −5 Playr.Web/App_Start/RouteConfig.cs
  10. +83 −44 Playr.Web/Content/Site.css
  11. +39 −16 Playr.Web/Controllers/HomeController.cs
  12. BIN Playr.Web/Images/emptyFavorite.png
  13. BIN Playr.Web/Images/fullFavorite.png
  14. +1 −0 Playr.Web/Models/Song.cs
  15. +2 −19 Playr.Web/Playr.Web.csproj
  16. +6 −4 Playr.Web/Scripts/_references.js
  17. +1 −0 Playr.Web/Scripts/jquery.balloon.min.js
  18. +40 −17 Playr.Web/Scripts/playr.js
  19. +4 −11 Playr.Web/Views/Account/Login.cshtml
  20. +2 −5 Playr.Web/Views/Account/Profile.cshtml
  21. +3 −6 Playr.Web/Views/Account/Register.cshtml
  22. +0 −34 Playr.Web/Views/Home/About.cshtml
  23. +0 −50 Playr.Web/Views/Home/Contact.cshtml
  24. +37 −78 Playr.Web/Views/Home/Index.cshtml
  25. +24 −0 Playr.Web/Views/Shared/_CommandBar.cshtml
  26. +4 −4 Playr.Web/Views/Shared/_Layout.cshtml
  27. +0 −12 Playr.Web/Views/Shared/_LoginPartial.cshtml
  28. +0 −6 Playr.Web/_bin_deployableAssemblies/amd64/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest
  29. BIN Playr.Web/_bin_deployableAssemblies/amd64/Microsoft.VC90.CRT/README_ENU.txt
  30. BIN Playr.Web/_bin_deployableAssemblies/amd64/Microsoft.VC90.CRT/msvcr90.dll
  31. BIN Playr.Web/_bin_deployableAssemblies/amd64/sqlceca40.dll
  32. BIN Playr.Web/_bin_deployableAssemblies/amd64/sqlcecompact40.dll
  33. BIN Playr.Web/_bin_deployableAssemblies/amd64/sqlceer40EN.dll
  34. BIN Playr.Web/_bin_deployableAssemblies/amd64/sqlceme40.dll
  35. BIN Playr.Web/_bin_deployableAssemblies/amd64/sqlceqp40.dll
  36. BIN Playr.Web/_bin_deployableAssemblies/amd64/sqlcese40.dll
  37. +0 −6 Playr.Web/_bin_deployableAssemblies/x86/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest
  38. BIN Playr.Web/_bin_deployableAssemblies/x86/Microsoft.VC90.CRT/README_ENU.txt
  39. BIN Playr.Web/_bin_deployableAssemblies/x86/Microsoft.VC90.CRT/msvcr90.dll
  40. BIN Playr.Web/_bin_deployableAssemblies/x86/sqlceca40.dll
  41. BIN Playr.Web/_bin_deployableAssemblies/x86/sqlcecompact40.dll
  42. BIN Playr.Web/_bin_deployableAssemblies/x86/sqlceer40EN.dll
  43. BIN Playr.Web/_bin_deployableAssemblies/x86/sqlceme40.dll
  44. BIN Playr.Web/_bin_deployableAssemblies/x86/sqlceqp40.dll
  45. BIN Playr.Web/_bin_deployableAssemblies/x86/sqlcese40.dll
  46. +1 −0 README.markdown
View
@@ -19,3 +19,4 @@ TestResults
DebugConstants.cs
*.log
packages/*
+Playr.Web/App_Data/*
@@ -59,7 +59,7 @@ public void Next()
[RequireToken, HttpPost]
public void Previous()
- {
+ {
itunes.PreviousTrack();
}
@@ -49,7 +49,7 @@ public DjInfo QueueSong(int id)
[HttpGet]
public HttpResponseMessage Artwork(int id)
{
- HttpResponseMessage response = new HttpResponseMessage();
+ HttpResponseMessage response = Request.CreateResponse();
var track = itunes.GetTrackById(id);
if (track == null)
@@ -86,7 +86,7 @@ public HttpResponseMessage Artwork(int id)
[HttpGet]
public HttpResponseMessage DownloadSong(int id)
{
- HttpResponseMessage response = new HttpResponseMessage();
+ HttpResponseMessage response = Request.CreateResponse();
var track = itunes.GetTrackById(id);
if (track == null)
@@ -107,7 +107,7 @@ public HttpResponseMessage DownloadSong(int id)
[HttpGet]
public HttpResponseMessage DownloadAlbum(string name)
{
- HttpResponseMessage response = new HttpResponseMessage();
+ HttpResponseMessage response = Request.CreateResponse();
var tracks = itunes.GetAlbumTracks(name);
if (!tracks.Any())
@@ -216,7 +216,7 @@ public void Upload()
mediaType.Equals("audio/mp3", StringComparison.InvariantCultureIgnoreCase) ||
mediaType.Equals("audio/wav", StringComparison.InvariantCultureIgnoreCase))
{
- // TOOO: itunes it stupid and requires and extension for the file to be picked up. For now assume MIME type is audio/{extension}
+ // TOOO: itunes is stupid and requires the extension for the file to be picked up. For now assume MIME type is audio/{extension}
var localFile = Path.Combine(ApplicationSettings.iTunesAddFolder, String.Format("{0}.{1}", Guid.NewGuid(), mediaType.Substring(6)));
using (var fileStream = File.Create(localFile))
{
@@ -236,20 +236,34 @@ public void Upload()
[NonAction]
public DjInfo GetQueue()
{
+ var token = Request.GetToken();
+ User user = null;
+ using (var session = Helpers.DocumentStore.OpenSession())
+ {
+ user = session.Query<User>().Where(u => u.Token == token).FirstOrDefault();
+ }
+
var tracks = itunes.CurrentPlaylist.Tracks;
var queue = new DjInfo();
- for (int i = 1; i < 6; i++)
- {
- queue.History.Add(tracks[i].toSong());
- }
-
- queue.CurrentTrack = tracks[6].toSong();
+ var currentTrackReached = false;
- for (int i = 7; i <= tracks.Count; i++)
+ foreach (IITTrack track in tracks)
{
- queue.Queue.Add(tracks[i].toSong());
+ if (!currentTrackReached && track.TrackDatabaseID == itunes.CurrentTrack.TrackDatabaseID)
+ {
+ currentTrackReached = true;
+ queue.CurrentTrack = track.toSong(user);
+ }
+ else if (currentTrackReached)
+ {
+ queue.Queue.Add(track.toSong(user));
+ }
+ else
+ {
+ queue.History.Add(track.toSong(user));
+ }
}
return queue;
}
@@ -36,25 +36,6 @@ public User Register(User u)
}
}
- [HttpGet]
- public User Debug(string email)
- {
- if (String.IsNullOrEmpty(email))
- {
- throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Must provide an email."));
- }
-
- using (var session = Helpers.DocumentStore.OpenSession())
- {
- var user = session.Load<User>("Users/" + email);
- if (user == null)
- {
- throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No such user"));
- }
- return user;
- }
- }
-
[HttpGet]
public User Find(string email)
{
View
@@ -19,9 +19,12 @@ public static class Helpers
public static string GetToken(this HttpRequestMessage request)
{
-
var header = request.Headers.SingleOrDefault(x => x.Key == "x-playr-token");
- return header.Value.First();
+ if (header.Value == null)
+ {
+ return String.Empty;
+ }
+ return header.Value.FirstOrDefault();
}
public static IITTrack GetTrackById(this iTunesAppClass itunes, int id)
@@ -54,6 +57,13 @@ public static Song toSong(this IITTrack t)
return new Song { Id = t.TrackDatabaseID, Album = t.Album, Artist = t.Artist, Rating = t.Rating, Title = t.Name, ArtworkUrl = String.Format(_artworkUrlFormatString, t.TrackDatabaseID) };
}
+ public static Song toSong(this IITTrack t, User u)
+ {
+ // TODO: Make this shit faster yo....
+ var isFavorite = u != null && u.Favorites.Where(s => s.Id == t.TrackDatabaseID).Any();
+ return new Song { Id = t.TrackDatabaseID, Album = t.Album, Artist = t.Artist, Rating = t.Rating, Title = t.Name, ArtworkUrl = String.Format(_artworkUrlFormatString, t.TrackDatabaseID), IsFavorite = isFavorite };
+ }
+
private static IDocumentStore docStore;
public static IDocumentStore DocumentStore
View
@@ -13,5 +13,6 @@ public class Song
public string Title { get; set; }
public int Rating { get; set; }
public string ArtworkUrl { get; set; }
+ public bool IsFavorite { get; set; }
}
}
View
@@ -90,7 +90,6 @@ public static void SetUp(iTunesAppClass itunes)
ApplicationSettings.TempPath = temp;
// Automatically Add to Itunes folder
- // TODO: Is this Okay to do? Do i want to assume this is set up? Add to readme?
ApplicationSettings.iTunesAddFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), "iTunes\\iTunes Media\\Automatically Add to iTunes");
// Set up track change
Binary file not shown.
@@ -14,14 +14,14 @@ public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
- routes.MapHttpRoute(
- name: "DefaultApi",
- routeTemplate: "api/{controller}/{id}",
- defaults: new { id = RouteParameter.Optional }
+ routes.MapRoute(
+ name: "Default",
+ url: "songs/{id}/favorite",
+ defaults: new { controller = "Home", action = "favorite" }
);
routes.MapRoute(
- name: "Default",
+ name: "foo",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Oops, something went wrong.

0 comments on commit 5837b06

Please sign in to comment.