More bluebird, fetch larger artwork
This commit is contained in:
parent
e671b823e9
commit
23896f7ee6
16 changed files with 117 additions and 81 deletions
24
app.js
24
app.js
|
@ -35,18 +35,11 @@ app.use(session({
|
|||
app.use(flash());
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
var db;
|
||||
if (process.env.MONGOHQ_URL) {
|
||||
console.log("Connecting to MongoHQ")
|
||||
db = pmongo(process.env.MONGOHQ_URL, ['matches']);
|
||||
} else {
|
||||
db = pmongo('match-audio', ['matches']);
|
||||
}
|
||||
|
||||
var dbUrl = process.env.MONGOHQ_URL || "mongodb://localhost/match-audio";
|
||||
app.use(function(req, res, next) {
|
||||
req.db = res.db = db;
|
||||
req.db = res.db = pmongo(dbUrl, ['matches']);
|
||||
next();
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
app.get('*', function(req,res,next) {
|
||||
|
@ -56,7 +49,7 @@ app.get('*', function(req,res,next) {
|
|||
} else if (req.headers['cf-visitor']) {
|
||||
req.userProtocol = "https";
|
||||
} else {
|
||||
req.userProtocol = "http"
|
||||
req.userProtocol = "http";
|
||||
}
|
||||
// redirect www
|
||||
if (req.headers.host.match(/^www/) !== null ) {
|
||||
|
@ -67,15 +60,8 @@ app.get('*', function(req,res,next) {
|
|||
});
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
var samples = [
|
||||
{artist: "Aesop Rock", album: "Skelethon", url: '/google/album/B3ppmqcekrmxln4bre33om3qife'},
|
||||
{artist: "Hozier", album: "self-titled album", url: '/google/album/Bd3mxcy3otokg4yc45qktq7l35q'},
|
||||
{artist: "Daft Punk", album: "Discovery", url: '/google/album/B4t6yqqvhnb2hy4st4uisjrcsrm'}
|
||||
];
|
||||
|
||||
// shitty sort until I add more metadata on cached items
|
||||
req.db.matches.find().sort({$natural:-1}).limit(6).toArray().then(function(docs){
|
||||
res.render('index', { page: "home", samples: samples, recent: docs, error: req.flash('search-error') });
|
||||
res.render('index', { page: "home", recent: docs, error: req.flash('search-error') });
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -33,27 +33,30 @@ module.exports.parseUrl = function(url) {
|
|||
|
||||
module.exports.lookupId = function(id, type) {
|
||||
if (type == "album") {
|
||||
return request.get(apiRoot + "/albums/" + id + "/images/default?size=medium&client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
||||
var artwork = res.headers.location;
|
||||
return request.get(apiRoot + "/albums/" + id + "?client_id=" + credentials.key).promise().then(function(res) {
|
||||
if (!res.body.data) {
|
||||
var error = new Error("Not Found");
|
||||
error.status = 404;
|
||||
throw error;
|
||||
}
|
||||
var result = res.body.data;
|
||||
return {
|
||||
service: "beats",
|
||||
type: "album",
|
||||
id: result.id,
|
||||
name: result.title,
|
||||
streamUrl: "https://listen.beatsmusic.com/albums/" + result.id,
|
||||
purchaseUrl: null,
|
||||
artwork: artwork.replace("http:", "https:"),
|
||||
artist: {
|
||||
name: result.artist_display_name
|
||||
return request.get(apiRoot + "/albums/" + id + "/images/default?size=large&client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
||||
var artwork = {large: res.headers.location.replace("http:", "https:")};
|
||||
return request.get(apiRoot + "/albums/" + id + "/images/default?client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
||||
artwork.small = res.headers.location.replace("http:", "https:");
|
||||
return request.get(apiRoot + "/albums/" + id + "?client_id=" + credentials.key).promise().then(function(res) {
|
||||
if (!res.body.data) {
|
||||
var error = new Error("Not Found");
|
||||
error.status = 404;
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
var result = res.body.data;
|
||||
return {
|
||||
service: "beats",
|
||||
type: "album",
|
||||
id: result.id,
|
||||
name: result.title,
|
||||
streamUrl: "https://listen.beatsmusic.com/albums/" + result.id,
|
||||
purchaseUrl: null,
|
||||
artwork: artwork,
|
||||
artist: {
|
||||
name: result.artist_display_name
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
} else if (type == "track") {
|
||||
|
@ -64,23 +67,26 @@ module.exports.lookupId = function(id, type) {
|
|||
throw error;
|
||||
}
|
||||
var result = res.body.data;
|
||||
return request.get(apiRoot + "/albums/" + result.refs.album.id + "/images/default?size=medium&client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
||||
var artwork = res.headers.location;
|
||||
return {
|
||||
service: "beats",
|
||||
type: "track",
|
||||
id: result.id,
|
||||
name: result.title,
|
||||
streamUrl: "https://listen.beatsmusic.com/albums/" + result.refs.album.id + "/tracks/" + result.id,
|
||||
purchaseUrl: null,
|
||||
artwork: artwork.replace("http:", "https:"),
|
||||
artist: {
|
||||
name: result.artist_display_name
|
||||
},
|
||||
album: {
|
||||
name: result.refs.album.display
|
||||
}
|
||||
};
|
||||
return request.get(apiRoot + "/albums/" + result.refs.album.id + "/images/default?size=large&client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
||||
var artwork = {large: res.headers.location.replace("http:", "https:")};
|
||||
return request.get(apiRoot + "/albums/" + result.refs.album.id + "/images/default?client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
||||
artwork.small = res.headers.location.replace("http:", "https:");
|
||||
return {
|
||||
service: "beats",
|
||||
type: "track",
|
||||
id: result.id,
|
||||
name: result.title,
|
||||
streamUrl: "https://listen.beatsmusic.com/albums/" + result.refs.album.id + "/tracks/" + result.id,
|
||||
purchaseUrl: null,
|
||||
artwork: artwork,
|
||||
artist: {
|
||||
name: result.artist_display_name
|
||||
},
|
||||
album: {
|
||||
name: result.refs.album.display
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -32,7 +32,10 @@ module.exports.lookupId = function(id, type) {
|
|||
}
|
||||
var cover = result.cover || result.album.cover;
|
||||
return request.get(cover).redirects(0).promise().then(function(res) {
|
||||
var artwork = res.headers.location.replace("120x120", "200x200");
|
||||
var artwork = {
|
||||
small: res.headers.location.replace("120x120", "200x200"),
|
||||
large: res.headers.location.replace("120x120", "800x800")
|
||||
};
|
||||
if (type == "album") {
|
||||
return {
|
||||
service: "deezer",
|
||||
|
|
|
@ -53,7 +53,10 @@ module.exports.lookupId = function(id, type) {
|
|||
name: album.name,
|
||||
streamUrl: "https://play.google.com/music/listen#/album/" + album.albumId,
|
||||
purchaseUrl: "https://play.google.com/store/music/album?id=" + album.albumId,
|
||||
artwork: album.albumArtRef.replace("http:", "https:"),
|
||||
artwork: {
|
||||
small: album.albumArtRef.replace("http:", "https:"),
|
||||
large: album.albumArtRef.replace("http:", "https:")
|
||||
},
|
||||
artist: {
|
||||
name: album.artist
|
||||
}
|
||||
|
@ -70,7 +73,10 @@ module.exports.lookupId = function(id, type) {
|
|||
name: track.title,
|
||||
streamUrl: "https://play.google.com/music/listen#/track/" + track.nid + "/" + track.albumId,
|
||||
purchaseUrl: "https://play.google.com/store/music/album?id=" + track.albumId,
|
||||
artwork: track.albumArtRef[0].url.replace("http:", "https:"),
|
||||
artwork: {
|
||||
small: track.albumArtRef[0].url.replace("http:", "https:"),
|
||||
large: track.albumArtRef[0].url.replace("http:", "https:")
|
||||
},
|
||||
album: {
|
||||
name: track.album
|
||||
},
|
||||
|
|
|
@ -57,7 +57,10 @@ module.exports.lookupId = function(id, type, cc) {
|
|||
name: result.trackName ? result.trackName : result.collectionName,
|
||||
streamUrl: null,
|
||||
purchaseUrl: result.collectionViewUrl,
|
||||
artwork: "https://match.audio/itunes/" + result.artworkUrl100.replace("100x100", "200x200").replace("http://", ""),
|
||||
artwork: {
|
||||
small: "https://match.audio/itunes/" + result.artworkUrl100.replace("100x100", "200x200").replace("http://", ""),
|
||||
large: "https://match.audio/itunes/" + result.artworkUrl100.replace("100x100", "600x600").replace("http://", ""),
|
||||
},
|
||||
artist: {
|
||||
name: result.artistName
|
||||
}
|
||||
|
@ -115,7 +118,10 @@ module.exports.search = function(data) {
|
|||
name: result.trackName ? result.trackName : result.collectionName,
|
||||
streamUrl: null,
|
||||
purchaseUrl: result.collectionViewUrl,
|
||||
artwork: "https://match.audio/itunes/" + result.artworkUrl100.replace("100x100", "200x200").replace("http://", ""),
|
||||
artwork: {
|
||||
small: "https://match.audio/itunes/" + result.artworkUrl100.replace("100x100", "200x200").replace("http://", ""),
|
||||
large: "https://match.audio/itunes/" + result.artworkUrl100.replace("100x100", "600x600").replace("http://", ""),
|
||||
},
|
||||
artist: {
|
||||
name: result.artistName
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ module.exports.lookupId = function(id) {
|
|||
var parsed = parse(result.shortUrl)
|
||||
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||
var type = result.album ? "track" : "album";
|
||||
|
||||
var item = {
|
||||
service: "rdio",
|
||||
type: type,
|
||||
|
@ -36,7 +37,10 @@ module.exports.lookupId = function(id) {
|
|||
name: result.name,
|
||||
streamUrl: result.shortUrl,
|
||||
purchaseUrl: null,
|
||||
artwork: result.icon.replace("square-200", "square-250").replace("http:", "https:"),
|
||||
artwork: {
|
||||
small: result.icon.replace("square-200", "square-250").replace("http:", "https:"),
|
||||
large: result.icon.replace("square-200", "square-600").replace("http:", "https:")
|
||||
},
|
||||
artist: {
|
||||
name: result.artist
|
||||
}
|
||||
|
@ -89,7 +93,10 @@ module.exports.parseUrl = function(url) {
|
|||
name: result.name,
|
||||
streamUrl: result.shortUrl,
|
||||
purchaseUrl: null,
|
||||
artwork: result.icon.replace("square-200", "square-250").replace("http:", "https:"),
|
||||
artwork: {
|
||||
small: result.icon.replace("square-200", "square-250").replace("http:", "https:"),
|
||||
large: result.icon.replace("square-200", "square-600").replace("http:", "https:")
|
||||
},
|
||||
artist: {
|
||||
name: result.artist
|
||||
}
|
||||
|
|
|
@ -33,7 +33,10 @@ module.exports.lookupId = function(id, type) {
|
|||
name: data.name,
|
||||
streamUrl: "https://play.spotify.com/" + type + "/" + data.id,
|
||||
purchaseUrl: null,
|
||||
artwork: data.images ? data.images[1].url.replace("http:", "https:") : data.album.images[1].url.replace("http:", "https:"),
|
||||
artwork: {
|
||||
small: data.images[1].url.replace("http:", "https:"),
|
||||
large: data.images[0].url.replace("http:", "https:"),
|
||||
},
|
||||
artist: {
|
||||
name: artist.name
|
||||
}
|
||||
|
@ -46,7 +49,10 @@ module.exports.lookupId = function(id, type) {
|
|||
name: data.name,
|
||||
streamUrl: "https://play.spotify.com/" + type + "/" + data.id,
|
||||
purchaseUrl: null,
|
||||
artwork: data.images ? data.images[1].url.replace("http:", "https:") : data.album.images[1].url.replace("http:", "https:"),
|
||||
artwork: {
|
||||
small: data.album.images[1].url.replace("http:", "https:"),
|
||||
large: data.album.images[0].url.replace("http:", "https:"),
|
||||
},
|
||||
artist: {
|
||||
name: artist.name
|
||||
},
|
||||
|
|
|
@ -46,7 +46,10 @@ module.exports.search = function(data) {
|
|||
name: result.snippet.title,
|
||||
streamUrl: "https://www.youtube.com/watch?v=" + result.id.videoId,
|
||||
purchaseUrl: null,
|
||||
artwork: result.snippet.thumbnails.medium.url,
|
||||
artwork: {
|
||||
small: result.snippet.thumbnails.medium.url,
|
||||
large: result.snippet.thumbnails.high.url,
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
|
@ -23,8 +23,7 @@ module.exports = function(req, res, next) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
req.db.matches.findOne({_id:serviceId + itemId}).then(function(doc) {
|
||||
req.db.matches.findOne({_id:serviceId + "-" + itemId}).then(function(doc) {
|
||||
if (doc) {
|
||||
res.render(type, {
|
||||
page: type,
|
||||
|
@ -58,7 +57,7 @@ module.exports = function(req, res, next) {
|
|||
});
|
||||
|
||||
items.unshift(item);
|
||||
req.db.matches.save({_id:serviceId + itemId, items:items});
|
||||
req.db.matches.save({_id:serviceId + "-" + itemId, items:items});
|
||||
res.render(type, {
|
||||
page: type,
|
||||
title: item.name + " by " + item.artist.name,
|
||||
|
|
|
@ -12,6 +12,13 @@ describe('Google Play Music', function(){
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should find track by ID', function(done){
|
||||
google.lookupId("Tjosptub24g2dft37lforqnudpe", "track").then(function(result) {
|
||||
result.name.should.equal("Cherub Rock");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('search', function(){
|
||||
|
|
|
@ -7,14 +7,14 @@ var itunes = require("../../lib/services/itunes");
|
|||
describe('iTunes Music', function(){
|
||||
describe('lookupId', function(){
|
||||
it('should find album by ID', function(done){
|
||||
itunes.lookupId("id215206912").then(function(result) {
|
||||
itunes.lookupId("id215206912", "album").then(function(result) {
|
||||
result.name.should.equal("Peace Orchestra");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should find track by ID', function(done){
|
||||
itunes.lookupId("id215206958").then(function(result) {
|
||||
itunes.lookupId("id215206958", "track").then(function(result) {
|
||||
result.name.should.equal("Double Drums");
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -12,6 +12,13 @@ describe('Spotify', function(){
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should find track by ID', function(done){
|
||||
spotify.lookupId("7dS5EaCoMnN7DzlpT6aRn2", "track").then(function(result) {
|
||||
result.name.should.equal("Take Me To Church");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('search', function(){
|
||||
|
|
|
@ -34,17 +34,17 @@
|
|||
</div>
|
||||
<a href="https://www.youtube.com/results?search_query=<%= items[0].name %> <%= items[0].artist.name %>">More Youtube matches</a>
|
||||
<% } else if (album.streamUrl) { %>
|
||||
<a href="<%= album.streamUrl %>"><img src="<%= album.artwork %>" class="img-rounded album-artwork" width="100%"></a>
|
||||
<a href="<%= album.streamUrl %>"><img src="<%= album.artwork.small %>" class="img-rounded album-artwork" width="100%"></a>
|
||||
<div class="service-link">
|
||||
<a href="<%= album.streamUrl %>"><img src="/images/<%= album.service %>.png" class="img-rounded"></a>
|
||||
</div>
|
||||
<% } else if (album.purchaseUrl) { %>
|
||||
<a href="<%= album.purchaseUrl %>"><img src="<%= album.artwork %>" class="img-rounded album-artwork" width="100%"></a>
|
||||
<a href="<%= album.purchaseUrl %>"><img src="<%= album.artwork.small %>" class="img-rounded album-artwork" width="100%"></a>
|
||||
<div class="service-link">
|
||||
<a href="<%= album.purchaseUrl %>"><img src="/images/<%= album.service %>.png" class="img-rounded"></a>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<img src="<%= items[0].artwork %>" class="img-rounded album-artwork not-found" width="100%"></a>
|
||||
<img src="<%= items[0].artwork.small %>" class="img-rounded album-artwork not-found" width="100%"></a>
|
||||
<div class="service-link">
|
||||
<img src="/images/<%= album.service %>.png" class="img-rounded not-found">
|
||||
</div>
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<% if (locals.items) { var item = items[0] %>
|
||||
<meta name="twitter:card" content="summary">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@MatchAudio">
|
||||
<meta name="twitter:title" property="og:title" content="<%= item.name + " by " + item.artist.name %>">
|
||||
<meta name="twitter:description" property="og:description" content="We've matched this music on Rdio, Spotify, Deezer, Beats Music, Google Music and iTunes so you can open it in the service you use." />
|
||||
<meta name="twitter:image" property="og:image" content="<%= item.artwork %>" />
|
||||
<meta property="og:url" content="<%= thisUrl %>" />
|
||||
<meta name="twitter:image:src" property="og:image" content="<%= item.artwork.large %>" />
|
||||
<meta property="og:url" content="<%= thisUrl %>" />
|
||||
<% } %>
|
||||
<link rel="shortcut icon" href="/images/favicon.png">
|
||||
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,700' rel='stylesheet' type='text/css'>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<div class="row recent">
|
||||
<% for (var i=0;i < recent.length;i++) { var item = recent[i].items[0]; %>
|
||||
<div class="col-sm-4 col-xs-6">
|
||||
<a href="/<%= item.service.replace("playmusic", "") %>/<%= item.type %>/<%= item.id %>"><img src="<%= item.artwork %>" width="100%"></a>
|
||||
<a href="/<%= item.service.replace("playmusic", "") %>/<%= item.type %>/<%= item.id %>"><img src="<%= item.artwork.small ? item.artwork.small : item.artwork %>" width="100%"></a>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
|
|
|
@ -34,17 +34,17 @@
|
|||
</div>
|
||||
<a href="https://www.youtube.com/results?search_query=<%= items[0].name %> <%= items[0].artist.name %>">More Youtube matches</a>
|
||||
<% } else if (track.streamUrl) { %>
|
||||
<a href="<%= track.streamUrl %>"><img src="<%= track.artwork %>" class="img-rounded album-artwork" width="100%"></a>
|
||||
<a href="<%= track.streamUrl %>"><img src="<%= track.artwork.small %>" class="img-rounded album-artwork" width="100%"></a>
|
||||
<div class="service-link">
|
||||
<a href="<%= track.streamUrl %>"><img src="/images/<%= track.service %>.png" class="img-rounded"></a>
|
||||
</div>
|
||||
<% } else if (track.purchaseUrl) { %>
|
||||
<a href="<%= track.purchaseUrl %>"><img src="<%= track.artwork %>" class="img-rounded album-artwork" width="100%"></a>
|
||||
<a href="<%= track.purchaseUrl %>"><img src="<%= track.artwork.small %>" class="img-rounded album-artwork" width="100%"></a>
|
||||
<div class="service-link">
|
||||
<a href="<%= track.purchaseUrl %>"><img src="/images/<%= track.service %>.png" class="img-rounded"></a>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<img src="<%= items[0].artwork %>" class="img-rounded album-artwork not-found" width="100%"></a>
|
||||
<img src="<%= items[0].artwork.small %>" class="img-rounded album-artwork not-found" width="100%"></a>
|
||||
<div class="service-link">
|
||||
<img src="/images/<%= track.service %>.png" class="img-rounded not-found">
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue