001package net.filebot.subtitle;
002
003import static java.util.Arrays.*;
004import static java.util.stream.Collectors.*;
005import static net.filebot.util.FileUtilities.*;
006
007import java.io.File;
008import java.util.List;
009
010import net.filebot.web.SubtitleDescriptor;
011
012public enum SubtitleNaming {
013
014        ORIGINAL {
015
016                @Override
017                public String format(File video, SubtitleDescriptor subtitle, String ext) {
018                        return subtitle.toFile().getName();
019                }
020
021                @Override
022                public String toString() {
023                        return "Keep Original";
024                }
025        },
026
027        MATCH_VIDEO {
028
029                @Override
030                public String format(File video, SubtitleDescriptor subtitle, String ext) {
031                        return SubtitleUtilities.formatSubtitle(getName(video), null, ext);
032                }
033
034                @Override
035                public String toString() {
036                        return "Match Video";
037                }
038        },
039
040        MATCH_VIDEO_ADD_LANGUAGE_TAG {
041
042                @Override
043                public String format(File video, SubtitleDescriptor subtitle, String ext) {
044                        return SubtitleUtilities.formatSubtitle(getName(video), subtitle.getLanguageName(), ext);
045                }
046
047                @Override
048                public String toString() {
049                        return "Match Video and Language";
050                }
051        };
052
053        public abstract String format(File video, SubtitleDescriptor subtitle, String ext);
054
055        public static List<String> names() {
056                return stream(values()).map(Enum::name).collect(toList());
057        }
058
059        public static SubtitleNaming forName(String name) {
060                for (SubtitleNaming naming : values()) {
061                        if (naming.name().equalsIgnoreCase(name)) {
062                                return naming;
063                        }
064                }
065
066                throw new IllegalArgumentException(String.format("%s not in %s", name, names()));
067        }
068
069}