-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up storing analysis and audio files
- Loading branch information
Showing
13 changed files
with
325 additions
and
585 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
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
15 changes: 8 additions & 7 deletions
15
src/main/kotlin/org/abimon/eternalJukebox/data/NodeSource.kt
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,26 +1,27 @@ | ||
package org.abimon.eternalJukebox.data | ||
|
||
import com.github.kittinunf.fuel.Fuel | ||
import org.abimon.visi.io.DataSource | ||
import org.abimon.visi.io.HTTPDataSource | ||
import java.net.URL | ||
import io.vertx.ext.web.RoutingContext | ||
import org.abimon.eternalJukebox.redirect | ||
import java.util.* | ||
|
||
abstract class NodeSource { | ||
abstract val nodeHosts: Array<String> | ||
|
||
private val rng: Random = Random() | ||
|
||
fun provide(path: String): DataSource? { | ||
fun provide(path: String, context: RoutingContext): Boolean { | ||
val starting = rng.nextInt(nodeHosts.size) | ||
|
||
for (i in nodeHosts.indices) { | ||
val host = nodeHosts[(starting + i) % nodeHosts.size] | ||
val (_, healthy) = Fuel.get("$host/api/node/healthy").timeout(5 * 1000).response() | ||
if (healthy.statusCode == 200) | ||
return HTTPDataSource(URL("$host/api/node/$path")) | ||
if (healthy.statusCode == 200) { | ||
context.response().redirect("$host/api/node/$path") | ||
return true | ||
} | ||
} | ||
|
||
return null | ||
return false | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
src/main/kotlin/org/abimon/eternalJukebox/data/audio/IAudioSource.kt
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,25 +1,25 @@ | ||
package org.abimon.eternalJukebox.data.audio | ||
|
||
import io.vertx.ext.web.RoutingContext | ||
import org.abimon.eternalJukebox.EternalJukebox | ||
import org.abimon.eternalJukebox.objects.ClientInfo | ||
import org.abimon.eternalJukebox.objects.JukeboxInfo | ||
import org.abimon.visi.io.DataSource | ||
import java.net.URL | ||
|
||
@FunctionalInterface | ||
interface IAudioSource { | ||
val audioSourceOptions | ||
get() = EternalJukebox.config.audioSourceOptions | ||
/** | ||
* Provide the audio data for a required song | ||
* Returns a data source pointing to a **valid audio file**, or null if none can be obtained | ||
* Provide the audio data for a required song to the routing context. | ||
* Returns true if handled; false otherwise. | ||
*/ | ||
suspend fun provide(info: JukeboxInfo, clientInfo: ClientInfo?): DataSource? | ||
suspend fun provide(info: JukeboxInfo, context: RoutingContext): Boolean | ||
|
||
/** | ||
* Provide a location for a required song | ||
* The provided location may not be a direct download link, and may not contain valid audio data. | ||
* The provided location, however, should be a link to said song where possible, or return null if nothing could be found. | ||
*/ | ||
suspend fun provideLocation(info: JukeboxInfo, clientInfo: ClientInfo?): URL? = null | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/kotlin/org/abimon/eternalJukebox/data/audio/NodeAudioSource.kt
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
Oops, something went wrong.