diff --git a/lib/services/rdio/index.js b/lib/services/rdio/index.js deleted file mode 100644 index cb0955d..0000000 --- a/lib/services/rdio/index.js +++ /dev/null @@ -1,168 +0,0 @@ -import { parse } from 'url'; -import bluebird from 'bluebird'; -import rdioInit from 'rdio'; -import { match as urlMatch } from './url'; - -export let id = 'rdio'; - -if (!process.env.RDIO_CLIENT_ID || !process.env.RDIO_CLIENT_SECRET) { - console.warn('RDIO_CLIENT_ID or RDIO_CLIENT_SECRET environment constiables not found, deactivating Rdio.'); -} - -const Rdio = rdioInit({ - rdio: { - clientId: process.env.RDIO_CLIENT_ID, - clientSecret: process.env.RDIO_CLIENT_SECRET, - } -}); - -const rdio = bluebird.promisifyAll(new Rdio()); - -export const match = urlMatch; - -export function* lookupId(id) { - yield rdio.getClientTokenAsync(); - const response = yield rdio.requestAsync({method: 'getObjectFromShortCode', short_code: id}, false); - const result = response.result; - const parsedShortUrl = parse(result.shortUrl); - const rid = parsedShortUrl.path.replace('/x/', '').replace('/', ''); - const type = result.album ? 'track' : 'album'; - - const item = { - service: 'rdio', - type: type, - id: rid, - name: result.name, - streamUrl: result.shortUrl, - purchaseUrl: null, - 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 - } - }; - if (type === 'track') { - item.album = { - name: result.album - }; - } - return item; -}; - -export function* parseUrl(url) { - const parsedUrl = parse(url); - - let query, args; - - if (parsedUrl.host === 'rd.io') { - query = { - method: 'getObjectFromShortCode', - short_code: parsedUrl.path.replace('/x/', '').replace('/', '') - }; - } else if (parsedUrl.host.match(/rdio\.com$/)) { - query = { - method: 'getObjectFromUrl', - url: parsedUrl.path - }; - } else { - const error = new Error('Not Found'); - error.status = 404; - throw error; - } - - yield rdio.getClientTokenAsync(); - const response = yield rdio.requestAsync(query, false); - const result = response.result; - const parsedShortUrl = parse(result.shortUrl); - const id = parsedShortUrl.path.replace('/x/', '').replace('/', ''); - const type = result.album ? 'track' : 'album'; - const item = { - service: 'rdio', - type: type, - id: id, - name: result.name, - streamUrl: result.shortUrl, - purchaseUrl: null, - 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 - } - }; - if (type === 'track') { - item.album = { - name: result.album - }; - } - return item; -}; - -export function* search(data) { - let query, albumClean; - const type = data.type; - - if (type === 'album') { - query = data.artist.name + ' ' + data.name; - albumClean = data.name.match(/([^\(\[]+)/)[0]; - } else if (type === 'track') { - query = data.artist.name + ' ' + data.album.name + ' ' + data.name; - try { - albumClean = data.album.name.match(/([^\(\[]+)/)[0]; - } catch(e) { - albumClean = ''; - } - } - - yield rdio.getClientTokenAsync(); - const response = yield rdio.requestAsync({method: 'search', query: query, types: type}, false); - const result = response.result.results.filter(function(item) { - if (type === 'album' && item.name.match(/([^\(\[]+)/)[0] === albumClean) { - return item; - } else if (type === 'track' && (item.album.match(/([^\(\[]+)/)[0] === albumClean || !albumClean)) { - return item; - } - }).shift(); - - if (!result) { - const matches = albumClean.match(/^[^\(\[]+/); - if (matches && matches[0] && matches[0] !== albumClean) { - const cleanedData = JSON.parse(JSON.stringify(data)); - if (type === 'album') { - cleanedData.name = matches[0].trim(); - } else if (type === 'track') { - cleanedData.album.name = matches[0].trim(); - } - return module.exports.search(cleanedData); - } else { - return {service: 'rdio'}; - } - } else { - const parsedShortUrl = parse(result.shortUrl); - const id = parsedShortUrl.path.replace('/x/', '').replace('/', ''); - const item = { - service: 'rdio', - type: type, - id: id, - name: result.name, - streamUrl: result.shortUrl, - purchaseUrl: null, - 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 - } - }; - if (type === 'track') { - item.album = { - name: result.album - }; - } - return item; - } -}; diff --git a/lib/services/rdio/url.js b/lib/services/rdio/url.js deleted file mode 100644 index 8fb7f40..0000000 --- a/lib/services/rdio/url.js +++ /dev/null @@ -1,11 +0,0 @@ -import { parse } from 'url'; - -export function* match(url) { - const parsed = parse(url); - if (!parsed.host.match(/rd\.io$/) && !parsed.host.match(/rdio\.com$/)) { - return false; - } - const regular = parsed.path.match(/[\/]*artist[\/]*([^\/]*)[\/]*album[\/]*([^\/]*)[\/]*([track]*)?[\/]*([^\/]*)/); - const short = parsed.path.match(/[\/]*x[\/]*([^\/]*)/); - return (regular && !!regular[2]) || (short && !!short[1]); -}; diff --git a/package.json b/package.json index c173cc2..4494935 100644 --- a/package.json +++ b/package.json @@ -17,13 +17,12 @@ "npm": "^3.3.0" }, "dependencies": { - "babel": "~6.1.18", - "babel-cli": "^6.2.0", - "babel-core": "^6.2.1", - "babel-plugin-syntax-jsx": "^6.1.18", - "babel-plugin-transform-es2015-arrow-functions": "^6.1.18", + "babel": "^6.1.18", + "babel-cli": "^6.3.13", + "babel-core": "^6.3.13", + "babel-plugin-syntax-jsx": "^6.3.13", + "babel-plugin-transform-es2015-arrow-functions": "^6.3.13", "babel-plugin-transform-es2015-block-scoped-functions": "^6.1.18", - "babel-plugin-transform-es2015-block-scoping": "^6.1.18", "babel-plugin-transform-es2015-classes": "^6.2.2", "babel-plugin-transform-es2015-computed-properties": "^6.1.18", "babel-plugin-transform-es2015-constants": "^6.1.4", diff --git a/public/images/deezer.png b/public/images/deezer.png index ba00d74..34a9fae 100644 Binary files a/public/images/deezer.png and b/public/images/deezer.png differ diff --git a/public/images/google.png b/public/images/google.png index d4914f1..c9f278e 100644 Binary files a/public/images/google.png and b/public/images/google.png differ diff --git a/public/images/itunes.png b/public/images/itunes.png index 543f3a5..7bb4ce9 100644 Binary files a/public/images/itunes.png and b/public/images/itunes.png differ diff --git a/public/images/rdio.png b/public/images/rdio.png index c365789..6e04cf2 100644 Binary files a/public/images/rdio.png and b/public/images/rdio.png differ diff --git a/public/images/spotify.png b/public/images/spotify.png index ad02685..b165267 100644 Binary files a/public/images/spotify.png and b/public/images/spotify.png differ diff --git a/public/images/xbox.png b/public/images/xbox.png index e1f097a..d4f1e64 100644 Binary files a/public/images/xbox.png and b/public/images/xbox.png differ diff --git a/public/images/youtube.png b/public/images/youtube.png index 4aebaa8..a9e6294 100644 Binary files a/public/images/youtube.png and b/public/images/youtube.png differ diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 757db1c..ca18e38 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -136,6 +136,7 @@ h3 { .service { padding: 40px 10px 10px 10px; + margin-bottom: 10px; } .matching-from { position: absolute; @@ -152,7 +153,6 @@ h3 { width: 100%; height: 0; padding-bottom: 100%; - margin-bottom: 10px; background-repeat: none; background-size: cover; border-radius: 5px; @@ -211,7 +211,7 @@ h3 { text-decoration: none; } .service-link img { - margin-bottom: 7px; + height: 40px; } .error { diff --git a/test/services/rdio.js b/test/services/rdio.js deleted file mode 100644 index 5dd9a4c..0000000 --- a/test/services/rdio.js +++ /dev/null @@ -1,30 +0,0 @@ -import 'should'; -import * as rdio from '../../lib/services/rdio'; - -describe('Rdio', function(){ - describe('lookupId', function(){ - it('should find album by ID', function* (){ - const result = yield rdio.lookupId('Qj4NXr0'); - result.name.should.equal('Listen (Deluxe)'); - }); - }); - - describe('search', function(){ - it('should find album by search', function* (){ - const result = yield rdio.search({type: 'album', artist: {name: 'David Guetta'}, name: 'Listen (Deluxe)'}); - result.name.should.equal('Listen (Deluxe)'); - }); - }); - - describe('parseUrl', function(){ - it('should parse regular url into album object', function* (){ - const result = yield rdio.parseUrl('https://www.rdio.com/artist/David_Guetta/album/Listen_(Deluxe)/'); - result.name.should.equal('Listen (Deluxe)'); - }); - - it('should parse short url into album object', function* (){ - const result = yield rdio.parseUrl('http://rd.io/x/Qj4NXr0/'); - result.name.should.equal('Listen (Deluxe)'); - }); - }); -}); diff --git a/views/share.js b/views/share.js index c381d9c..70f935b 100644 --- a/views/share.js +++ b/views/share.js @@ -39,7 +39,7 @@ const MusicItem = React.createClass({ return ( <div className='col-md-3 col-xs-6'> <div className={'service' + (this.props.inc === 0 ? ' source-service' : '')}> - <div className='matching-from hidden-xs'>{this.props.inc === 0 ? 'Found matches using this link' : ''}</div> + <div className='matching-from'>{this.props.inc === 0 ? 'Found matches using' : ''}</div> <a href={this.props.item.streamUrl || this.props.item.purchaseUrl}> <div className={this.props.item.service === 'youtube' ? 'artwork-youtube artwork' : 'artwork'} style={{backgroundImage: 'url(' + this.props.item.artwork.small + ')'}}> </div> @@ -47,11 +47,11 @@ const MusicItem = React.createClass({ {this.props.item.service === 'youtube' && this.props.inc > 0 ? this.props.item.name : ''} </div> </a> - <div className='service-link'> - <a href={this.props.item.streamUrl || this.props.item.purchaseUrl}> - <img src={'/images/' + this.props.item.service + '.png'} className='img-rounded' /> - </a> - </div> + </div> + <div className='service-link'> + <a href={this.props.item.streamUrl || this.props.item.purchaseUrl}> + <img src={'/images/' + this.props.item.service + '.png'} /> + </a> </div> </div> );