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
val manifestWriter = if (args.size == 2) File(args[1]).writer() else System.out.writer() |
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
package org.aump.server.generator | |
import com.beust.klaxon.JsonObject | |
import org.jaudiotagger.audio.AudioFile | |
import org.jaudiotagger.audio.AudioFileIO | |
import org.jaudiotagger.tag.FieldKey | |
import java.io.File | |
fun main(args: Array<String>) { | |
val sourceDirectory = File(args.getOrNull(0) ?: System.getProperty("user.dir")) |
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
import com.sun.net.httpserver.HttpExchange | |
import com.sun.net.httpserver.HttpServer | |
import java.io.File | |
import java.net.InetSocketAddress | |
import java.net.URI | |
fun main(args: Array<String>) { | |
val port = args[0].toIntOrNull() ?: 8080 |
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
fun validRequest(exchange: HttpExchange): Boolean = | |
exchange.requestHeaders.containsKey("User-Agent") | |
&& exchange.requestMethod == "GET" |
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
fun localFileFromRequestUri(basePath: File, uri: URI): File { | |
val basePathElements = basePath.absolutePath.split(File.separator).filter { it.isNotEmpty() }.toMutableSet() | |
val clientPathElements = uri.path.substring(1).split(File.separatorChar) | |
val filteredPathElements = clientPathElements.mapNotNull { | |
if (!basePathElements.remove(it)) { | |
it | |
} else { | |
null | |
} | |
}.joinToString(separator = File.separator) { it } |
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
fun fetchFileOrNull(exchange: HttpExchange, basePath: File): File? = | |
when (validRequest(exchange)) { | |
true -> { | |
val resource = localFileFromRequestUri(basePath, exchange.requestURI) | |
print("Seeking ${resource.absolutePath}...") | |
if (resource.isFile) resource else null | |
} | |
false -> null |
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
fun fetchFileOrNull(exchange: HttpExchange, basePath: File): File? = | |
when (validRequest(exchange)) { | |
true -> { | |
val resource = localFileFromRequestUri(basePath, exchange.requestURI) | |
print("Seeking ${resource.absolutePath}...") | |
if (resource.isFile) resource else null | |
} | |
false -> null |
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
fun fetchFileOrNull(exchange: HttpExchange, basePath: File): File? = | |
when (validRequest(exchange)) { | |
true -> { | |
localFileFromRequestUri(basePath, exchange.requestURI).let { requestedFile -> | |
if (requestedFile.isFile) requestedFile else null | |
} | |
} | |
false -> null | |
} |
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
import com.sun.net.httpserver.HttpExchange | |
import com.sun.net.httpserver.HttpServer | |
import java.io.File | |
import java.net.InetSocketAddress | |
import java.net.URI | |
fun main(args: Array<String>) { | |
val port = args[0].toIntOrNull() ?: 8080 | |
val basePath = File(args.getOrElse(1, { System.getProperty("user.dir")!! })) |
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
... | |
/** | |
* Utility class to get a list of MusicTrack's based on a server-side JSON | |
* configuration. | |
*/ | |
public class RemoteJSONSource implements MusicProviderSource { | |
private static final String TAG = LogHelper.makeLogTag(RemoteJSONSource.class); |