Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soundcloud #50

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ GEM
temple (~> 0.4.1)
tilt (~> 1.3.3)
slop (2.4.4)
springboard (0.18.7.1)
springboard (0.19.9)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of the changes in this file: git checkout master Gemfile.lock

sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
web: bundle exec rails server Puma
worker: bundle exec sidekiq -q push,5 -q indexing,2 -q archiving,1 -c 10
push: bundle exec thin start -R push/faye.ru -p 9292 -e production
search: bundle exec springboard -c config/elasticsearch -f
search: bundle exec springboard -c config/elasticsearch -f
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of the changes in this file: git checkout master Procfile

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ $ echo 'FACEBOOK_APP_ID=111111111111111' >> .env
$ echo 'FACEBOOK_APP_SECRET=abcdefabcdefabcdefabcdefabcdefab' >> .env
```

Add your SoundCloud Client ID. Note that Warble currently exposes this
to end users. Get a new ID from http://soundcloud.com/you/apps/new

```sh
$ echo 'SOUNDCLOUD_CLIENT_ID=soundcloud_client_id' >> .env
```

Add credentials for a Pandora partner. Pick one from
<http://pan-do-ra-api.wikia.com/wiki/Json/5/partners>:

Expand Down
Binary file added app/assets/images/soundcloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 14 additions & 10 deletions app/assets/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#= require faye-browser
#= require jquery.mapkey
#= require tooltip

#= require_self

#= require_tree ./components
Expand All @@ -30,6 +29,7 @@ jQuery(document).ready ($) ->
'hype/popular/3days/:page' : 'hypePopular3Days'
'hype/popular/week/:page' : 'hypePopularWeek'
'hype/:user/:page' : 'hypeUser'
'soundcloud' : 'soundcloud'
'*unmatched' : 'home'

initialize: ->
Expand All @@ -41,15 +41,16 @@ jQuery(document).ready ($) ->
@hypeSongs = new Warble.HypeSongList

# initialize views
@headerView = new Warble.HeaderView model: @jukebox
@currentPlayView = new Warble.CurrentPlayView model: @jukebox
@playlistView = new Warble.PlaylistView collection: @playlist
@serviceChooserView = new Warble.ServiceChooserView
@pandoraAuthView = new Warble.PandoraCredentialsView
@pandoraStationsView = new Warble.PandoraStationsView collection: @stationList
@youtubeSearchView = new Warble.YoutubeSearchView
@hypeChooserView = new Warble.HypeFeedsView
@hypeSongsView = new Warble.HypeSongsView collection: @hypeSongs
@headerView = new Warble.HeaderView model: @jukebox
@currentPlayView = new Warble.CurrentPlayView model: @jukebox
@playlistView = new Warble.PlaylistView collection: @playlist
@serviceChooserView = new Warble.ServiceChooserView
@pandoraAuthView = new Warble.PandoraCredentialsView
@pandoraStationsView = new Warble.PandoraStationsView collection: @stationList
@youtubeSearchView = new Warble.YoutubeSearchView
@hypeChooserView = new Warble.HypeFeedsView
@hypeSongsView = new Warble.HypeSongsView collection: @hypeSongs
@soundcloudSearchView = new Warble.SoundcloudSearchView

# load data
@jukebox.fetch()
Expand Down Expand Up @@ -146,6 +147,9 @@ jQuery(document).ready ($) ->
@hypeSongs.url = "/hype?username=#{encodeURIComponent(user)}&page=#{encodeURIComponent(page)}"
@hypeSongs.fetch()

soundcloud: ->
#SC.initialize client_id: "dae39b5eb16934e43c93209cb65051ee"
@switchPane @soundcloudSearchView

window.workspace = workspace = new Warble.WorkspaceRouter
Backbone.history.start pushState: true
Expand Down
12 changes: 12 additions & 0 deletions app/assets/javascripts/templates/soundcloud.jst.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="breadcrumbs">
<a href="/" data-relative="true">Sources</a>
&raquo;
<span class="current">SoundCloud</span>
</div>

<h2>SoundCloud</h2>

<input type="text" id="soundcloud_query"/>
<a href="#" class="button" id="soundcloud_search">Search</a>

<div id="soundcloud_search_results"></div>
2 changes: 2 additions & 0 deletions app/assets/javascripts/templates/soundcloud_preview.jst.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<audio class="scpreview-player" controls="controls" src="{{url}}" type="audio/mp3" autoplay />

26 changes: 26 additions & 0 deletions app/assets/javascripts/templates/soundcloud_results.jst.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<ul>
{{#results}}
<li>
<a href="#" class="entry" data-id="{{index}}">
<img src="{{thumbnail}}" class="thumbnail" />
<div class="title">{{title}}</div>
<div class="author">{{author}}</div>
</a>
<div class="scpreview" data-soundcloud="{{url}}"><a href='#'>preview</a></div>
</li>
{{/results}}
</ul>

{{#if hasPrev}}
<a href="#" class="paging button" id="previous_results">
<span class="pictos">[</span>
Previous
</a>
{{/if}}

{{#if hasNext}}
<a href="#" class="paging button" id="next_results">
Next
<span class="pictos">]</span>
</a>
{{/if}}
6 changes: 6 additions & 0 deletions app/assets/javascripts/templates/sources.jst.hbs.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
YouTube
</a>
</li>
<li>
<a href="/soundcloud" data-relative="true">
<%= image_tag 'soundcloud.png' %>
SoundCloud
</a>
</li>
<li>
<a href="/hype" data-relative="true">
The Hype Machine
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#= require ui/application/panes/pane
#= require templates/soundcloud
#= require templates/soundcloud_results
#= require templates/soundcloud_preview

# TODO: proper controller routes for pages and queries
class Warble.SoundcloudSearchView extends Warble.PaneView
SOUNDCLOUD_CLIENT_ID = "<%= ENV['SOUNDCLOUD_CLIENT_ID'] %>"
SOUNDCLOUD_SEARCH_URL = "https://api.soundcloud.com/tracks"

template: window.JST['templates/soundcloud']
searchResultsTemplate: window.JST['templates/soundcloud_results']

events:
'click #soundlcoud_search' : 'search'
'keypress input' : 'handleEnter'
'click a.entry' : 'queueSong'
'click .scpreview a' : 'previewAudio'
'click a#previous_results' : 'previousPage'
'click a#next_results' : 'nextPage'

initialize: ->
@searchData = null
@query = ''
@pageSize = 10
@startIndex = 0

activate: ->
@$('#soundcloud_query').focus()

handleEnter: (event) ->
if event.which == 13
this.search event

previewAudio: (event) ->
preview_el = @$(event.currentTarget)
preview_el.parent('div').parent('li').addClass('show-preview')
preview_el.parent('div').html window.JST['templates/soundcloud_preview']
url: preview_el.parent('div').data('soundcloud')
this

previousPage: (event) ->
@startIndex -= @pageSize + 1
this.search event

nextPage: (event) ->
@startIndex += @pageSize + 1
this.search event

search: (event) ->
window.workspace.showSpinner()
q = @$('#soundcloud_query').val()

#reset the search start-index if it's a new search
if @query != q
@startIndex = 1
@query = q

search_params =
q: @query
'limit': @pageSize
'offset': @startIndex if @startIndex >= @pageSize
'client_id': SOUNDCLOUD_CLIENT_ID

$.getJSON SOUNDCLOUD_SEARCH_URL, search_params, (data) =>
# extract results into a saner object array
@data = _.map data, (entry, index) ->
index: index
soundcloud_id: entry.id
title: entry.title
thumbnail: entry.artwork_url
author: entry.user.username
url: entry.stream_url + "?client_id=" + SOUNDCLOUD_CLIENT_ID

$('#soundcloud_search_results').html @searchResultsTemplate
results: @data
hasPrev: @startIndex > 1
hasNext: true #Fix this. Need total number of results from soundcloud.

@$el.scrollTop 0
window.workspace.hideSpinner()
event.preventDefault()

queueSong: (event) ->
console.log @data[$(event.currentTarget).attr('data-id')]
window.workspace.showSpinner()

$.ajax '/jukebox/playlist',
type: 'POST'
data:
soundcloud: @data[$(event.currentTarget).attr('data-id')]
success: =>
window.workspace.hideSpinner()
error: ->
window.workspace.navigate '/', true
window.workspace.hideSpinner()

event.preventDefault()
8 changes: 5 additions & 3 deletions app/assets/stylesheets/application.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -468,19 +468,22 @@ header
+box-shadow(rgba(0, 0, 0, 0.6) 1px 1px 4px)


#youtube_query, #search_query // TODO: combine
#youtube_query, #soundcloud_query, #search_query // TODO: combine
width: 220px

#youtube_search, #library_search, #username_search // TODO: combine
margin-left: 15px

#youtube_search_results
#youtube_search_results, #soundcloud_search_results
li // TODO: combine with pandora_songs list
height: 48px
padding: 10px 0

&.preview
padding-bottom: 220px

&.show-preview
padding-bottom: 35px

img // TODO: compied from pandora_songs list, consolidate them
float: left
Expand All @@ -493,7 +496,6 @@ header
.title
margin-top: 10px


a.button
font-size: 13px
background: $secondary_a_dark
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/pandora/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Pandora::BaseController < ApplicationController
before_filter :check_pandora_credentials!


private
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of the changes in this file: git checkout master app/controllers/pandora/base_controller.rb


def check_pandora_credentials!
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/plays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ def create
Jukebox.enqueue(Song.find(song_id), current_user)
end
head :created


elsif params[:soundcloud]
song = Song.find_or_create_from_soundcloud_params(params[:soundcloud], current_user)
Jukebox.enqueue(song, current_user)
head :created

elsif params[:youtube]
song = Song.find_or_create_from_youtube_params(params[:youtube], current_user)
Jukebox.enqueue(song, current_user)
Expand Down
21 changes: 20 additions & 1 deletion app/models/song.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ def self.find_or_create_from_pandora_song(pandora_song, submitter)
song
end
end

def self.find_or_create_from_soundcloud_params(params, submitter)
if song = where(source: 'soundcloud').where(external_id: params[:soundcloud_id]).first
song.fsck! params[:url]
song
else # first time seeing the song, so create it
song = Song.create({
source: 'soundcloud',
title: params[:title],
artist: params[:author],
cover_url: params[:artwork_url],
url: params[:url],
external_id: params[:soundcloud_id],
user: submitter
}, without_protection: true)
ArchiveSongWorker.perform_async song.id # Queue for archiving
song
end
end

def self.find_or_create_from_youtube_params(params, submitter)
if song = where(source: 'youtube').where(external_id: params[:youtube_id]).first
Expand Down Expand Up @@ -106,7 +125,7 @@ def self.random

# Is this song archivable to disk?
def archivable?
%w[pandora hypem].include?(source)
%w[pandora hypem soundcloud].include?(source)
end

# Ensure a song has been archived.
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

match 'hype' => 'hype#index'


### ------------------------ ADMINISTRATIVE ROUTES ---------------------------
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of the changes in this file: git checkout master config/routes.rb


mount Sidekiq::Web => '/sidekiq'
Expand Down
20 changes: 20 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
0 info it worked if it ends with ok
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of this file: git rm npm-debug.log

1 verbose cli [ 'node', '/usr/local/bin/npm', 'run-script', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose node symlink /usr/local/bin/node
5 verbose read json /Users/tsucho/rails/warble/package.json
6 error Error: ENOENT, open '/Users/tsucho/rails/warble/package.json'
7 error If you need help, you may report this log at:
7 error <http://github.com/isaacs/npm/issues>
7 error or email it to:
7 error <[email protected]>
8 error System Darwin 12.2.0
9 error command "node" "/usr/local/bin/npm" "run-script" "start"
10 error cwd /Users/tsucho/rails/warble
11 error node -v v0.8.10
12 error npm -v 1.1.62
13 error path /Users/tsucho/rails/warble/package.json
14 error code ENOENT
15 error errno 34
16 verbose exit [ 34, true ]