├── .gitignore
├── Gemfile
├── lib
├── play
│ ├── templates
│ │ ├── search.mustache
│ │ ├── play_history.mustache
│ │ ├── album_songs.mustache
│ │ ├── artist_songs.mustache
│ │ ├── now_playing.mustache
│ │ ├── show_song.mustache
│ │ ├── layout.mustache
│ │ ├── index.mustache
│ │ ├── song.mustache
│ │ └── profile.mustache
│ ├── views
│ │ ├── layout.rb
│ │ ├── index.rb
│ │ ├── search.rb
│ │ ├── play_history.rb
│ │ ├── artist_songs.rb
│ │ ├── profile.rb
│ │ ├── album_songs.rb
│ │ ├── now_playing.rb
│ │ └── show_song.rb
│ ├── history.rb
│ ├── vote.rb
│ ├── core_ext
│ │ └── hash.rb
│ ├── album.rb
│ ├── artist.rb
│ ├── office.rb
│ ├── user.rb
│ ├── client.rb
│ ├── library.rb
│ ├── song.rb
│ ├── app
│ │ └── api.rb
│ └── app.rb
└── play.rb
├── test
├── test_client.rb
├── test_play.rb
├── test_artist.rb
├── test_library.rb
├── test_user.rb
├── test_album.rb
├── test_office.rb
├── helper.rb
├── spec
│ └── mini.rb
├── test_app.rb
├── test_song.rb
└── test_api.rb
├── config.ru
├── play.yml.example
├── bin
└── play
├── db
└── migrate
│ └── 01_create_schema.rb
├── Gemfile.lock
├── public
└── css
│ └── base.css
├── play.gemspec
├── Rakefile
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | db/*.sqlite3
2 | pkg/
3 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'http://rubygems.org'
2 | gemspec
3 |
--------------------------------------------------------------------------------
/lib/play/templates/search.mustache:
--------------------------------------------------------------------------------
1 | {{#songs}}
2 | {{>song}}
3 | {{/songs}}
4 |
--------------------------------------------------------------------------------
/lib/play/templates/play_history.mustache:
--------------------------------------------------------------------------------
1 | {{#songs}}
2 | {{>song}}
3 | {{/songs}}
4 |
--------------------------------------------------------------------------------
/lib/play/templates/album_songs.mustache:
--------------------------------------------------------------------------------
1 |
Yeah, this page should be fixed.
6 |
--------------------------------------------------------------------------------
/lib/play/views/play_history.rb:
--------------------------------------------------------------------------------
1 | module Play
2 | module Views
3 | class PlayHistory < Layout
4 | def title
5 | "History"
6 | end
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/lib/play/views/artist_songs.rb:
--------------------------------------------------------------------------------
1 | module Play
2 | module Views
3 | class ArtistSongs < Layout
4 | def title
5 | @artist.name
6 | end
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/lib/play/views/profile.rb:
--------------------------------------------------------------------------------
1 | module Play
2 | module Views
3 | class Profile < Layout
4 | def title
5 | @user ? @user.name : "Profile"
6 | end
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/lib/play/views/album_songs.rb:
--------------------------------------------------------------------------------
1 | module Play
2 | module Views
3 | class AlbumSongs < Layout
4 | def title
5 | "#{@artist.name}: #{@album.name}"
6 | end
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/test/test_client.rb:
--------------------------------------------------------------------------------
1 | require 'helper'
2 |
3 | context "Client" do
4 | setup do
5 | end
6 |
7 | test "volume" do
8 | Client.stubs(:system).returns(true)
9 | Client.volume(1)
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | require File.expand_path(File.dirname(__FILE__) + '/lib/play')
2 |
3 | require 'play'
4 | require 'omniauth/oauth'
5 | oauth = Play.config
6 |
7 | use Rack::Session::Cookie
8 | use OmniAuth::Strategies::GitHub, oauth['gh_key'], oauth['gh_secret']
9 |
10 | run Play::App
11 |
--------------------------------------------------------------------------------
/lib/play/templates/show_song.mustache:
--------------------------------------------------------------------------------
1 |
2 | {{#users}}
3 |
4 |
5 |
6 | {{/users}}
7 |
8 | Played {{plays}} times.
9 |
10 |
--------------------------------------------------------------------------------
/lib/play/views/now_playing.rb:
--------------------------------------------------------------------------------
1 | module Play
2 | module Views
3 | class NowPlaying < Layout
4 | def title
5 | "now playing"
6 | end
7 |
8 | def artist_name
9 | @song.artist_name
10 | end
11 |
12 | def song_title
13 | @song.title
14 | end
15 | end
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/test/test_play.rb:
--------------------------------------------------------------------------------
1 | require 'helper'
2 |
3 | context "Play" do
4 | setup do
5 | end
6 |
7 | test "path" do
8 | Play.expects(:config).returns({'path' => '/tmp/play'})
9 | assert_equal '/tmp/play', Play.path
10 | end
11 |
12 | test "now playing" do
13 | @song = Play::Song.create
14 | @song.play!
15 | assert @song, Play.now_playing
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/lib/play/album.rb:
--------------------------------------------------------------------------------
1 | module Play
2 | class Album < ActiveRecord::Base
3 | has_many :songs
4 | belongs_to :artist
5 |
6 | # Queue up an entire ALBUM!
7 | #
8 | # user - the User who is requesting the album to be queued
9 | #
10 | # Returns nothing.
11 | def enqueue!(user)
12 | songs.each{ |song| song.enqueue!(user) }
13 | end
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/lib/play/views/show_song.rb:
--------------------------------------------------------------------------------
1 | module Play
2 | module Views
3 | class ShowSong < Layout
4 | def title
5 | "#{@song.title} by #{@song.artist.name}"
6 | end
7 |
8 | def users
9 | @song.votes.group(:user_id).collect do |vote|
10 | vote.user
11 | end
12 | end
13 |
14 | def plays
15 | @song.votes.count
16 | end
17 | end
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/test/test_artist.rb:
--------------------------------------------------------------------------------
1 | require 'helper'
2 |
3 | context "Artist" do
4 | fixtures do
5 | @artist = Play::Artist.create(:name => "Justice")
6 | @song = Play::Song.create(:title => "Stress", :artist => @artist)
7 | @user = User.create
8 | end
9 |
10 | test "enqueueing ten songs" do
11 | Song.any_instance.expects(:enqueue!).with(@user).times(1)
12 | @artist.enqueue!(@user)
13 | end
14 |
15 | end
16 |
--------------------------------------------------------------------------------
/test/test_library.rb:
--------------------------------------------------------------------------------
1 | require 'helper'
2 |
3 | context "Library" do
4 | fixtures do
5 | end
6 |
7 | test "imports a song" do
8 | Library.import_song('/tmp/path')
9 | assert_equal 1, Play::Song.count
10 | end
11 |
12 | test "fs_songs" do
13 | FileUtils.mkdir_p '/tmp/play'
14 | FileUtils.touch '/tmp/play/song_1'
15 | FileUtils.touch '/tmp/play/song_2'
16 | Play.stubs(:path).returns('/tmp/play')
17 | assert_equal 2, Library.fs_songs.size
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/test/test_user.rb:
--------------------------------------------------------------------------------
1 | require 'helper'
2 |
3 | context "User" do
4 | fixtures do
5 | @user = Play::User.create(:email => "holman@example.com")
6 | end
7 |
8 | test "vote for" do
9 | @user.vote_for(Play::Song.create)
10 | assert_equal 1, @user.votes.count
11 | end
12 |
13 | test "gravatar_id" do
14 | assert_equal "54e4ab9ced3fd1f3f5b20ab2f8201b73", @user.gravatar_id
15 | end
16 |
17 | test "votes count" do
18 | @user.vote_for(Play::Song.create)
19 | assert_equal 1, @user.votes_count
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/lib/play/artist.rb:
--------------------------------------------------------------------------------
1 | module Play
2 | class Artist < ActiveRecord::Base
3 | has_many :songs
4 | has_many :albums
5 | has_many :votes
6 |
7 | # Queue up an artist. This will grab ten random tracks for this artist and
8 | # queue 'em up.
9 | #
10 | # user - the User who is requesting the artist be queued
11 | #
12 | # Returns nothing.
13 | def enqueue!(user)
14 | songs.shuffle[0..9].collect do |song|
15 | song.enqueue!(user)
16 | song
17 | end
18 | end
19 |
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/lib/play/templates/layout.mustache:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 | The queue is empty. Quick, play some
Ace of Base; no one's looking.
17 |
18 | {{/songs}}
19 |
--------------------------------------------------------------------------------
/lib/play/templates/song.mustache:
--------------------------------------------------------------------------------
1 |
2 | {{#user}}
3 |
4 |

5 |
6 |
7 |
8 | @{{login}}
9 | Queued up {{votes_count}} songs.
10 |
11 |
12 | {{/user}}
13 |
14 |
15 |