iTunes tracks, iTunes url lookups
This commit is contained in:
parent
da5daeeffb
commit
dcca32c998
6 changed files with 110 additions and 99 deletions
|
@ -69,7 +69,11 @@ module.exports.search = function(data) {
|
||||||
query = data.artist.name + " " + data.album.name + " " + data.name;
|
query = data.artist.name + " " + data.album.name + " " + data.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
pm.search(query, 5, function(data) { // max 5 results
|
pm.search(query, 5, function(data) {
|
||||||
|
if (!data.entries) {
|
||||||
|
deferred.resolve({service: "googleplaymusic"});
|
||||||
|
return;
|
||||||
|
}
|
||||||
var result = data.entries.filter(function(result) {
|
var result = data.entries.filter(function(result) {
|
||||||
return result[type];
|
return result[type];
|
||||||
}).sort(function(a, b) { // sort by match score
|
}).sort(function(a, b) { // sort by match score
|
||||||
|
|
|
@ -14,81 +14,83 @@ module.exports.match = function(url, type) {
|
||||||
|
|
||||||
module.exports.lookupId = function(id, type) {
|
module.exports.lookupId = function(id, type) {
|
||||||
var deferred = Q.defer();
|
var deferred = Q.defer();
|
||||||
if (type == "album") {
|
var path = "/lookup?id=" + id;
|
||||||
request.get(apiRoot + "/albums/" + id + "/images/default?size=medium&client_id=" + credentials.key).redirects(0).end(function(res) {
|
|
||||||
var artwork = res.headers.location;
|
|
||||||
request.get(apiRoot + "/albums/" + id + "?client_id=" + credentials.key, function(res) {
|
|
||||||
var result = res.body.data;
|
|
||||||
deferred.resolve({
|
|
||||||
service: "itunes",
|
|
||||||
type: "album",
|
|
||||||
id: result.id,
|
|
||||||
name: result.title,
|
|
||||||
url: "https://listen.beatsmusic.com/albums/" + result.id,
|
|
||||||
artwork: artwork,
|
|
||||||
artist: {
|
|
||||||
name: result.artist_display_name
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else if (type == "track") {
|
|
||||||
request.get(apiRoot + "/tracks/" + id + "?client_id=" + credentials.key, function(res) {
|
|
||||||
var result = res.body.data;
|
|
||||||
request.get(apiRoot + "/albums/" + result.refs.album.id + "/images/default?size=medium&client_id=" + credentials.key).redirects(0).end(function(res) {
|
|
||||||
var artwork = res.headers.location;
|
|
||||||
deferred.resolve({
|
|
||||||
service: "itunes",
|
|
||||||
type: "track",
|
|
||||||
id: result.id,
|
|
||||||
name: result.title,
|
|
||||||
purchaseUrl: "https://listen.beatsmusic.com/albums/" + result.refs.album.id + "/tracks/" + result.id,
|
|
||||||
streamUrl: null,
|
|
||||||
artwork: artwork,
|
|
||||||
artist: {
|
|
||||||
name: result.artist_display_name
|
|
||||||
},
|
|
||||||
album: {
|
|
||||||
name: result.refs.album.display
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.search = function(data) {
|
|
||||||
var deferred = Q.defer();
|
|
||||||
var query = "";
|
|
||||||
var type = data.type;
|
|
||||||
|
|
||||||
if (type == "album") {
|
|
||||||
query = data.artist.name + " " + data.name;
|
|
||||||
} else if (type == "track") {
|
|
||||||
query = data.artist.name + " " + data.album.name + " " + data.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
var path = "/search?term=" + encodeURIComponent(query) + "&media=music&entity=album"
|
|
||||||
request.get(apiRoot + path, function(res) {
|
request.get(apiRoot + path, function(res) {
|
||||||
var data = JSON.parse(res.text);
|
var data = JSON.parse(res.text);
|
||||||
|
|
||||||
if (!data.results[0].collectionId) {
|
if (!data.results[0].collectionId) {
|
||||||
deferred.resolve({service: "itunes"});
|
deferred.resolve({service: "itunes"});
|
||||||
} else {
|
} else {
|
||||||
var result = data.results[0];
|
var result = data.results[0];
|
||||||
|
|
||||||
deferred.resolve({
|
var item = {
|
||||||
service: "itunes",
|
service: "itunes",
|
||||||
type: type,
|
type: type,
|
||||||
id: result.collectionId,
|
id: result.collectionId,
|
||||||
name: result.collectionName,
|
name: result.trackName ? result.trackName : result.collectionName,
|
||||||
streamUrl: null,
|
streamUrl: null,
|
||||||
purchaseUrl: result.collectionViewUrl,
|
purchaseUrl: result.collectionViewUrl,
|
||||||
artwork: result.artworkUrl100.replace("100x100", "200x200"),
|
artwork: result.artworkUrl100.replace("100x100", "200x200"),
|
||||||
artist: {
|
artist: {
|
||||||
name: result.artistName
|
name: result.artistName
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (type == "track") {
|
||||||
|
item.album = {
|
||||||
|
name: result.collectionName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
deferred.resolve(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.search = function(data) {
|
||||||
|
var deferred = Q.defer();
|
||||||
|
var query = "";
|
||||||
|
var entity = "";
|
||||||
|
var type = data.type;
|
||||||
|
|
||||||
|
if (type == "album") {
|
||||||
|
query = data.artist.name + " " + data.name;
|
||||||
|
entity = "album";
|
||||||
|
} else if (type == "track") {
|
||||||
|
query = data.artist.name + " " + data.album.name + " " + data.name;
|
||||||
|
entity = "musicTrack";
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = "/search?term=" + encodeURIComponent(query) + "&media=music&entity=" + entity;
|
||||||
|
request.get(apiRoot + path, function(res) {
|
||||||
|
var data = JSON.parse(res.text);
|
||||||
|
|
||||||
|
if (!data.results[0].collectionId) {
|
||||||
|
deferred.resolve({service: "itunes"});
|
||||||
|
} else {
|
||||||
|
var result = data.results[0];
|
||||||
|
|
||||||
|
var item = {
|
||||||
|
service: "itunes",
|
||||||
|
type: type,
|
||||||
|
id: result.collectionId,
|
||||||
|
name: result.trackName ? result.trackName : result.collectionName,
|
||||||
|
streamUrl: null,
|
||||||
|
purchaseUrl: result.collectionViewUrl,
|
||||||
|
artwork: result.artworkUrl100.replace("100x100", "200x200"),
|
||||||
|
artist: {
|
||||||
|
name: result.artistName
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (type == "track") {
|
||||||
|
item.album = {
|
||||||
|
name: result.collectionName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
deferred.resolve(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -97,10 +99,10 @@ module.exports.search = function(data) {
|
||||||
|
|
||||||
module.exports.parseUrl = function(url) {
|
module.exports.parseUrl = function(url) {
|
||||||
var deferred = Q.defer();
|
var deferred = Q.defer();
|
||||||
var matches = parse(url).path.match(/\/(album|track)[\/]+([^\/]+)/);
|
var matches = parse(url).path.match(/\/(album|track)[\/]+([^\/]+)[\/]+([^\?]+)/);
|
||||||
|
|
||||||
if (matches && matches[2]) {
|
if (matches && matches[3]) {
|
||||||
module.exports.lookupId(matches[2], matches[1]).then(deferred.resolve);
|
module.exports.lookupId(matches[3].substr(2), matches[1]).then(deferred.resolve);
|
||||||
}
|
}
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ module.exports.search = function(data) {
|
||||||
}).shift();
|
}).shift();
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return next({service: "rdio"});
|
return deferred.resolve({service: "rdio"});
|
||||||
}
|
}
|
||||||
var parsed = parse(result.shortUrl)
|
var parsed = parse(result.shortUrl)
|
||||||
var id = parsed.path.replace("/x/", "").replace("/", "");
|
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||||
|
|
|
@ -40,7 +40,7 @@ router.get('/:service/:type/:id', function(req, res) {
|
||||||
return !a.id || !b.id;
|
return !a.id || !b.id;
|
||||||
}).sort(function(a, b) {
|
}).sort(function(a, b) {
|
||||||
return !a.streamUrl || b.streamUrl;
|
return !a.streamUrl || b.streamUrl;
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h2><%= items[0].artist.name %> - <%= items[0].name %></h2>
|
<h2><%= items[0].artist.name %> - <%= items[0].name %></h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -33,20 +33,20 @@
|
||||||
<div class="service <%= i==0 ? "source-service" : "" %>">
|
<div class="service <%= i==0 ? "source-service" : "" %>">
|
||||||
<div class="matching-from"><%= i==0 ? "Found matches for this link" : "" %></div>
|
<div class="matching-from"><%= i==0 ? "Found matches for this link" : "" %></div>
|
||||||
<% if (album.streamUrl) { %>
|
<% 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 %>" class="img-rounded album-artwork" width="100%"></a>
|
||||||
<div class="service-link">
|
<div class="service-link">
|
||||||
<a href="<%= album.streamUrl %>"><img src="/images/<%= album.service %>.png" class="img-rounded"></a>
|
<a href="<%= album.streamUrl %>"><img src="/images/<%= album.service %>.png" class="img-rounded"></a>
|
||||||
</div>
|
</div>
|
||||||
<% } else if (album.purchaseUrl) { %>
|
<% } 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 %>" class="img-rounded album-artwork" width="100%"></a>
|
||||||
<div class="service-link">
|
<div class="service-link">
|
||||||
<a href="<%= album.purchaseUrl %>"><img src="/images/<%= album.service %>.png" class="img-rounded"></a>
|
<a href="<%= album.purchaseUrl %>"><img src="/images/<%= album.service %>.png" class="img-rounded"></a>
|
||||||
</div>
|
</div>
|
||||||
<% }else { %>
|
<% }else { %>
|
||||||
<img src="<%= items[0].artwork %>" class="img-rounded album-artwork not-found" width="100%"></a>
|
<img src="<%= items[0].artwork %>" class="img-rounded album-artwork not-found" width="100%"></a>
|
||||||
<div class="service-link">
|
<div class="service-link">
|
||||||
<img src="/images/<%= album.service %>.png" class="img-rounded not-found">
|
<img src="/images/<%= album.service %>.png" class="img-rounded not-found">
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
</div><% if((i+1)%4 == 0) { %></div><div class="row"><% } %>
|
</div><% if((i+1)%4 == 0) { %></div><div class="row"><% } %>
|
||||||
|
|
|
@ -29,27 +29,32 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<% for (var i=0;i < items.length;i++) { var track = items[i]; %>
|
<% for (var i=0;i < items.length;i++) { var track = items[i]; %>
|
||||||
<div class="col-md-3 col-xs-6">
|
<div class="col-md-3 col-xs-6">
|
||||||
<div class="service <%= i==0 ? "source-service" : "" %>">
|
<div class="service <%= i==0 ? "source-service" : "" %>">
|
||||||
<div class="matching-from"><%= i==0 ? "Found matches for this link" : "" %></div>
|
<div class="matching-from"><%= i==0 ? "Found matches for this link" : "" %></div>
|
||||||
<% if (track.url) { %>
|
<% if (track.streamUrl) { %>
|
||||||
<a href="<%= track.url %>"><img src="<%= track.artwork %>" class="img-rounded album-artwork" width="100%"></a>
|
<a href="<%= track.streamUrl %>"><img src="<%= track.artwork %>" class="img-rounded album-artwork" width="100%"></a>
|
||||||
<div class="service-link">
|
<div class="service-link">
|
||||||
<a href="<%= track.url %>"><img src="/images/<%= track.service %>.png" class="img-rounded"></a>
|
<a href="<%= track.streamUrl %>"><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>
|
|
||||||
<div class="service-link">
|
|
||||||
<img src="/images/<%= track.service %>.png" class="img-rounded not-found">
|
|
||||||
</div>
|
|
||||||
<% } %>
|
|
||||||
</div>
|
</div>
|
||||||
|
<% } else if (track.purchaseUrl) { %>
|
||||||
|
<a href="<%= track.purchaseUrl %>"><img src="<%= track.artwork %>" 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>
|
||||||
|
<div class="service-link">
|
||||||
|
<img src="/images/<%= track.service %>.png" class="img-rounded not-found">
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
</div><% if((i+1)%4 == 0) { %></div><div class="row"><% } %>
|
||||||
</div>
|
<% } %>
|
||||||
<div class="row share">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
<div class="row share">
|
||||||
</html>
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue