Skip to content

Commit

Permalink
change: update dependencies on class implementing old Format enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ptylczynski committed Dec 20, 2021
1 parent 1af8cfb commit ef7db24
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cloud.ptl.povserver.data.repositories;


import cloud.ptl.povserver.data.model.Format;
import cloud.ptl.povserver.data.model.ResourceDAO;
import cloud.ptl.povserver.ffmpeg.convert.ConvertRequest;
import org.springframework.data.repository.CrudRepository;

import java.io.File;
Expand All @@ -19,13 +19,13 @@ public interface ResourceRepository extends CrudRepository<ResourceDAO, Long> {

Optional<ResourceDAO> findByMovie(File file);

Optional<ResourceDAO> findByTitleAndFormat(String title, ConvertRequest.Format format);
Optional<ResourceDAO> findByTitleAndFormat(String title, Format format);

List<ResourceDAO> findAllByTitleContaining(String title);

List<ResourceDAO> findAllByTitleContainingAndFormat(String title, ConvertRequest.Format format);
List<ResourceDAO> findAllByTitleContainingAndFormat(String title, Format format);

Collection<ResourceDAO> findAllByFormatEquals(ConvertRequest.Format format);
Collection<ResourceDAO> findAllByFormatEquals(Format format);

boolean existsByTitleAndFormat(String title, ConvertRequest.Format format);
boolean existsByTitleAndFormat(String title, Format format);
}
9 changes: 5 additions & 4 deletions src/main/java/cloud/ptl/povserver/ffmpeg/FfmpegMediator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// ffmpeg -i 'I made Brett do this....webm' -s 1280x720 -vcodec libx265 'I made Brett do this...1280x720.mp4'

import cloud.ptl.povserver.data.model.Format;
import cloud.ptl.povserver.data.model.ResourceDAO;
import cloud.ptl.povserver.ffmpeg.convert.ConvertRequest;
import cloud.ptl.povserver.ffmpeg.convert.FormatConverter;
Expand Down Expand Up @@ -41,10 +42,10 @@ public ResourceDAO convert(ConvertRequest convertRequest) throws IOException, In
return this.formatConverter.convert(convertRequest);
}

public static ConvertRequest.Format findFormat(String locator) {
if (locator.endsWith(".gif")) return ConvertRequest.Format.GIF;
else if (locator.endsWith(".mp4")) return ConvertRequest.Format.MP4;
else if (locator.endsWith(".webm")) return ConvertRequest.Format.WEBM;
public static Format findFormat(String locator) {
if (locator.endsWith(".gif")) return Format.GIF;
else if (locator.endsWith(".mp4")) return Format.MP4;
else if (locator.endsWith(".webm")) return Format.WEBM;
else throw new IllegalArgumentException(
String.format(
"Unrecognized file format: %s",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cloud.ptl.povserver.ffmpeg.convert;

import cloud.ptl.povserver.data.model.Format;
import cloud.ptl.povserver.data.model.ResolutionDAO;
import cloud.ptl.povserver.data.model.ResourceDAO;
import cloud.ptl.povserver.service.resource.ResolutionService;
Expand Down Expand Up @@ -30,8 +31,8 @@ public GifToWebMConverter(ResolutionService resolutionService, ResourceService r
}

@Override
public boolean supports(ConvertRequest.Format format) {
return ConvertRequest.Format.GIF.equals(format);
public boolean supports(Format format) {
return Format.GIF.equals(format);
}

@Override
Expand All @@ -50,7 +51,7 @@ public ResourceDAO convert(ConvertRequest convertRequest) throws IOException, In
convertRequest.getDestinationFolder().getAbsolutePath() + File.separator + convertRequest.getFileToConvert().getName() + ".mp4"
)
);
newResourceDAO.setFormat(ConvertRequest.Format.MP4);
newResourceDAO.setFormat(Format.MP4);
newResourceDAO.setTitle(convertRequest.getFileToConvert().getName());
return this.resourceService.save(newResourceDAO);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cloud.ptl.povserver.ffmpeg.convert;

import cloud.ptl.povserver.data.model.Format;
import cloud.ptl.povserver.data.model.ResourceDAO;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -9,7 +10,7 @@

@Slf4j
public abstract class ResourceConverter {
public abstract boolean supports(ConvertRequest.Format format);
public abstract boolean supports(Format format);

public abstract ResourceDAO convert(ConvertRequest convertRequest) throws IOException, InterruptedException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cloud.ptl.povserver.ffmpeg.convert;

import cloud.ptl.povserver.data.model.Format;
import cloud.ptl.povserver.data.model.ResourceDAO;
import cloud.ptl.povserver.exception.NotFoundException;
import cloud.ptl.povserver.service.resource.ResolutionService;
Expand All @@ -26,8 +27,8 @@ public WebmToMp4Converter(ResolutionService resolutionService, ResourceService r
}

@Override
public boolean supports(ConvertRequest.Format format) {
return format.equals(ConvertRequest.Format.WEBM);
public boolean supports(Format format) {
return format.equals(Format.WEBM);
}

@Override
Expand All @@ -52,7 +53,7 @@ public ResourceDAO convert(ConvertRequest convertRequest) throws IOException, In
resourceDAO.getThumbnailUrls().forEach(el -> newResourceDAO.getThumbnailUrls().add(el));
// newResourceDAO.setThumbnailUrls(resourceDAO.getThumbnailUrls());
newResourceDAO.setIsMovie(true);
newResourceDAO.setFormat(ConvertRequest.Format.MP4);
newResourceDAO.setFormat(Format.MP4);
return this.resourceService.save(newResourceDAO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private ResourceDAO saveWebM(VideoInfo videoInfo, File file, String link) {
resourceDAO.setTitle(videoInfo.details().title());
resourceDAO.setResolutions(new ArrayList<>());
resourceDAO.setDownloadUrl(link);
resourceDAO.setFormat(ConvertRequest.Format.WEBM);
resourceDAO.setFormat(cloud.ptl.povserver.data.model.Format.WEBM);
ResolutionDAO resolutionDAO = new ResolutionDAO();
resolutionDAO.setWidth(videoInfo.bestVideoFormat().width());
resolutionDAO.setHeight(videoInfo.bestVideoFormat().height());
Expand All @@ -157,7 +157,7 @@ private ResourceDAO saveWebM(VideoInfo videoInfo, File file, String link) {

private ResourceDAO convertMp4(ResourceDAO resourceDAO) {
ConvertRequest convertRequest = new ConvertRequest();
convertRequest.setSourceFormat(ConvertRequest.Format.WEBM);
convertRequest.setSourceFormat(cloud.ptl.povserver.data.model.Format.WEBM);
convertRequest.setFileToConvert(resourceDAO.getMovie());
convertRequest.setDestinationFolder(this.youtubeDownloadDir);
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package cloud.ptl.povserver.service.resource;

import cloud.ptl.povserver.data.model.Format;
import cloud.ptl.povserver.data.model.ResourceDAO;
import cloud.ptl.povserver.data.repositories.ResourceRepository;
import cloud.ptl.povserver.exception.NotFoundException;
import cloud.ptl.povserver.ffmpeg.convert.ConvertRequest;
import cloud.ptl.povserver.service.frame.PovFrameRequest;
import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.*;
import java.util.stream.IntStream;

import static cloud.ptl.povserver.ffmpeg.convert.ConvertRequest.Format.FRAMES;

/**
* Everything we store in system is resource. It can be gif, picture or movie.
* This resource is used to manage resource entity
Expand All @@ -30,16 +29,16 @@ public Collection<ResourceDAO> findAllResources() {
}

public Collection<ResourceDAO> findAllMP4Resources() {
return this.resourceRepository.findAllByFormatEquals(ConvertRequest.Format.MP4);
return this.resourceRepository.findAllByFormatEquals(Format.MP4);
}

public boolean existsByTitleAndIsFrames(String title) {
return this.resourceRepository.existsByTitleAndFormat(title, FRAMES);
return this.resourceRepository.existsByTitleAndFormat(title, Format.FRAMES);
}

public ResourceDAO findByTitleAndIsFrames(String title) throws NotFoundException {
return this.resourceRepository
.findByTitleAndFormat(title, FRAMES)
.findByTitleAndFormat(title, Format.FRAMES)
.orElseThrow(() -> new NotFoundException("Cannot find resource with title " + title));
}

Expand Down Expand Up @@ -92,7 +91,7 @@ public List<ResourceDAO> findAllByTitleContaining(String title) {
}

public List<ResourceDAO> findAllByTitleContainingAndIsFrameStream(String title) {
return this.resourceRepository.findAllByTitleContainingAndFormat(title, FRAMES);
return this.resourceRepository.findAllByTitleContainingAndFormat(title, Format.FRAMES);
}

public boolean existByDownloadUrl(String donwloadUrl) {
Expand Down Expand Up @@ -169,4 +168,30 @@ public void deleteRelatedTo(ResourceDAO resourceDAO) {
else el.getFrameStream().delete();
});
}

public ResourceDAO markAsConversionStarted(ResourceDAO resourceDAO) {
resourceDAO.setConversionOngoing(true);
return this.resourceRepository.save(resourceDAO);
}

public void markAsConversionStarted(PovFrameRequest request) {
request.setResourceDAO(
this.markAsConversionStarted(
request.getResourceDAO()
)
);
}

public ResourceDAO markAsConversionEnded(ResourceDAO resourceDAO) {
resourceDAO.setConversionOngoing(false);
return this.resourceRepository.save(resourceDAO);
}

public void markAsConversionEnded(PovFrameRequest request) {
request.setResourceDAO(
this.markAsConversionEnded(
request.getResourceDAO()
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cloud.ptl.povserver.data.frame.PovFrame;
import cloud.ptl.povserver.data.model.ResourceDAO;
import cloud.ptl.povserver.exception.ConversionOngoingException;
import cloud.ptl.povserver.exception.NotFoundException;
import cloud.ptl.povserver.service.frame.FrameService;
import cloud.ptl.povserver.service.frame.PovFrameRequest;
Expand Down Expand Up @@ -33,7 +34,7 @@ public FrameStreamService(FrameService frameParseService, ResourceService resour
this.resourceService = resourceService;
}

public Region getVideoRegion(Long videoId, int height, int width, int sampleInterval, int start, Integer end, String ledStrip) throws IOException, NotFoundException, InterruptedException {
public Region getVideoRegion(Long videoId, int height, int width, int sampleInterval, int start, Integer end, String ledStrip) throws IOException, NotFoundException, InterruptedException, ConversionOngoingException {
ResourceDAO requestedResource = this.resourceService.findById(videoId);
PovFrameRequest povFrameRequest = new PovFrameRequest();
povFrameRequest.setHeight(height);
Expand Down

0 comments on commit ef7db24

Please sign in to comment.