|
|
@ -23,11 +23,17 @@ import org.libresonic.player.domain.Transcoding; |
|
|
|
import org.libresonic.player.service.TranscodingService; |
|
|
|
import org.libresonic.player.service.TranscodingService; |
|
|
|
import org.libresonic.player.service.SettingsService; |
|
|
|
import org.libresonic.player.service.SettingsService; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
|
|
|
|
import org.springframework.ui.Model; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.mvc.ParameterizableViewController; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
@ -36,43 +42,41 @@ import java.util.Map; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Sindre Mehus |
|
|
|
* @author Sindre Mehus |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class TranscodingSettingsController extends ParameterizableViewController { |
|
|
|
@Controller |
|
|
|
|
|
|
|
@RequestMapping("/transcodingSettings") |
|
|
|
|
|
|
|
public class TranscodingSettingsController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TranscodingService transcodingService; |
|
|
|
private TranscodingService transcodingService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SettingsService settingsService; |
|
|
|
private SettingsService settingsService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
public String doGet(Model model) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
|
|
|
|
|
|
|
|
if (isFormSubmission(request)) { |
|
|
|
|
|
|
|
handleParameters(request, map); |
|
|
|
|
|
|
|
map.put("toast", true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ModelAndView result = super.handleRequestInternal(request, response); |
|
|
|
|
|
|
|
map.put("transcodings", transcodingService.getAllTranscodings()); |
|
|
|
map.put("transcodings", transcodingService.getAllTranscodings()); |
|
|
|
map.put("transcodeDirectory", transcodingService.getTranscodeDirectory()); |
|
|
|
map.put("transcodeDirectory", transcodingService.getTranscodeDirectory()); |
|
|
|
map.put("downsampleCommand", settingsService.getDownsamplingCommand()); |
|
|
|
map.put("downsampleCommand", settingsService.getDownsamplingCommand()); |
|
|
|
map.put("hlsCommand", settingsService.getHlsCommand()); |
|
|
|
map.put("hlsCommand", settingsService.getHlsCommand()); |
|
|
|
map.put("brand", settingsService.getBrand()); |
|
|
|
map.put("brand", settingsService.getBrand()); |
|
|
|
|
|
|
|
|
|
|
|
result.addObject("model", map); |
|
|
|
model.addAttribute("model", map); |
|
|
|
return result; |
|
|
|
return "transcodingSettings"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@RequestMapping(method = RequestMethod.POST) |
|
|
|
* Determine if the given request represents a form submission. |
|
|
|
public String doPost(HttpServletRequest request, RedirectAttributes redirectAttributes) throws Exception { |
|
|
|
* |
|
|
|
String error = handleParameters(request, redirectAttributes); |
|
|
|
* @param request current HTTP request |
|
|
|
if(error != null) { |
|
|
|
* @return if the request represents a form submission |
|
|
|
redirectAttributes.addFlashAttribute("settings_toast", true); |
|
|
|
*/ |
|
|
|
} |
|
|
|
private boolean isFormSubmission(HttpServletRequest request) { |
|
|
|
redirectAttributes.addFlashAttribute("error", error); |
|
|
|
return "POST".equals(request.getMethod()); |
|
|
|
return "redirect:transcodingSettings.view"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void handleParameters(HttpServletRequest request, Map<String, Object> map) { |
|
|
|
private String handleParameters(HttpServletRequest request, RedirectAttributes redirectAttributes) { |
|
|
|
|
|
|
|
|
|
|
|
for (Transcoding transcoding : transcodingService.getAllTranscodings()) { |
|
|
|
for (Transcoding transcoding : transcodingService.getAllTranscodings()) { |
|
|
|
Integer id = transcoding.getId(); |
|
|
|
Integer id = transcoding.getId(); |
|
|
@ -86,13 +90,13 @@ public class TranscodingSettingsController extends ParameterizableViewController |
|
|
|
if (delete) { |
|
|
|
if (delete) { |
|
|
|
transcodingService.deleteTranscoding(id); |
|
|
|
transcodingService.deleteTranscoding(id); |
|
|
|
} else if (name == null) { |
|
|
|
} else if (name == null) { |
|
|
|
map.put("error", "transcodingsettings.noname"); |
|
|
|
return "transcodingsettings.noname"; |
|
|
|
} else if (sourceFormats == null) { |
|
|
|
} else if (sourceFormats == null) { |
|
|
|
map.put("error", "transcodingsettings.nosourceformat"); |
|
|
|
return "transcodingsettings.nosourceformat"; |
|
|
|
} else if (targetFormat == null) { |
|
|
|
} else if (targetFormat == null) { |
|
|
|
map.put("error", "transcodingsettings.notargetformat"); |
|
|
|
return "transcodingsettings.notargetformat"; |
|
|
|
} else if (step1 == null) { |
|
|
|
} else if (step1 == null) { |
|
|
|
map.put("error", "transcodingsettings.nostep1"); |
|
|
|
return "transcodingsettings.nostep1"; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
transcoding.setName(name); |
|
|
|
transcoding.setName(name); |
|
|
|
transcoding.setSourceFormats(sourceFormats); |
|
|
|
transcoding.setSourceFormats(sourceFormats); |
|
|
@ -112,35 +116,30 @@ public class TranscodingSettingsController extends ParameterizableViewController |
|
|
|
|
|
|
|
|
|
|
|
if (name != null || sourceFormats != null || targetFormat != null || step1 != null || step2 != null) { |
|
|
|
if (name != null || sourceFormats != null || targetFormat != null || step1 != null || step2 != null) { |
|
|
|
Transcoding transcoding = new Transcoding(null, name, sourceFormats, targetFormat, step1, step2, null, defaultActive); |
|
|
|
Transcoding transcoding = new Transcoding(null, name, sourceFormats, targetFormat, step1, step2, null, defaultActive); |
|
|
|
|
|
|
|
String error = null; |
|
|
|
if (name == null) { |
|
|
|
if (name == null) { |
|
|
|
map.put("error", "transcodingsettings.noname"); |
|
|
|
error = "transcodingsettings.noname"; |
|
|
|
} else if (sourceFormats == null) { |
|
|
|
} else if (sourceFormats == null) { |
|
|
|
map.put("error", "transcodingsettings.nosourceformat"); |
|
|
|
error = "transcodingsettings.nosourceformat"; |
|
|
|
} else if (targetFormat == null) { |
|
|
|
} else if (targetFormat == null) { |
|
|
|
map.put("error", "transcodingsettings.notargetformat"); |
|
|
|
error = "transcodingsettings.notargetformat"; |
|
|
|
} else if (step1 == null) { |
|
|
|
} else if (step1 == null) { |
|
|
|
map.put("error", "transcodingsettings.nostep1"); |
|
|
|
error = "transcodingsettings.nostep1"; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
transcodingService.createTranscoding(transcoding); |
|
|
|
transcodingService.createTranscoding(transcoding); |
|
|
|
} |
|
|
|
} |
|
|
|
if (map.containsKey("error")) { |
|
|
|
if(error != null) { |
|
|
|
map.put("newTranscoding", transcoding); |
|
|
|
redirectAttributes.addAttribute("newTranscoding", transcoding); |
|
|
|
|
|
|
|
return error; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
settingsService.setDownsamplingCommand(StringUtils.trim(request.getParameter("downsampleCommand"))); |
|
|
|
settingsService.setDownsamplingCommand(StringUtils.trim(request.getParameter("downsampleCommand"))); |
|
|
|
settingsService.setHlsCommand(StringUtils.trim(request.getParameter("hlsCommand"))); |
|
|
|
settingsService.setHlsCommand(StringUtils.trim(request.getParameter("hlsCommand"))); |
|
|
|
settingsService.save(); |
|
|
|
settingsService.save(); |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getParameter(HttpServletRequest request, String name, Integer id) { |
|
|
|
private String getParameter(HttpServletRequest request, String name, Integer id) { |
|
|
|
return StringUtils.trimToNull(request.getParameter(name + "[" + id + "]")); |
|
|
|
return StringUtils.trimToNull(request.getParameter(name + "[" + id + "]")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setTranscodingService(TranscodingService transcodingService) { |
|
|
|
|
|
|
|
this.transcodingService = transcodingService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setSettingsService(SettingsService settingsService) { |
|
|
|
|
|
|
|
this.settingsService = settingsService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|