Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Search and play now uses the new Official.fm api.

Part of #190
  • Loading branch information...
commit c46955751c5f73231af0c5930b79732bef2982b7 1 parent 5042f0f
@kallux kallux authored
View
28 scripts/InfoFetcher.js
@@ -45,7 +45,7 @@ var InfoFetcher = {
},
loadOfficialFmTrackInfo: function(video) {
- var url = "http://api.official.fm/track/" + video.videoId;
+ var url = "http://api.official.fm/tracks/" + video.videoId + '?api_version=2&fields=cover';
var params = {
format: 'json',
key: OFFICIALFM_API_KEY
@@ -54,17 +54,23 @@ var InfoFetcher = {
video: video
};
$.getJSON(url, params, function(data) {
- data = data[0];
- info.video.title = data.title;
- info.video.duration = data.length * 1000;
- info.url = 'http://official.fm/tracks/' + data.id;
- info.title = data.title;
- info.description = data.description;
- info.thumbnail = data.picture_absolute_url;
+ data = data.track;
+ var title = data.title.indexOf(data.artist) > -1 ?
+ data.title :
+ data.artist + ' - ' + data.title,
+ id = data.page.split('/');
+ id = id[id.length-1];
+
+ info.video.title = title;
+ info.video.duration = data.duration * 1000;
+ info.url = 'http://official.fm/tracks/' + id;
+ info.title = title;
+ info.description = "";
+ info.thumbnail = data.cover.urls.large;
info.author = {
- name: data.artist_string,
- url: data.web_url || data.buy_url,
- user_id: data.user_id
+ name: data.artist,
+ url: data.project.url.replace(/api\./, "").split('?')[0] || data.buy_url,
+ user_id: data.project.url.split('/')[data.project.url.split('/').length -1].split('?')[0]
};
info.buyLinks = video.buyLinks || data.buy_url ? [data.buy_url] : null;
EventSystem.callEventListeners('video_info_fetched', info);
View
5 scripts/OfficialfmPlayer.js
@@ -6,7 +6,6 @@ function OfficialfmPlayer() {
self.video = null;
self.view = null;
self.volume = 100;
- self.mp3_url = 'http://cdn.official.fm/';
self.playedSuccessfully = false;
self.defaultWidth = $('#left .players').width();
self.defaultHeight = $('#left .players').height();
@@ -54,8 +53,8 @@ function OfficialfmPlayer() {
soundManager.stopAll();
self.playedSuccessfully = false;
soundManager.createSound({
- id: video.videoId,
- url: 'http://cdn.official.fm/mp3s/' + Math.floor(video.videoId / 1000) + '/' + video.videoId + '.mp3',
+ id: video.videoId,
+ url: 'http://api.official.fm/tracks/' + video.videoId + '/stream?api_version=2',
volume: self.volume,
onplay: function() {
if (!self.playedSuccessfully) {
View
19 scripts/Search.js
@@ -182,7 +182,7 @@ var Search = {
});
break;
case 'officialfm-tracks':
- url = 'http://api.official.fm/search/tracks/' + escape(q) + '/paginate';
+ url = 'http://api.official.fm/tracks/search?q=' + escape(q) + '&api_version=2&fields=cover';
params = {
'format': 'json',
'per_page': 30,
@@ -279,15 +279,22 @@ var Search = {
getVideosFromOfficialfmSearchData: function(data) {
ret = [];
$.each(data, function(i, track) {
- var buyLinks = track.purchase_url ? [track.buy_url] : null;
+ track = track.track;
+ var title = track.title.indexOf(track.artist) > -1 ?
+ track.title :
+ track.artist + ' - ' + track.title,
+ buyLinks = track.purchase_url ? [track.buy_url] : null,
+ id = track.page.split('/');
+ id = id[id.length-1];
ret.push(new Video({
parent: 'search',
onPlayCallback: Search.onPlayCallback,
- videoId: track.id,
- title: track.title,
- duration: track.length * 1000,
+ videoId: id,
+ title: title,
+ duration: track.duration * 1000,
buyLinks: buyLinks,
- type: 'officialfm'
+ type: 'officialfm',
+ artworkURL: track.cover.urls.large
}));
});
return ret;
Please sign in to comment.
Something went wrong with that request. Please try again.