Search in sources :

Example 6 with FileFinder

use of org.fagu.fmv.utils.file.FileFinder in project fmv by f-agu.

the class Bootstrap method findMovie.

// ---------------------------------------------------
/**
 */
private MovieFinder findMovie(File saveFile, File... srcFiles) throws IOException {
    MovieFinder movieFinder = new MovieFinder(saveFile);
    movieFinder.addInfoFile(new VolumeInfoFile());
    movieFinder.addListener(new FileFinderListener<Movie>() {

        private int count;

        /**
         * @see org.fagu.fmv.utils.file.FileFinderListener#eventFindPre(org.fagu.fmv.utils.file.FileFinder.FileFound)
         */
        @Override
        public void eventFindPre(FileFound fileFound) {
            System.out.println(count + ": " + fileFound.getFileFound().getName());
            ++count;
        }

        /**
         * @see org.fagu.fmv.utils.file.FileFinderListener#eventFindPost(FileFound, java.lang.Object)
         */
        @Override
        public void eventFindPost(FileFound fileFound, FileFinder<Movie>.InfosFile infosFile) {
            Movie movie = infosFile.getMain();
            MovieMetadatas videoMetadatas = movie.getMetadatas();
            // Format format = videoMetadatas.getFormat();
            VideoStream videoStream = videoMetadatas.getVideoStream();
            Rotation rotate = videoStream.rotate();
            // System.out.println(count + ": " + file.getName() + " " + infos); // .getFormat().creationDate()
            System.out.println("   " + rotate + ", " + videoStream.handlerName());
        }
    });
    for (File srcFile : srcFiles) {
        movieFinder.find(srcFile);
    }
    return movieFinder;
}
Also used : VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) FileFinder(org.fagu.fmv.utils.file.FileFinder) Rotation(org.fagu.fmv.utils.media.Rotation) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) MovieFinder(org.fagu.fmv.mymedia.file.MovieFinder) FileFound(org.fagu.fmv.utils.file.FileFinder.FileFound) File(java.io.File)

Example 7 with FileFinder

use of org.fagu.fmv.utils.file.FileFinder in project fmv by f-agu.

the class ByDayAndIndexClassifier method classify.

/**
 * @see org.fagu.fmv.mymedia.classify.movie.image.mymedia.Classifier#classify()
 */
@Override
public List<File> classify(Converter<Movie> converter, ConverterListener<Movie> listener) throws IOException {
    List<File> files = new ArrayList<>(100);
    for (Entry<String, SortedSet<FileFinder<Movie>.InfosFile>> entry : map.entrySet()) {
        int index = 0;
        for (FileFinder<Movie>.InfosFile infosFile : entry.getValue()) {
            Movie movie = infosFile.getMain();
            String extension = FilenameUtils.getExtension(movie.getFile().getName());
            StringBuilder buf = new StringBuilder();
            buf.append(entry.getKey()).append(" (");
            buf.append(StringUtils.leftPad(Integer.toString(++index), 2, '0')).append(") .");
            buf.append(converter.getFormat(extension));
            File destFile = new File(destFolder, buf.toString());
            converter.convert(movie, infosFile, destFile, listener);
            files.add(destFile);
        }
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) FileFinder(org.fagu.fmv.utils.file.FileFinder) File(java.io.File) SortedSet(java.util.SortedSet) MapSortedSet(org.fagu.fmv.utils.collection.MapSortedSet)

Example 8 with FileFinder

use of org.fagu.fmv.utils.file.FileFinder in project fmv by f-agu.

the class TimeOffsetImageComparatorTestCase method testEmpty.

/**
 */
@Test
public void testEmpty() {
    TimeOffsetImageComparator comparator = new TimeOffsetImageComparator();
    FileFinder<Image>.InfosFile image1 = mockImage(1, "1");
    FileFinder<Image>.InfosFile image2 = mockImage(2, "2");
    FileFinder<Image>.InfosFile image1b = mockImage(1, "1b");
    assertEquals(-1, comparator.compare(image1, image2));
    assertEquals(1, comparator.compare(image2, image1));
    assertEquals(1, comparator.compare(image1b, image1));
}
Also used : TimeOffsetImageComparator(org.fagu.fmv.mymedia.classify.image.TimeOffsetImageComparator) FileFinder(org.fagu.fmv.utils.file.FileFinder) Test(org.junit.Test)

Example 9 with FileFinder

use of org.fagu.fmv.utils.file.FileFinder in project fmv by f-agu.

the class ByDayAndIndexClassifier method classify.

/**
 * @see org.fagu.fmv.mymedia.classify.Classifier#classify(org.fagu.fmv.mymedia.classify.Converter)
 */
@Override
public List<File> classify(Converter<Media> converter, ConverterListener<Media> listener) throws IOException {
    List<File> files = new ArrayList<>(100);
    int idxLen = 1 + (int) Math.log10(map.sizeValues());
    int index = 0;
    for (Entry<String, SortedSet<FileFinder<Media>.InfosFile>> entry : map.entrySet()) {
        File curFolder = new File(destFolder, entry.getKey());
        if (!curFolder.exists()) {
            curFolder.mkdirs();
        }
        for (FileFinder<Media>.InfosFile infosFile : entry.getValue()) {
            Media media = infosFile.getMain();
            File srcFile = media.getFile();
            StringBuilder buf = new StringBuilder();
            buf.append(StringUtils.leftPad(Integer.toString(++index), idxLen, '0')).append('.');
            buf.append(FilenameUtils.getExtension(srcFile.getName()).toLowerCase());
            File destFile = new File(curFolder, buf.toString());
            converter.convert(media, infosFile, destFile, listener);
            files.add(destFile);
        }
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) Media(org.fagu.fmv.media.Media) FileFinder(org.fagu.fmv.utils.file.FileFinder) File(java.io.File) SortedSet(java.util.SortedSet) MapSortedSet(org.fagu.fmv.utils.collection.MapSortedSet)

Example 10 with FileFinder

use of org.fagu.fmv.utils.file.FileFinder in project fmv by f-agu.

the class FindDiffTime method main.

/**
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    ImageFinder imagesFinder = Sources.load(new File("C:\\tmp\\july\\save"));
    for (FileFinder<Image>.InfosFile infosFile : imagesFinder.getAll()) {
        Image image = infosFile.getMain();
        File file = image.getFile();
        System.out.println(file.getParentFile().getName() + "/" + file.getName() + " : " + DATE_FORMAT.format(new Date(image.getTime())));
        if ("GOPR0698.JPG".equals(file.getName())) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(2014, Calendar.JULY, 10, 15, 30, 0);
            System.out.println("############### " + (image.getTime() - calendar.getTimeInMillis()));
        }
    }
}
Also used : ImageFinder(org.fagu.fmv.mymedia.file.ImageFinder) Calendar(java.util.Calendar) FileFinder(org.fagu.fmv.utils.file.FileFinder) Image(org.fagu.fmv.im.Image) File(java.io.File) Date(java.util.Date)

Aggregations

FileFinder (org.fagu.fmv.utils.file.FileFinder)10 File (java.io.File)8 ArrayList (java.util.ArrayList)3 SortedSet (java.util.SortedSet)3 Image (org.fagu.fmv.im.Image)3 MapSortedSet (org.fagu.fmv.utils.collection.MapSortedSet)3 IOException (java.io.IOException)2 Date (java.util.Date)2 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)2 TimeOffsetImageComparator (org.fagu.fmv.mymedia.classify.image.TimeOffsetImageComparator)2 InfosFile (org.fagu.fmv.utils.file.FileFinder.InfosFile)2 Rotation (org.fagu.fmv.utils.media.Rotation)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 PrintStream (java.io.PrintStream)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1