Skip to content
Snippets Groups Projects
Commit 080c4dbe authored by srosse's avatar srosse
Browse files

Merge with 6d47b63173a3b5951d1f537790b5ec37bcc2dec0

parents 943a0e67 9bf3de2f
No related branches found
No related tags found
No related merge requests found
......@@ -99,8 +99,30 @@ public class MovieServiceImpl implements MovieService, ThumbnailSPI {
FileChannelWrapper in = new FileChannelWrapper(ch);
MP4Demuxer demuxer1 = new MP4Demuxer(in);
org.jcodec.common.model.Size size = demuxer1.getMovie().getDisplaySize();
// Case 1: standard case, get dimension from movie
int w = size.getWidth();
int h = size.getHeight();
// Case 2: landscape movie from iOS: width and height is negative, no dunny why
if (w < 0 && h < 0) {
w = 0 - w;
h = 0 - h;
}
if (w == 0) {
// Case 3: portrait movie from iOS: movie dimensions are not set, but there
// something in the track box.
try {
// This code is the way it is just because I don't know
// how to safely read the rotation/portrait/landscape
// flag of the movie. Those mp4 guys are really
// secretive folks, did not find any documentation about
// this. Best guess.
org.jcodec.common.model.Size size2 = demuxer1.getVideoTrack().getBox().getCodedSize();
w = size2.getHeight();
h = size2.getWidth();
} catch(Exception e) {
log.debug("can not get size from box " + e.getMessage());
}
}
return new Size(w, h, false);
} catch (Exception | AssertionError e) {
log.error("Cannot extract size of: " + media, e);
......
......@@ -135,6 +135,15 @@ public interface FileElement extends FormMultipartItem {
*/
public String getUploadFileName();
/**
* Set the filename of the uploaded file. Use this if you want the final filename
* to be something different than file name from the upload. Whenever a file is
* uploaded again, this name is replaced again by the browser provided upload file name
*
* @param the uploaded file name
*/
public void setUploadFileName(String uploadFileName);
/**
* The mime type is first looked up by servletContext.getMimeType(). If no
* mime type is available, the browser supplied mime type is used.
......
......@@ -464,6 +464,12 @@ public class FileElementImpl extends FormItemImpl
public String getUploadFileName() {
return uploadFilename;
}
@Override
public void setUploadFileName(String uploadFileName) {
this.uploadFilename = uploadFileName;
this.uploadMimeType = WebappHelper.getMimeType(uploadFilename);
}
/**
* @see org.olat.core.gui.components.form.flexible.elements.FileElement#getUploadMimeType()
......
......@@ -22,6 +22,8 @@ package org.olat.modules.webFeed.ui.podcast;
import java.io.File;
import java.util.Date;
import org.olat.core.commons.services.image.Size;
import org.olat.core.commons.services.video.MovieService;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.components.form.flexible.FormItemContainer;
......@@ -42,12 +44,15 @@ import org.olat.core.util.FileUtils;
import org.olat.core.util.Formatter;
import org.olat.core.util.StringHelper;
import org.olat.core.util.WebappHelper;
import org.olat.core.util.vfs.LocalFileImpl;
import org.olat.core.util.vfs.Quota;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback;
import org.olat.modules.webFeed.managers.FeedManager;
import org.olat.modules.webFeed.models.Feed;
import org.olat.modules.webFeed.models.Item;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Provides a form for editing episode data (title, description, file ...)
......@@ -75,6 +80,9 @@ public class EpisodeFormController extends FormBasicController {
private FileElement file;
private FormLink cancelButton;
@Autowired
private MovieService movieService;
/**
* @param ureq
* @param control
......@@ -151,8 +159,23 @@ public class EpisodeFormController extends FormBasicController {
file.clearError();
if (file.isUploadSuccess()) {
String newFilename = file.getUploadFileName();
boolean isValidFileType = newFilename.toLowerCase().matches(MIME_TYPES_ALLOWED);
String newFilename = file.getUploadFileName().toLowerCase();
VFSLeaf movie = new LocalFileImpl(file.getUploadFile());
// remove spaces
newFilename = newFilename.replaceAll(" ", "_");
file.setUploadFileName(newFilename);
if (newFilename.endsWith("mov") || newFilename.endsWith("m4v")) {
// Check if it actually is a mp4 file, if so rename file to
// mp4 to make later processes work smoothly. MOV is used
// when uploading a video from an iOS device.
if (movieService.isMP4(movie, newFilename)) {
newFilename = newFilename.substring(0, newFilename.length() - 3) + "mp4";
file.setUploadFileName(newFilename);
}
}
boolean isValidFileType = newFilename.matches(MIME_TYPES_ALLOWED);
boolean isFilenameValid = validateFilename(newFilename);
if (!isValidFileType || !isFilenameValid) {
if(!isValidFileType) {
......@@ -160,6 +183,17 @@ public class EpisodeFormController extends FormBasicController {
} else if (!isFilenameValid) {
file.setErrorKey("podcastfile.name.notvalid", null);
}
} else {
// try to autodetect width and height for movies, prefill for user if possible
Size size = movieService.getSize(movie, FileUtils.getFileSuffix(newFilename));
if (size != null) {
if (size.getWidth() > 1) {
widthEl.setValue(size.getWidth() + "");
}
if (size.getHeight() > 1) {
heightEl.setValue(size.getHeight() + "");
}
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment