1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00

+ Support episode SortOrder

This commit is contained in:
Reinhard Pointner 2012-02-13 09:54:57 +00:00
parent 05417b1b39
commit f2e07377ef
28 changed files with 277 additions and 337 deletions

View File

@ -28,6 +28,9 @@ public class ArgumentBean {
@Option(name = "--db", usage = "Episode/Movie database", metaVar = "[TVRage, AniDB, TheTVDB] or [OpenSubtitles, TheMovieDB]")
public String db;
@Option(name = "--order", usage = "Episode order", metaVar = "[Default, Absolute, DVD]")
public String order = "Airdate";
@Option(name = "--format", usage = "Episode naming scheme", metaVar = "expression")
public String format;

View File

@ -43,7 +43,7 @@ public class ArgumentProcessor {
try {
// print episode info
if (args.list) {
for (String eps : cli.fetchEpisodeList(args.query, args.format, args.db, args.lang)) {
for (String eps : cli.fetchEpisodeList(args.query, args.format, args.db, args.order, args.lang)) {
System.out.println(eps);
}
return 0;
@ -69,7 +69,7 @@ public class ArgumentProcessor {
}
if (args.rename) {
cli.rename(files, args.query, args.format, args.db, args.lang, !args.nonStrict);
cli.rename(files, args.query, args.format, args.db, args.order, args.lang, !args.nonStrict);
}
if (args.check) {

View File

@ -9,7 +9,7 @@ import java.util.List;
public interface CmdlineInterface {
List<File> rename(Collection<File> files, String query, String format, String db, String lang, boolean strict) throws Exception;
List<File> rename(Collection<File> files, String query, String format, String db, String sortOrder, String lang, boolean strict) throws Exception;
List<File> getSubtitles(Collection<File> files, String query, String lang, String output, String encoding, boolean strict) throws Exception;
@ -24,7 +24,7 @@ public interface CmdlineInterface {
File compute(Collection<File> files, String output, String encoding) throws Exception;
List<String> fetchEpisodeList(String query, String format, String db, String lang) throws Exception;
List<String> fetchEpisodeList(String query, String format, String db, String sortOrder, String lang) throws Exception;
String getMediaInfo(File file, String format) throws Exception;

View File

@ -66,6 +66,7 @@ import net.sourceforge.filebot.web.Movie;
import net.sourceforge.filebot.web.MovieIdentificationService;
import net.sourceforge.filebot.web.MoviePart;
import net.sourceforge.filebot.web.SearchResult;
import net.sourceforge.filebot.web.SortOrder;
import net.sourceforge.filebot.web.SubtitleDescriptor;
import net.sourceforge.filebot.web.SubtitleProvider;
import net.sourceforge.filebot.web.VideoHashSubtitleService;
@ -74,7 +75,7 @@ import net.sourceforge.filebot.web.VideoHashSubtitleService;
public class CmdlineOperations implements CmdlineInterface {
@Override
public List<File> rename(Collection<File> files, String query, String expression, String db, String languageName, boolean strict) throws Exception {
public List<File> rename(Collection<File> files, String query, String expression, String db, String sortOrder, String languageName, boolean strict) throws Exception {
ExpressionFormat format = (expression != null) ? new ExpressionFormat(expression) : null;
Locale locale = getLanguage(languageName).toLocale();
@ -85,7 +86,7 @@ public class CmdlineOperations implements CmdlineInterface {
if (getEpisodeListProvider(db) != null) {
// tv series mode
return renameSeries(files, query, format, getEpisodeListProvider(db), locale, strict);
return renameSeries(files, query, format, getEpisodeListProvider(db), SortOrder.forName(sortOrder), locale, strict);
}
if (getMovieIdentificationService(db) != null) {
@ -121,14 +122,14 @@ public class CmdlineOperations implements CmdlineInterface {
CLILogger.finest(format("Filename pattern: [%.02f] SxE, [%.02f] CWS", sxe / max, cws / max));
if (sxe >= (max * 0.65) || cws >= (max * 0.65)) {
return renameSeries(files, query, format, getEpisodeListProviders()[0], locale, strict); // use default episode db
return renameSeries(files, query, format, getEpisodeListProviders()[0], SortOrder.forName(sortOrder), locale, strict); // use default episode db
} else {
return renameMovie(files, query, format, getMovieIdentificationServices()[0], locale, strict); // use default movie db
}
}
public List<File> renameSeries(Collection<File> files, String query, ExpressionFormat format, EpisodeListProvider db, Locale locale, boolean strict) throws Exception {
public List<File> renameSeries(Collection<File> files, String query, ExpressionFormat format, EpisodeListProvider db, SortOrder sortOrder, Locale locale, boolean strict) throws Exception {
CLILogger.config(format("Rename episodes using [%s]", db.getName()));
List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES);
@ -153,7 +154,7 @@ public class CmdlineOperations implements CmdlineInterface {
Collection<String> seriesNames = (query == null) ? detectQuery(batch, locale, strict) : singleton(query);
// fetch episode data
Set<Episode> episodes = fetchEpisodeSet(db, seriesNames, locale, strict);
Set<Episode> episodes = fetchEpisodeSet(db, seriesNames, sortOrder, locale, strict);
if (episodes.size() > 0) {
matches.addAll(matchEpisodes(filter(mediaFiles, VIDEO_FILES), episodes, sequence));
@ -204,7 +205,7 @@ public class CmdlineOperations implements CmdlineInterface {
}
private Set<Episode> fetchEpisodeSet(final EpisodeListProvider db, final Collection<String> names, final Locale locale, final boolean strict) throws Exception {
private Set<Episode> fetchEpisodeSet(final EpisodeListProvider db, final Collection<String> names, final SortOrder sortOrder, final Locale locale, final boolean strict) throws Exception {
List<Callable<List<Episode>>> tasks = new ArrayList<Callable<List<Episode>>>();
// detect series names and create episode list fetch tasks
@ -223,7 +224,7 @@ public class CmdlineOperations implements CmdlineInterface {
List<Episode> episodes = new ArrayList<Episode>();
for (SearchResult it : selectedSearchResults) {
CLILogger.fine(format("Fetching episode data for [%s]", it.getName()));
episodes.addAll(db.getEpisodeList(it, locale));
episodes.addAll(db.getEpisodeList(it, sortOrder, locale));
Analytics.trackEvent(db.getName(), "FetchEpisodeList", it.getName());
}
@ -862,16 +863,17 @@ public class CmdlineOperations implements CmdlineInterface {
@Override
public List<String> fetchEpisodeList(String query, String expression, String db, String languageName) throws Exception {
public List<String> fetchEpisodeList(String query, String expression, String db, String sortOrderName, String languageName) throws Exception {
// find series on the web and fetch episode list
ExpressionFormat format = (expression != null) ? new ExpressionFormat(expression) : null;
EpisodeListProvider service = (db == null) ? TVRage : getEpisodeListProvider(db);
SortOrder sortOrder = SortOrder.forName(sortOrderName);
Locale locale = getLanguage(languageName).toLocale();
SearchResult hit = selectSearchResult(query, service.search(query, locale), false).get(0);
List<String> episodes = new ArrayList<String>();
for (Episode it : service.getEpisodeList(hit, locale)) {
for (Episode it : service.getEpisodeList(hit, sortOrder, locale)) {
String name = (format != null) ? format.format(new MediaBindingBean(it, null)) : EpisodeFormat.SeasonEpisode.format(it);
episodes.add(name);
}

View File

@ -183,7 +183,7 @@ List.metaClass.sortBySimilarity = { prime, Closure toStringFunction = { obj -> o
// CLI bindings
def rename(args) { args = _defaults(args)
synchronized (_cli) {
_guarded { _cli.rename(_files(args), args.query, args.format, args.db, args.lang, args.strict) }
_guarded { _cli.rename(_files(args), args.query, args.format, args.db, args.order, args.lang, args.strict) }
}
}
@ -213,7 +213,7 @@ def compute(args) { args = _defaults(args)
def fetchEpisodeList(args) { args = _defaults(args)
synchronized (_cli) {
_guarded { _cli.fetchEpisodeList(args.query, args.format, args.db, args.lang) }
_guarded { _cli.fetchEpisodeList(args.query, args.format, args.db, args.order, args.lang) }
}
}
@ -244,6 +244,7 @@ def _defaults(args) {
args.query = args.query ?: _args.query
args.format = args.format ?: _args.format
args.db = args.db ?: _args.db
args.order = args.order ?: _args.order
args.lang = args.lang ?: _args.lang
args.output = args.output ?: _args.output
args.encoding = args.encoding ?: _args.encoding

View File

@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.episodelist;
import static net.sourceforge.filebot.ui.episodelist.SeasonSpinnerModel.*;
import static net.sourceforge.filebot.web.EpisodeUtilities.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
@ -21,6 +22,7 @@ import java.util.Locale;
import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JSpinner;
import javax.swing.KeyStroke;
@ -43,6 +45,8 @@ import net.sourceforge.filebot.ui.transfer.SaveAction;
import net.sourceforge.filebot.web.Episode;
import net.sourceforge.filebot.web.EpisodeListProvider;
import net.sourceforge.filebot.web.SearchResult;
import net.sourceforge.filebot.web.SeasonOutOfBoundsException;
import net.sourceforge.filebot.web.SortOrder;
import net.sourceforge.tuned.StringUtilities;
import net.sourceforge.tuned.ui.LabelProvider;
import net.sourceforge.tuned.ui.SelectButton;
@ -54,6 +58,7 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
private SeasonSpinnerModel seasonSpinnerModel = new SeasonSpinnerModel();
private LanguageComboBox languageComboBox = new LanguageComboBox(this, Language.getLanguage("en"));
private JComboBox sortOrderComboBox = new JComboBox(SortOrder.values());
public EpisodeListPanel() {
@ -67,8 +72,9 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
seasonSpinner.setMinimumSize(seasonSpinner.getPreferredSize());
// add after text field
add(seasonSpinner, "gap indent", 1);
add(languageComboBox, "gap indent+5", 2);
add(seasonSpinner, "sgy combo, gap indent", 1);
add(sortOrderComboBox, "sgy combo, gap rel", 2);
add(languageComboBox, "sgy combo, gap indent+5", 3);
// add after tabbed pane
tabbedPaneGroup.add(new JButton(new SaveAction(new SelectedTabExportHandler())));
@ -103,9 +109,10 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
EpisodeListProvider provider = searchTextField.getSelectButton().getSelectedValue();
String text = searchTextField.getText().trim();
int season = seasonSpinnerModel.getSeason();
SortOrder order = (SortOrder) sortOrderComboBox.getSelectedItem();
Locale language = languageComboBox.getModel().getSelectedItem().toLocale();
return new EpisodeListRequestProcessor(new EpisodeListRequest(provider, text, season, language));
return new EpisodeListRequestProcessor(new EpisodeListRequest(provider, text, season, order, language));
};
@ -182,32 +189,19 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
protected static class EpisodeListRequest extends Request {
private final EpisodeListProvider provider;
private final int season;
private final Locale language;
public final EpisodeListProvider provider;
public final int season;
public final SortOrder order;
public final Locale language;
public EpisodeListRequest(EpisodeListProvider provider, String searchText, int season, Locale language) {
public EpisodeListRequest(EpisodeListProvider provider, String searchText, int season, SortOrder order, Locale language) {
super(searchText);
this.provider = provider;
this.season = season;
this.order = order;
this.language = language;
}
public EpisodeListProvider getProvider() {
return provider;
}
public int getSeason() {
return season;
}
public Locale getLanguage() {
return language;
}
}
@ -220,31 +214,30 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
@Override
public Collection<SearchResult> search() throws Exception {
return request.getProvider().search(request.getSearchText(), request.getLanguage());
return request.provider.search(request.getSearchText(), request.language);
}
@Override
public Collection<Episode> fetch() throws Exception {
List<Episode> episodes;
List<Episode> episodes = request.provider.getEpisodeList(getSearchResult(), request.order, request.language);
if (request.getSeason() != ALL_SEASONS)
episodes = request.getProvider().getEpisodeList(getSearchResult(), request.getSeason(), request.getLanguage());
else
episodes = request.getProvider().getEpisodeList(getSearchResult(), request.getLanguage());
if (request.season != ALL_SEASONS) {
List<Episode> episodeForSeason = filterBySeason(episodes, request.season);
if (episodeForSeason.isEmpty()) {
throw new SeasonOutOfBoundsException(getSearchResult().getName(), request.season, getLastSeason(episodes));
}
episodes = episodeForSeason;
}
Analytics.trackEvent(request.getProvider().getName(), "ViewEpisodeList", getSearchResult().getName());
Analytics.trackEvent(request.provider.getName(), "ViewEpisodeList", getSearchResult().getName());
return episodes;
}
@Override
public URI getLink() {
if (request.getSeason() != ALL_SEASONS) {
return request.getProvider().getEpisodeListLink(getSearchResult(), request.getSeason());
}
return request.getProvider().getEpisodeListLink(getSearchResult());
return request.provider.getEpisodeListLink(getSearchResult());
}
@ -271,17 +264,17 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
@Override
public String getTitle() {
if (request.getSeason() == ALL_SEASONS)
if (request.season == ALL_SEASONS)
return super.getTitle();
// add additional information to default title
return String.format("%s - Season %d", super.getTitle(), request.getSeason());
return String.format("%s - Season %d", super.getTitle(), request.season);
}
@Override
public Icon getIcon() {
return request.getProvider().getIcon();
return request.provider.getIcon();
}

View File

@ -8,9 +8,10 @@ import java.util.List;
import java.util.Locale;
import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.web.SortOrder;
interface AutoCompleteMatcher {
List<Match<File, ?>> match(List<File> files, Locale locale, boolean autodetection, Component parent) throws Exception;
List<Match<File, ?>> match(List<File> files, SortOrder order, Locale locale, boolean autodetection, Component parent) throws Exception;
}

View File

@ -43,6 +43,7 @@ import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.web.Episode;
import net.sourceforge.filebot.web.EpisodeListProvider;
import net.sourceforge.filebot.web.SearchResult;
import net.sourceforge.filebot.web.SortOrder;
class EpisodeListMatcher implements AutoCompleteMatcher {
@ -119,7 +120,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
}
protected Set<Episode> fetchEpisodeSet(Collection<String> seriesNames, final Locale locale, final Component parent) throws Exception {
protected Set<Episode> fetchEpisodeSet(Collection<String> seriesNames, final SortOrder sortOrder, final Locale locale, final Component parent) throws Exception {
List<Callable<List<Episode>>> tasks = new ArrayList<Callable<List<Episode>>>();
// detect series names and create episode list fetch tasks
@ -135,7 +136,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
SearchResult selectedSearchResult = selectSearchResult(query, results, parent);
if (selectedSearchResult != null) {
List<Episode> episodes = provider.getEpisodeList(selectedSearchResult, locale);
List<Episode> episodes = provider.getEpisodeList(selectedSearchResult, sortOrder, locale);
Analytics.trackEvent(provider.getName(), "FetchEpisodeList", selectedSearchResult.getName());
return episodes;
@ -168,9 +169,9 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
@Override
public List<Match<File, ?>> match(final List<File> files, final Locale locale, final boolean autodetection, final Component parent) throws Exception {
public List<Match<File, ?>> match(final List<File> files, final SortOrder sortOrder, final Locale locale, final boolean autodetection, final Component parent) throws Exception {
// focus on movie and subtitle files
final List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES);;
final List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES);
// assume that many shows will be matched, do it folder by folder
List<Callable<List<Match<File, ?>>>> taskPerFolder = new ArrayList<Callable<List<Match<File, ?>>>>();
@ -192,7 +193,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
@Override
public List<Match<File, ?>> call() throws Exception {
return matchEpisodeSet(batchSet, locale, autodetection, parent);
return matchEpisodeSet(batchSet, sortOrder, locale, autodetection, parent);
}
});
}
@ -217,7 +218,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
}
public List<Match<File, ?>> matchEpisodeSet(final List<File> files, Locale locale, boolean autodetection, Component parent) throws Exception {
public List<Match<File, ?>> matchEpisodeSet(final List<File> files, SortOrder sortOrder, Locale locale, boolean autodetection, Component parent) throws Exception {
Set<Episode> episodes = emptySet();
// detect series name and fetch episode list
@ -226,7 +227,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
if (names.size() > 0) {
// only allow one fetch session at a time so later requests can make use of cached results
synchronized (providerLock) {
episodes = fetchEpisodeSet(names, locale, parent);
episodes = fetchEpisodeSet(names, sortOrder, locale, parent);
}
}
}
@ -250,7 +251,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
if (input.size() > 0) {
// only allow one fetch session at a time so later requests can make use of cached results
synchronized (providerLock) {
episodes = fetchEpisodeSet(input, locale, parent);
episodes = fetchEpisodeSet(input, sortOrder, locale, parent);
}
}
}

View File

@ -43,6 +43,7 @@ import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.web.Movie;
import net.sourceforge.filebot.web.MovieIdentificationService;
import net.sourceforge.filebot.web.MoviePart;
import net.sourceforge.filebot.web.SortOrder;
class MovieHashMatcher implements AutoCompleteMatcher {
@ -56,7 +57,7 @@ class MovieHashMatcher implements AutoCompleteMatcher {
@Override
public List<Match<File, ?>> match(final List<File> files, final Locale locale, final boolean autodetect, final Component parent) throws Exception {
public List<Match<File, ?>> match(final List<File> files, final SortOrder sortOrder, final Locale locale, final boolean autodetect, final Component parent) throws Exception {
// handle movie files
List<File> movieFiles = filter(files, VIDEO_FILES);

View File

@ -25,13 +25,17 @@ import javax.swing.Action;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.border.CompoundBorder;
import javax.swing.border.TitledBorder;
import ca.odell.glazedlists.ListSelection;
import ca.odell.glazedlists.swing.EventSelectionModel;
@ -49,6 +53,7 @@ import net.sourceforge.filebot.web.EpisodeListProvider;
import net.sourceforge.filebot.web.Movie;
import net.sourceforge.filebot.web.MovieFormat;
import net.sourceforge.filebot.web.MovieIdentificationService;
import net.sourceforge.filebot.web.SortOrder;
import net.sourceforge.tuned.ExceptionUtilities;
import net.sourceforge.tuned.PreferencesMap.PreferencesEntry;
import net.sourceforge.tuned.ui.ActionPopup;
@ -71,6 +76,7 @@ public class RenamePanel extends JComponent {
private static final PreferencesEntry<String> persistentEpisodeFormat = Settings.forPackage(RenamePanel.class).entry("rename.format.episode");
private static final PreferencesEntry<String> persistentMovieFormat = Settings.forPackage(RenamePanel.class).entry("rename.format.movie");
private static final PreferencesEntry<String> persistentPreferredLanguage = Settings.forPackage(RenamePanel.class).entry("rename.language").defaultValue("en");
private static final PreferencesEntry<String> persistentPreferredEpisodeOrder = Settings.forPackage(RenamePanel.class).entry("rename.episode.order").defaultValue("Airdate");
public RenamePanel() {
@ -203,8 +209,9 @@ public class RenamePanel extends JComponent {
languages.addAll(Language.preferredLanguages()); // add preferred languages first
languages.addAll(Language.availableLanguages()); // then others
JList message = new JList(languages.toArray());
message.setCellRenderer(new DefaultListCellRenderer() {
JComboBox orderCombo = new JComboBox(SortOrder.values());
JList languageList = new JList(languages.toArray());
languageList.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
@ -214,19 +221,33 @@ public class RenamePanel extends JComponent {
}
});
// pre-select current language preferences
// pre-select current preferences
try {
orderCombo.setSelectedItem(SortOrder.forName(persistentPreferredEpisodeOrder.getValue()));
} catch (IllegalArgumentException e) {
// ignore
}
for (Language language : languages) {
if (language.getCode().equals(persistentPreferredLanguage.getValue())) {
message.setSelectedValue(language, true);
languageList.setSelectedValue(language, true);
break;
}
}
JOptionPane pane = new JOptionPane(new JScrollPane(message), PLAIN_MESSAGE, OK_CANCEL_OPTION);
pane.createDialog(getWindowAncestor(RenamePanel.this), "Language Preference").setVisible(true);
JScrollPane spLanguageList = new JScrollPane(languageList);
spLanguageList.setBorder(new CompoundBorder(new TitledBorder("Preferred Language"), spLanguageList.getBorder()));
JScrollPane spOrderCombo = new JScrollPane(orderCombo, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
spOrderCombo.setBorder(new CompoundBorder(new TitledBorder("Preferred Episode Order"), spOrderCombo.getBorder()));
JPanel message = new JPanel(new MigLayout("fill, flowy, insets 0"));
message.add(spLanguageList, "grow");
message.add(spOrderCombo, "grow, hmin 24px");
JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION);
pane.createDialog(getWindowAncestor(RenamePanel.this), "Preferences").setVisible(true);
if (pane.getValue() != null && pane.getValue().equals(OK_OPTION)) {
persistentPreferredLanguage.setValue(((Language) message.getSelectedValue()).getCode());
persistentPreferredLanguage.setValue(((Language) languageList.getSelectedValue()).getCode());
persistentPreferredEpisodeOrder.setValue(((SortOrder) orderCombo.getSelectedItem()).name());
}
}
});
@ -349,13 +370,14 @@ public class RenamePanel extends JComponent {
SwingWorker<List<Match<File, ?>>, Void> worker = new SwingWorker<List<Match<File, ?>>, Void>() {
private final List<File> remainingFiles = new LinkedList<File>(renameModel.files());
private final SortOrder order = SortOrder.forName(persistentPreferredEpisodeOrder.getValue());
private final Locale locale = new Locale(persistentPreferredLanguage.getValue());
private final boolean autodetection = !isShiftDown(evt); // skip name auto-detection if SHIFT is pressed
@Override
protected List<Match<File, ?>> doInBackground() throws Exception {
List<Match<File, ?>> matches = matcher.match(remainingFiles, locale, autodetection, getWindow(RenamePanel.this));
List<Match<File, ?>> matches = matcher.match(remainingFiles, order, locale, autodetection, getWindow(RenamePanel.this));
// remove matched files
for (Match<File, ?> match : matches) {

View File

@ -2,8 +2,6 @@
package net.sourceforge.filebot.web;
import static net.sourceforge.filebot.web.EpisodeUtilities.*;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
@ -32,7 +30,7 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
protected abstract List<SearchResult> fetchSearchResult(String query, Locale locale) throws Exception;
protected abstract List<Episode> fetchEpisodeList(SearchResult searchResult, Locale locale) throws Exception;
protected abstract List<Episode> fetchEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws Exception;
public List<SearchResult> search(String query) throws Exception {
@ -56,40 +54,22 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
public List<Episode> getEpisodeList(SearchResult searchResult) throws Exception {
return getEpisodeList(searchResult, getDefaultLocale());
return getEpisodeList(searchResult, SortOrder.Airdate, getDefaultLocale());
}
public List<Episode> getEpisodeList(SearchResult searchResult, Locale locale) throws Exception {
public List<Episode> getEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws Exception {
ResultCache cache = getCache();
List<Episode> episodes = (cache != null) ? cache.getEpisodeList(searchResult, locale) : null;
List<Episode> episodes = (cache != null) ? cache.getEpisodeList(searchResult, sortOrder, locale) : null;
if (episodes != null) {
return episodes;
}
// perform actual search
episodes = fetchEpisodeList(searchResult, locale);
episodes = fetchEpisodeList(searchResult, sortOrder, locale);
// cache results and return
return (cache != null) ? cache.putEpisodeList(searchResult, locale, episodes) : episodes;
}
public List<Episode> getEpisodeList(SearchResult searchResult, int season) throws Exception {
return getEpisodeList(searchResult, season, getDefaultLocale());
}
@Override
public List<Episode> getEpisodeList(SearchResult searchResult, int season, Locale locale) throws Exception {
List<Episode> all = getEpisodeList(searchResult, locale);
List<Episode> eps = filterBySeason(all, season);
if (eps.isEmpty()) {
throw new SeasonOutOfBoundsException(searchResult.getName(), season, getLastSeason(all));
}
return eps;
return (cache != null) ? cache.putEpisodeList(searchResult, sortOrder, locale, episodes) : episodes;
}
@ -145,9 +125,9 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
}
public List<Episode> putEpisodeList(SearchResult key, Locale locale, List<Episode> episodes) {
public List<Episode> putEpisodeList(SearchResult key, SortOrder sortOrder, Locale locale, List<Episode> episodes) {
try {
cache.put(new Element(new Key(id, key, locale), episodes.toArray(new Episode[0])));
cache.put(new Element(new Key(id, key, sortOrder, locale), episodes.toArray(new Episode[0])));
} catch (Exception e) {
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage(), e);
}
@ -156,9 +136,9 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
}
public List<Episode> getEpisodeList(SearchResult key, Locale locale) {
public List<Episode> getEpisodeList(SearchResult key, SortOrder sortOrder, Locale locale) {
try {
Element element = cache.get(new Key(id, key, locale));
Element element = cache.get(new Key(id, key, sortOrder, locale));
if (element != null) {
return Arrays.asList((Episode[]) element.getValue());
}

View File

@ -96,7 +96,7 @@ public class AnidbClient extends AbstractEpisodeListProvider {
@Override
public List<Episode> fetchEpisodeList(SearchResult searchResult, Locale language) throws Exception {
public List<Episode> fetchEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale language) throws Exception {
AnidbSearchResult anime = (AnidbSearchResult) searchResult;
// e.g. http://api.anidb.net:9001/httpapi?request=anime&client=filebot&clientver=1&protover=1&aid=4521
@ -145,28 +145,14 @@ public class AnidbClient extends AbstractEpisodeListProvider {
@Override
public URI getEpisodeListLink(SearchResult searchResult) {
int aid = ((AnidbSearchResult) searchResult).getAnimeId();
try {
return new URI("http", host, "/a" + aid, null);
return new URI("http", host, "/a" + ((AnidbSearchResult) searchResult).getAnimeId(), null);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
@Override
public List<Episode> getEpisodeList(SearchResult searchResult, int season, Locale locale) throws Exception {
throw new UnsupportedOperationException();
}
@Override
public URI getEpisodeListLink(SearchResult searchResult, int season) {
return null;
}
public synchronized List<AnidbSearchResult> getAnimeTitles() throws Exception {
URL url = new URL("http", host, "/api/animetitles.dat.gz");
ResultCache cache = getCache();

View File

@ -26,15 +26,9 @@ public interface EpisodeListProvider {
public List<SearchResult> search(String query, Locale locale) throws Exception;
public List<Episode> getEpisodeList(SearchResult searchResult, Locale locale) throws Exception;
public List<Episode> getEpisodeList(SearchResult searchResult, int season, Locale locale) throws Exception;
public List<Episode> getEpisodeList(SearchResult searchResult, SortOrder order, Locale locale) throws Exception;
public URI getEpisodeListLink(SearchResult searchResult);
public URI getEpisodeListLink(SearchResult searchResult, int season);
}

View File

@ -21,7 +21,7 @@ public final class EpisodeUtilities {
// filter given season from all seasons
for (Episode episode : episodes) {
if (season == episode.getSeason()) {
if (episode.getSeason() != null && season == episode.getSeason()) {
results.add(episode);
}
}

View File

@ -15,8 +15,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -78,7 +76,6 @@ public class IMDbClient implements MovieIdentificationService {
results.add(new Movie(name, Integer.parseInt(year), getImdbId(href)));
} catch (Exception e) {
// ignore illegal movies (TV Shows, Videos, Video Games, etc)
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getClass().getName() + ": " + e.getMessage());
}
}

View File

@ -115,7 +115,7 @@ public class SerienjunkiesClient extends AbstractEpisodeListProvider {
@Override
public List<Episode> fetchEpisodeList(SearchResult searchResult, Locale locale) throws IOException {
public List<Episode> fetchEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws IOException {
SerienjunkiesSearchResult series = (SerienjunkiesSearchResult) searchResult;
// fetch episode data
@ -162,18 +162,7 @@ public class SerienjunkiesClient extends AbstractEpisodeListProvider {
@Override
public URI getEpisodeListLink(SearchResult searchResult) {
return getEpisodeListLink(searchResult, "alle-serien-staffeln");
}
@Override
public URI getEpisodeListLink(SearchResult searchResult, int season) {
return getEpisodeListLink(searchResult, "season" + season);
}
public URI getEpisodeListLink(SearchResult searchResult, String page) {
return URI.create(String.format("http://www.serienjunkies.de/%s/%s.html", ((SerienjunkiesSearchResult) searchResult).getLink(), page));
return URI.create(String.format("http://www.serienjunkies.de/%s/alle-serien-staffeln.html", ((SerienjunkiesSearchResult) searchResult).getLink()));
}

View File

@ -0,0 +1,25 @@
package net.sourceforge.filebot.web;
public enum SortOrder {
Airdate,
DVD,
Absolute;
public static SortOrder forName(String name) {
for (SortOrder order : SortOrder.values()) {
if (order.name().equalsIgnoreCase(name)) {
return order;
}
}
throw new IllegalArgumentException("Invalid SortOrder: " + name);
}
@Override
public String toString() {
return String.format("%s Order", name());
}
}

View File

@ -67,7 +67,7 @@ public class TVRageClient extends AbstractEpisodeListProvider {
@Override
public List<Episode> fetchEpisodeList(SearchResult searchResult, Locale locale) throws IOException, SAXException {
public List<Episode> fetchEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws IOException, SAXException {
TVRageSearchResult series = (TVRageSearchResult) searchResult;
URL episodeListUrl = new URL("http", host, "/feeds/full_show_info.php?sid=" + series.getSeriesId());
@ -95,6 +95,11 @@ public class TVRageClient extends AbstractEpisodeListProvider {
specials.add(new Episode(seriesName, seriesStartDate, seasonNumber, null, title, null, specialNumber, airdate));
} else {
// handle as normal episode
if (sortOrder == SortOrder.Absolute) {
episodeNumber = getIntegerContent("epnum", node);
seasonNumber = null;
}
episodes.add(new Episode(seriesName, seriesStartDate, seasonNumber, episodeNumber, title, null, null, airdate));
}
}
@ -108,20 +113,7 @@ public class TVRageClient extends AbstractEpisodeListProvider {
@Override
public URI getEpisodeListLink(SearchResult searchResult) {
return getEpisodeListLink(searchResult, "all");
}
@Override
public URI getEpisodeListLink(SearchResult searchResult, int season) {
return getEpisodeListLink(searchResult, String.valueOf(season));
}
private URI getEpisodeListLink(SearchResult searchResult, String seasonString) {
String base = ((TVRageSearchResult) searchResult).getLink();
return URI.create(base + "/episode_list/" + seasonString);
return URI.create(((TVRageSearchResult) searchResult).getLink() + "/episode_list/all");
}

View File

@ -109,9 +109,8 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
@Override
public List<Episode> fetchEpisodeList(SearchResult searchResult, Locale language) throws Exception {
public List<Episode> fetchEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale language) throws Exception {
TheTVDBSearchResult series = (TheTVDBSearchResult) searchResult;
Document seriesRecord = getSeriesRecord(series, language);
// we could get the series name from the search result, but the language may not match the given parameter
@ -130,17 +129,9 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
Integer absoluteNumber = getIntegerContent("absolute_number", node);
Date airdate = Date.parse(getTextContent("FirstAired", node), "yyyy-MM-dd");
// prefer DVD SxE numbers if available
Integer seasonNumber;
Integer episodeNumber;
try {
seasonNumber = new Integer(dvdSeasonNumber);
episodeNumber = new Float(dvdEpisodeNumber).intValue();
} catch (Exception e) {
seasonNumber = getIntegerContent("SeasonNumber", node);
episodeNumber = getIntegerContent("EpisodeNumber", node);
}
// default numbering
Integer episodeNumber = getIntegerContent("EpisodeNumber", node);
Integer seasonNumber = getIntegerContent("SeasonNumber", node);
if (seasonNumber == null || seasonNumber == 0) {
// handle as special episode
@ -154,6 +145,20 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
specials.add(new Episode(seriesName, seriesStartDate, seasonNumber, null, episodeName, null, specialNumber, airdate));
} else {
// handle as normal episode
if (sortOrder == SortOrder.Absolute) {
if (absoluteNumber != null) {
episodeNumber = absoluteNumber;
seasonNumber = null;
}
} else if (sortOrder == SortOrder.DVD) {
try {
episodeNumber = new Float(dvdEpisodeNumber).intValue();
seasonNumber = new Integer(dvdSeasonNumber);
} catch (Exception e) {
// ignore, fallback to default numbering
}
}
episodes.add(new Episode(seriesName, seriesStartDate, seasonNumber, episodeNumber, episodeName, absoluteNumber, null, airdate));
}
}
@ -237,28 +242,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
@Override
public URI getEpisodeListLink(SearchResult searchResult) {
int seriesId = ((TheTVDBSearchResult) searchResult).getSeriesId();
return URI.create("http://" + host + "/?tab=seasonall&id=" + seriesId);
}
@Override
public URI getEpisodeListLink(SearchResult searchResult, int season) {
int seriesId = ((TheTVDBSearchResult) searchResult).getSeriesId();
try {
// get episode xml from first episode of given season
Document dom = getDocument(getResource(MirrorType.XML, "/api/" + apikey + "/series/" + seriesId + "/default/" + season + "/1/en.xml"));
int seasonId = Integer.valueOf(selectString("Data/Episode/seasonid", dom));
return new URI("http://" + host + "/?tab=season&seriesid=" + seriesId + "&seasonid=" + seasonId);
} catch (Exception e) {
// log and ignore any IOException
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to retrieve season id", e);
}
return null;
return URI.create("http://" + host + "/?tab=seasonall&id=" + ((TheTVDBSearchResult) searchResult).getSeriesId());
}

View File

@ -8,8 +8,6 @@ import java.io.File;
import org.junit.Test;
import net.sourceforge.filebot.media.ReleaseInfo;
public class ReleaseInfoTest {
@ -18,7 +16,7 @@ public class ReleaseInfoTest {
ReleaseInfo info = new ReleaseInfo();
File f = new File("Jurassic.Park[1993]DvDrip-aXXo.avi");
assertEquals("DvDrip", info.getVideoSource(f));
assertEquals("DVDRip", info.getVideoSource(f));
}

View File

@ -37,7 +37,7 @@ public class SeriesNameMatcherTest {
assertEquals("The Test", matcher.matchByEpisodeIdentifier("The Test - 1x01"));
// real world test
assertEquals("Mushishi", matcher.matchByEpisodeIdentifier("[niizk]_Mushishi_-_01_-_The_Green_Gathering"));
assertEquals("Mushishi", matcher.matchByEpisodeIdentifier("[niizk]_Mushishi_-_1x01_-_The_Green_Gathering"));
}

View File

@ -127,7 +127,7 @@ public class AnidbClientTest {
@Test
public void getEpisodeListI18N() throws Exception {
List<Episode> list = anidb.getEpisodeList(monsterSearchResult, Locale.JAPANESE);
List<Episode> list = anidb.getEpisodeList(monsterSearchResult, SortOrder.Airdate, Locale.JAPANESE);
Episode last = list.get(73);
assertEquals("モンスター", last.getSeriesName());

View File

@ -18,7 +18,6 @@ public class IMDbClientTest {
public void searchMovie() throws Exception {
List<Movie> results = imdb.searchMovie("Avatar", null);
assertEquals(26, results.size());
Movie movie = (Movie) results.get(0);
assertEquals("Avatar", movie.getName());

View File

@ -38,7 +38,7 @@ public class OpenSubtitlesXmlRpcTest {
Movie sample = (Movie) list.get(0);
// check sample entry
assertEquals("\"Babylon 5\"", sample.getName());
assertEquals("Babylon 5", sample.getName());
assertEquals(1994, sample.getYear());
assertEquals(105946, sample.getImdbId());
}

View File

@ -49,8 +49,6 @@ public class SublightSubtitleClientTest {
List<SubtitleDescriptor> list = client.getSubtitleList(new Movie("Heroes", 2006, 813715), "English");
SubtitleDescriptor sample = list.get(0);
assertTrue(sample.getName().startsWith("Heroes"));
assertEquals("English", sample.getLanguageName());
// check size

View File

@ -30,7 +30,7 @@ public class SubsceneSubtitleClientTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
twinpeaksSearchResult = new SubsceneSearchResult("Twin Peaks", "Twin Peaks - First Season (1990)", new URL("http://subscene.com/twin-peaks--first-season/subtitles-32482.aspx"));
twinpeaksSearchResult = new SubsceneSearchResult("Twin Peaks", "Twin Peaks - First Season (1990)", new URL("http://subscene.com/Twin-Peaks-First-Season/subtitles-32482.aspx"));
lostSearchResult = new SubsceneSearchResult("Lost", "Lost - Fourth Season (2008)", new URL("http://subscene.com/Lost-Fourth-Season/subtitles-70963.aspx"));
}
@ -64,12 +64,11 @@ public class SubsceneSubtitleClientTest {
@Test
public void getSubtitleListSearchResult() throws Exception {
List<SubtitleDescriptor> subtitleList = subscene.getSubtitleList(twinpeaksSearchResult, "Italian");
assertEquals(1, subtitleList.size());
assertEquals(10, subtitleList.size());
SubtitleDescriptor subtitle = subtitleList.get(0);
assertEquals("Twin Peaks - First Season", subtitle.getName());
assertEquals("Italian", subtitle.getLanguageName());
assertEquals("zip", subtitle.getType());
}

View File

@ -36,7 +36,7 @@ public class TVRageClientTest {
@Test
public void getEpisodeList() throws Exception {
List<Episode> list = tvrage.getEpisodeList(buffySearchResult, 7);
List<Episode> list = EpisodeUtilities.filterBySeason(tvrage.getEpisodeList(buffySearchResult), 7);
assertEquals(22, list.size());
@ -56,28 +56,16 @@ public class TVRageClientTest {
public void getEpisodeListAll() throws Exception {
List<Episode> list = tvrage.getEpisodeList(buffySearchResult);
assertEquals(145, list.size());
assertEquals(144, list.size());
Episode first = list.get(0);
assertEquals("Buffy the Vampire Slayer", first.getSeriesName());
assertEquals("Unaired Pilot", first.getTitle());
assertEquals("0", first.getEpisode().toString());
assertEquals("0", first.getSeason().toString());
assertEquals("Welcome to the Hellmouth (1)", first.getTitle());
assertEquals("1", first.getEpisode().toString());
assertEquals("1", first.getSeason().toString());
assertEquals(null, first.getAbsolute());
assertEquals(null, first.airdate());
}
@Test(expected = SeasonOutOfBoundsException.class)
public void getEpisodeListIllegalSeason() throws Exception {
tvrage.getEpisodeList(buffySearchResult, 42);
}
@Test
public void getEpisodeListLink() throws Exception {
assertEquals(tvrage.getEpisodeListLink(buffySearchResult, 1).toString(), "http://www.tvrage.com/Buffy_The_Vampire_Slayer/episode_list/1");
assertEquals("1997-03-10", first.airdate().toString());
}

View File

@ -83,9 +83,7 @@ public class TheTVDBClientTest {
@Test
public void getEpisodeListSingleSeason() throws Exception {
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Wonderfalls", 78845), 1);
assertEquals(14, list.size());
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Wonderfalls", 78845));
Episode first = list.get(0);
@ -101,9 +99,7 @@ public class TheTVDBClientTest {
@Test
public void getEpisodeListNumbering() throws Exception {
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Firefly", 78874), 1);
assertEquals(14, list.size());
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Firefly", 78874), SortOrder.DVD, Locale.ENGLISH);
Episode first = list.get(0);
assertEquals("Firefly", first.getSeriesName());
@ -122,12 +118,6 @@ public class TheTVDBClientTest {
}
@Test
public void getEpisodeListLinkSingleSeason() {
assertEquals("http://www.thetvdb.com/?tab=season&seriesid=73965&seasonid=6749", thetvdb.getEpisodeListLink(new TheTVDBSearchResult("Roswell", 73965), 3).toString());
}
@Test
public void getMirror() throws Exception {
assertNotNull(thetvdb.getMirror(MirrorType.XML));
@ -153,15 +143,15 @@ public class TheTVDBClientTest {
public void lookupByID() throws Exception {
TheTVDBSearchResult series = thetvdb.lookupByID(78874, Locale.ENGLISH);
assertEquals("Firefly", series.getName());
assertEquals(70726, series.getSeriesId());
assertEquals(78874, series.getSeriesId());
}
@Test
public void lookupByIMDbID() throws Exception {
TheTVDBSearchResult series = thetvdb.lookupByIMDbID(78874, Locale.ENGLISH);
TheTVDBSearchResult series = thetvdb.lookupByIMDbID(303461, Locale.ENGLISH);
assertEquals("Firefly", series.getName());
assertEquals(70726, series.getSeriesId());
assertEquals(78874, series.getSeriesId());
}
@ -179,9 +169,6 @@ public class TheTVDBClientTest {
assertEquals(310, it.getOverview().length());
assertEquals("60", it.getRuntime());
assertEquals("Chuck", it.getName());
assertEquals("http://thetvdb.com/banners/graphical/80348-g23.jpg", it.getBannerUrl().toString());
assertEquals("http://thetvdb.com/banners/fanart/original/80348-51.jpg", it.getFanartUrl().toString());
assertEquals("http://thetvdb.com/banners/posters/80348-16.jpg", it.getPosterUrl().toString());
}