| | |
| | | package de.uhilger.tango.api; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.sun.net.httpserver.Headers; |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import de.uhilger.tango.Server; |
| | | import de.uhilger.tango.entity.Abspielliste; |
| | | import de.uhilger.tango.entity.Entity; |
| | | import de.uhilger.tango.entity.Titel; |
| | | import de.uhilger.tango.store.FileStorage; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.logging.Logger; |
| | |
| | | * PUT /mz/api/alist/[pl-name]/[nr] an der Position nr der Liste [pl-name] den Titel im Body einfuegen |
| | | * PUT /mz/api/alist/[pl-name]/[nrVon]/[nrNach] den Titel von seiner aktuellen Position an eine |
| | | * andere Position der Liste [pl-name] verschieben |
| | | * GET /mz/api/alist/[pl-name]/m3u |
| | | * DELETE /mz/api/alist/[pl-name]/[nr] den Titel an der Position [nr] aus der Liste [pl-name] entfernen |
| | | * DELETE /mz/api/alist/[pl-name]/alle alle Titel aus der Liste [pl-name] entfernen |
| | | * |
| | |
| | | protected String get(HttpExchange e) { |
| | | String path = e.getRequestURI().toString(); |
| | | String[] elems = path.split(Server.SLASH); |
| | | String plname = elems[elems.length - 1]; |
| | | FileStorage fs = new FileStorage(conf); |
| | | String json = fs.readJson(FileStorage.ST_ABSPIELLISTE, plname); |
| | | return embedInCustomType(json, FileStorage.ST_ABSPIELLISTE); |
| | | if(elems.length > 5) { |
| | | if(elems[5].endsWith("m3u")) { |
| | | Headers headers = e.getResponseHeaders(); |
| | | headers.add("Content-Type", "application/m3u"); |
| | | return getM3u(e, elems[4]); |
| | | } else { |
| | | return "ungueltig"; |
| | | } |
| | | } else { |
| | | String plname = elems[elems.length - 1]; |
| | | FileStorage fs = new FileStorage(conf); |
| | | String json = fs.readJson(FileStorage.ST_ABSPIELLISTE, plname); |
| | | return embedInCustomType(json, FileStorage.ST_ABSPIELLISTE); |
| | | } |
| | | } |
| | | |
| | | private String getM3u(HttpExchange e, String plname) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | FileStorage fs = new FileStorage(conf); |
| | | Entity entity = fs.read(FileStorage.ST_ABSPIELLISTE, plname); |
| | | if (entity instanceof Abspielliste) { |
| | | Abspielliste liste = (Abspielliste) entity; |
| | | List<Titel> titelListe = liste.getTitel(); |
| | | |
| | | for(Titel titel : titelListe) { |
| | | |
| | | sb.append("http://hsrv:9090/tango"); |
| | | sb.append(titel.getKatalogUrl()); |
| | | sb.append(titel.getPfad()); |
| | | sb.append(titel.getName()); |
| | | sb.append("\n"); |
| | | } |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | @Override |