forked from nukeop/nuclear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Charles
committed
Jan 22, 2020
1 parent
811534e
commit 606ea6f
Showing
12 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
ACOUSTIC_ID_KEY=Fivodjxo37 | ||
YOUTUBE_API_KEY=AIzaSyCIM4EzNqi1in22f4Z3Ru3iYvLaY8tc3bo | ||
DISCORD_CLIENT_ID=668477264995811338 | ||
GITHUB_CLIENT_ID=ac58d6da7d7a74c039b7 | ||
GITHUB_SECRET=37d02377a3e9d849e18704c3ec823f9c5787d857 | ||
INVIDIOUS_URL=https://invidio.us | ||
JAMENDO_CLIENT_ID=836523a7 | ||
LAST_FM_API_KEY=2b75dcb291e2b0c9a2c994aca522ac14 | ||
LAST_FM_API_SECRET=2ee49e35f08b837d43b2824198171fc8 | ||
SOUNDCLOUD_API_KEY=22e8f71d7ca75e156d6b2f0e0a5172b3 | ||
JAMENDO_CLIENT_ID=836523a7 | ||
GITHUB_CLIENT_ID=ac58d6da7d7a74c039b7 | ||
GITHUB_SECRET=37d02377a3e9d849e18704c3ec823f9c5787d857 | ||
YOUTUBE_API_KEY=AIzaSyCIM4EzNqi1in22f4Z3Ru3iYvLaY8tc3bo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ | |
font-size: 1.2rem; | ||
padding: 0.5rem 1.5rem; | ||
border: 1px solid $white; | ||
cursor: pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import logger from 'electron-timber'; | ||
|
||
import StreamProviderPlugin from '../streamProvider'; | ||
import * as Invidious from '../../rest/Invidious'; | ||
|
||
class InvidiousPlugin extends StreamProviderPlugin { | ||
constructor() { | ||
super(); | ||
this.name = 'Invidious Plugin'; | ||
this.sourceName = 'Invidious'; | ||
this.description = 'A plugin allowing Nuclear to search for music and play it from invidious'; | ||
} | ||
|
||
async search(query) { | ||
const terms = query.artist + ' ' + query.track; | ||
try { | ||
const { | ||
adaptiveFormats, | ||
lengthSeconds, | ||
title, | ||
videoId, | ||
videoThumbnails | ||
} = await Invidious.trackSearch(terms); | ||
|
||
return { | ||
source: this.sourceName, | ||
id: videoId, | ||
stream: adaptiveFormats.find(({ type }) => type.includes('audio')).url, | ||
duration: lengthSeconds, | ||
title, | ||
thumbnail: videoThumbnails[3].url | ||
}; | ||
} catch (error) { | ||
logger.error(`Error while searching for ${terms} on Invidious`); | ||
logger.error(error); | ||
} | ||
} | ||
|
||
async getAlternateStream(query) { | ||
const terms = query.artist + ' ' + query.track; | ||
try { | ||
const { | ||
adaptiveFormats, | ||
lengthSeconds, | ||
title, | ||
videoId, | ||
videoThumbnails | ||
} = await Invidious.trackSearch(terms, true); | ||
|
||
return { | ||
source: this.sourceName, | ||
id: videoId, | ||
stream: adaptiveFormats.find(({ type }) => type.includes('audio')).url, | ||
duration: lengthSeconds, | ||
title, | ||
thumbnail: videoThumbnails[3].url | ||
}; | ||
} catch (error) { | ||
logger.error(`Error while searching for ${terms} on Invidious`); | ||
logger.error(error); | ||
} | ||
} | ||
} | ||
|
||
export default InvidiousPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as YoutubePlugin } from './YoutubePlugin'; | ||
export { default as SoundcloudPlugin } from './SoundcloudPlugin'; | ||
export { default as JamendoPlugin } from './JamendoPlugin'; | ||
export { default as InvidiousPlugin } from './InvidiousPlugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { getOption } from '../persistence/store'; | ||
|
||
const baseUrl = getOption('invidious.url'); | ||
|
||
export const trackSearch = async (query, alternate) => { | ||
const response = await fetch(`${baseUrl}/api/v1/search?q=${query}&sortBy=relevance&page=1`); | ||
if (!response.ok) { | ||
throw new Error('invidious search failed'); | ||
} | ||
const result = await response.json(); | ||
|
||
const trackInfo = await getTrackInfo(result[alternate ? 1 : 0].videoId); | ||
|
||
return trackInfo; | ||
}; | ||
|
||
const getTrackInfo = async (videoId) => { | ||
const response = await fetch(`${baseUrl}/api/v1/videos/${videoId}`); | ||
if (!response.ok) { | ||
throw new Error('invidious track info failed'); | ||
} | ||
|
||
return response.json(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters