Skip to content

Commit

Permalink
Create categories for plugins: meta provider, stream provider, lyrics…
Browse files Browse the repository at this point in the history
… provider
  • Loading branch information
nukeop committed Sep 24, 2019
1 parent 6342e5a commit 32cc322
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 30 deletions.
6 changes: 4 additions & 2 deletions app/actions/lyrics.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as LyricsSearch from '../plugins/Lyrics';
import SimpleLyricsProvider from '../plugins/lyrics/simple';
import logger from 'electron-timber';
export const LYRIC_SEARCH_START = 'LYRIC_SEARCH_START';
export const LYRIC_SEARCH_SUCCESS = 'LYRIC_SEARCH_SUCCESS';

const lyricsProvider = new SimpleLyricsProvider();

export function lyricSearchStart (query) {
return {
type: LYRIC_SEARCH_START,
Expand All @@ -23,7 +25,7 @@ export function lyricSearchSuccess (query, result) {
export function lyricsSearch (track) {
return dispatch => {
dispatch(lyricSearchStart(track));
LyricsSearch.search(track.artist, track.name)
lyricsProvider.search(track.artist, track.name)
.then(results => {
dispatch(lyricSearchSuccess(results));
})
Expand Down
9 changes: 0 additions & 9 deletions app/plugins/Lyrics/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/plugins/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as MusicSourcePlugins from './MusicSources/';
import * as StreamProviderPlugins from './stream/';

export const config = {
plugins: {
musicSources: MusicSourcePlugins
musicSources: StreamProviderPlugins
}
};
23 changes: 23 additions & 0 deletions app/plugins/lyrics/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import logger from 'electron-timber';
import lyrics from 'simple-get-lyrics';

import LyricsProvider from '../lyricsProvider';

class SimpleLyricsProvider extends LyricsProvider {
constructor() {
super();
this.name = 'Simple Lyrics Provider Plugin';
this.sourceName = 'Simple Lyrics Provider';
this.description = 'Simple lyrics provider plugin. Uses several sources with fallbacks.';
this.image = null;
}

search (artistName, trackName) {
return lyrics.search(artistName, trackName)
.then(result => result.lyrics).catch(function (err) {
logger.log('error', err);
});
}
}

export default SimpleLyricsProvider;
19 changes: 19 additions & 0 deletions app/plugins/lyricsProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import logger from 'electron-timber';

import Plugin from './plugin';

class LyricsProvider extends Plugin {
constructor() {
super();
this.name = 'Lyrics Provider Plugin';
this.sourceName = 'Generic Lyrics Provider';
this.description = 'A generic lyrics provider plugin. Should never be instantiated directly';
this.image = null;
}

search(artistName, trackName) {
logger.error(`Search not implemented in plugin ${this.name}\n Query was: ${artistName}, ${trackName}`);
}
}

export default LyricsProvider;
27 changes: 27 additions & 0 deletions app/plugins/metaProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logger from 'electron-timber';

import Plugin from './plugin';

class MetaProvider extends Plugin {
constructor() {
super();
this.name = 'Meta Provider Plugin';
this.sourceName = 'Generic Metadata Provider';
this.description = 'A generic metadata provider plugin. Should never be instantiated directly';
this.image = null;
}

searchForArtists(query) {
logger.error(`Search not implemented in plugin ${this.name}\n Query was: ${query}`);
}

searchForReleases(query) {
logger.error(`Search not implemented in plugin ${this.name}\n Query was: ${query}`);
}

searchAll(query) {
logger.error(`Search not implemented in plugin ${this.name}\n Query was: ${query}`);
}
}

export default MetaProvider;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logger from 'electron-timber';
import _ from 'lodash';

import MusicSourcePlugin from '../musicSources';
import StreamProviderPlugin from '../streamProvider';
import * as Jamendo from '../../rest/Jamendo';

class JamendoPlugin extends MusicSourcePlugin {
class JamendoPlugin extends StreamProviderPlugin {
constructor() {
super();
this.name = 'Jamendo Plugin';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MusicSourcePlugin from '../musicSources';
import StreamProviderPlugin from '../streamProvider';
import { localSearch } from '../../rest/Local';

class LocalPlugin extends MusicSourcePlugin {
class LocalPlugin extends StreamProviderPlugin {
constructor() {
super();
this.name = 'Local Plugin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import logger from 'electron-timber';
import _ from 'lodash';

import globals from '../../globals';
import MusicSourcePlugin from '../musicSources';
import StreamProviderPlugin from '../streamProvider';
import * as Soundcloud from '../../rest/Soundcloud';

class SoundcloudPlugin extends MusicSourcePlugin {
class SoundcloudPlugin extends StreamProviderPlugin {
constructor() {
super();
this.name = 'Soundcloud Plugin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import logger from 'electron-timber';
import _ from 'lodash';
import ytdl from 'ytdl-core';

import MusicSourcePlugin from '../musicSources';
import StreamProviderPlugin from '../streamProvider';
import * as Youtube from '../../rest/Youtube';

class YoutubePlugin extends MusicSourcePlugin {
class YoutubePlugin extends StreamProviderPlugin {
constructor() {
super();
this.name = 'Youtube Plugin';
Expand Down Expand Up @@ -37,7 +37,7 @@ class YoutubePlugin extends MusicSourcePlugin {
})
.catch(error => {
logger.error(`Error while searching for ${terms} on Youtube`);
logger.error(error);
logger.error(error);
});
}

Expand Down Expand Up @@ -65,7 +65,7 @@ class YoutubePlugin extends MusicSourcePlugin {
})
.catch(error => {
logger.error(`Error while looking up streams for ${terms} on Youtube`);
logger.error(error);
logger.error(error);
});
}
}
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions app/plugins/musicSources.js → app/plugins/streamProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import logger from 'electron-timber';

import Plugin from './plugin';

class MusicSourcePlugin extends Plugin {
class StreamProviderPlugin extends Plugin {
constructor() {
super();
this.name = 'Music Source Plugin';
this.sourceName = 'Generic Music Source';
this.description = 'A generic music source plugin. Should never be instantiated directly';
this.name = 'Stream Provider Plugin';
this.sourceName = 'Generic Stream Provider';
this.description = 'A generic stream provider plugin. Should never be instantiated directly';
this.image = null;
}

search(query) {
/*
query is an object :
query is an object :
{
artist : 'The artist name,
track : 'The track to search'
}
*/
logger.error('search not implemented in plugin ' + this.name +
logger.error('search not implemented in plugin ' + this.name +
'\n Query was: ' + query);
}

Expand All @@ -30,4 +30,4 @@ class MusicSourcePlugin extends Plugin {
}
}

export default MusicSourcePlugin;
export default StreamProviderPlugin;

0 comments on commit 32cc322

Please sign in to comment.