* include 3-letter language codes in Language config file
This commit is contained in:
parent
e1409b5c30
commit
b9f76c407c
|
@ -1,4 +1,4 @@
|
||||||
package net.sourceforge.filebot.ui;
|
package net.sourceforge.filebot;
|
||||||
|
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
@ -12,16 +12,26 @@ import java.util.Set;
|
||||||
|
|
||||||
public class Language {
|
public class Language {
|
||||||
|
|
||||||
private final String code;
|
private final String iso2;
|
||||||
|
private final String iso3;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public Language(String code, String name) {
|
public Language(String iso2, String iso3, String name) {
|
||||||
this.code = code;
|
this.iso2 = iso2;
|
||||||
|
this.iso3 = iso3;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
return code;
|
return iso2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getISO2() {
|
||||||
|
return iso2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getISO3() {
|
||||||
|
return iso3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -39,7 +49,7 @@ public class Language {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Language clone() {
|
public Language clone() {
|
||||||
return new Language(code, name);
|
return new Language(iso2, iso3, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Comparator<Language> ALPHABETIC_ORDER = new Comparator<Language>() {
|
public static final Comparator<Language> ALPHABETIC_ORDER = new Comparator<Language>() {
|
||||||
|
@ -54,12 +64,14 @@ public class Language {
|
||||||
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new Language(code, bundle.getString(code + ".name"));
|
String[] values = bundle.getString(code).split("\\t", 2);
|
||||||
|
return new Language(code, values[0], values[1]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (code == null || code.isEmpty()) {
|
if (code == null || code.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Language(code, new Locale(code).getDisplayLanguage(Locale.ROOT));
|
Locale locale = new Locale(code);
|
||||||
|
return new Language(locale.getLanguage(), locale.getISO3Language(), locale.getDisplayLanguage(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +86,16 @@ public class Language {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Language getLanguage(Locale locale) {
|
public static Language getLanguage(Locale locale) {
|
||||||
return locale == null ? null : getLanguageByName(locale.getDisplayLanguage(Locale.ENGLISH));
|
if (locale == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String code = locale.getLanguage();
|
||||||
|
for (Language it : availableLanguages()) {
|
||||||
|
if (it.getISO2().equals(code) || it.getISO3().equals(code)) {
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Language getLanguageByName(String name) {
|
public static Language getLanguageByName(String name) {
|
||||||
|
@ -87,16 +108,11 @@ public class Language {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getISO3LanguageCodeByName(String languageName) {
|
public static String getISO3LanguageCodeByName(String languageName) {
|
||||||
Language language = Language.getLanguageByName(languageName);
|
try {
|
||||||
if (language != null) {
|
return Language.getLanguageByName(languageName).getISO3();
|
||||||
try {
|
} catch (Exception e) {
|
||||||
return new Locale(language.getCode()).getISO3Language();
|
return null;
|
||||||
} catch (Exception e) {
|
|
||||||
return language.getCode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Language> availableLanguages() {
|
public static List<Language> availableLanguages() {
|
|
@ -0,0 +1,45 @@
|
||||||
|
# available languages
|
||||||
|
languages.all = sq,ar,hy,pb,bg,ca,zh,hr,cs,da,nl,en,et,fi,fr,de,el,he,hi,hu,id,it,ja,ko,lv,lt,mk,ms,no,fa,pl,pt,ro,ru,sr,sk,sl,es,sv,th,tr,vi
|
||||||
|
languages.common = en,de,fr,es,pt,ru,ja,zh
|
||||||
|
sq: sqi Albanian
|
||||||
|
ar: ara Arabic
|
||||||
|
hy: hye Armenian
|
||||||
|
pb: pob Brazilian
|
||||||
|
bg: bul Bulgarian
|
||||||
|
ca: cat Catalan
|
||||||
|
zh: zho Chinese
|
||||||
|
hr: hrv Croatian
|
||||||
|
cs: ces Czech
|
||||||
|
da: dan Danish
|
||||||
|
nl: nld Dutch
|
||||||
|
en: eng English
|
||||||
|
et: est Estonian
|
||||||
|
fi: fin Finnish
|
||||||
|
fr: fra French
|
||||||
|
de: deu German
|
||||||
|
el: ell Greek
|
||||||
|
he: heb Hebrew
|
||||||
|
hi: hin Hindi
|
||||||
|
hu: hun Hungarian
|
||||||
|
id: ind Indonesian
|
||||||
|
it: ita Italian
|
||||||
|
ja: jpn Japanese
|
||||||
|
ko: kor Korean
|
||||||
|
lv: lav Latvian
|
||||||
|
lt: lit Lithuanian
|
||||||
|
mk: mkd Macedonian
|
||||||
|
ms: msa Malay
|
||||||
|
no: nor Norwegian
|
||||||
|
fa: fas Persian
|
||||||
|
pl: pol Polish
|
||||||
|
pt: por Portuguese
|
||||||
|
ro: ron Romanian
|
||||||
|
ru: rus Russian
|
||||||
|
sr: srp Serbian
|
||||||
|
sk: slk Slovak
|
||||||
|
sl: slv Slovenian
|
||||||
|
es: spa Spanish
|
||||||
|
sv: swe Swedish
|
||||||
|
th: tha Thai
|
||||||
|
tr: tur Turkish
|
||||||
|
vi: vie Vietnamese
|
|
@ -57,7 +57,7 @@ import net.sourceforge.filebot.similarity.SeriesNameMatcher;
|
||||||
import net.sourceforge.filebot.similarity.SimilarityComparator;
|
import net.sourceforge.filebot.similarity.SimilarityComparator;
|
||||||
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
||||||
import net.sourceforge.filebot.subtitle.SubtitleFormat;
|
import net.sourceforge.filebot.subtitle.SubtitleFormat;
|
||||||
import net.sourceforge.filebot.ui.Language;
|
import net.sourceforge.filebot.Language;
|
||||||
import net.sourceforge.filebot.vfs.MemoryFile;
|
import net.sourceforge.filebot.vfs.MemoryFile;
|
||||||
import net.sourceforge.filebot.web.AudioTrack;
|
import net.sourceforge.filebot.web.AudioTrack;
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
|
|
|
@ -33,7 +33,7 @@ import net.sourceforge.filebot.similarity.MetricCascade;
|
||||||
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
|
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
|
||||||
import net.sourceforge.filebot.similarity.SequenceMatchSimilarity;
|
import net.sourceforge.filebot.similarity.SequenceMatchSimilarity;
|
||||||
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
||||||
import net.sourceforge.filebot.ui.Language;
|
import net.sourceforge.filebot.Language;
|
||||||
import net.sourceforge.filebot.vfs.ArchiveType;
|
import net.sourceforge.filebot.vfs.ArchiveType;
|
||||||
import net.sourceforge.filebot.vfs.MemoryFile;
|
import net.sourceforge.filebot.vfs.MemoryFile;
|
||||||
import net.sourceforge.filebot.web.SearchResult;
|
import net.sourceforge.filebot.web.SearchResult;
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
# available languages
|
|
||||||
languages.all = sq,ar,hy,pb,bg,ca,zh,hr,cs,da,nl,en,et,fi,fr,de,el,he,hi,hu,id,it,ja,ko,lv,lt,mk,ms,no,fa,pl,pt,ro,ru,sr,sk,sl,es,sv,th,tr,vi
|
|
||||||
languages.common = en,de,fr,es,pt,ru,ja,zh
|
|
||||||
sq.name: Albanian
|
|
||||||
ar.name: Arabic
|
|
||||||
hy.name: Armenian
|
|
||||||
pb.name: Brazilian
|
|
||||||
bg.name: Bulgarian
|
|
||||||
ca.name: Catalan
|
|
||||||
zh.name: Chinese
|
|
||||||
hr.name: Croatian
|
|
||||||
cs.name: Czech
|
|
||||||
da.name: Danish
|
|
||||||
nl.name: Dutch
|
|
||||||
en.name: English
|
|
||||||
et.name: Estonian
|
|
||||||
fi.name: Finnish
|
|
||||||
fr.name: French
|
|
||||||
de.name: German
|
|
||||||
el.name: Greek
|
|
||||||
he.name: Hebrew
|
|
||||||
hi.name: Hindi
|
|
||||||
hu.name: Hungarian
|
|
||||||
id.name: Indonesian
|
|
||||||
it.name: Italian
|
|
||||||
ja.name: Japanese
|
|
||||||
ko.name: Korean
|
|
||||||
lv.name: Latvian
|
|
||||||
lt.name: Lithuanian
|
|
||||||
mk.name: Macedonian
|
|
||||||
ms.name: Malay
|
|
||||||
no.name: Norwegian
|
|
||||||
fa.name: Persian
|
|
||||||
pl.name: Polish
|
|
||||||
pt.name: Portuguese
|
|
||||||
ro.name: Romanian
|
|
||||||
ru.name: Russian
|
|
||||||
sr.name: Serbian
|
|
||||||
sk.name: Slovak
|
|
||||||
sl.name: Slovenian
|
|
||||||
es.name: Spanish
|
|
||||||
sv.name: Swedish
|
|
||||||
th.name: Thai
|
|
||||||
tr.name: Turkish
|
|
||||||
vi.name: Vietnamese
|
|
|
@ -1,7 +1,7 @@
|
||||||
package net.sourceforge.filebot.ui;
|
package net.sourceforge.filebot.ui;
|
||||||
|
|
||||||
import static java.awt.event.ItemEvent.*;
|
import static java.awt.event.ItemEvent.*;
|
||||||
import static net.sourceforge.filebot.ui.Language.*;
|
import static net.sourceforge.filebot.Language.*;
|
||||||
|
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
import java.awt.event.ItemListener;
|
import java.awt.event.ItemListener;
|
||||||
|
@ -16,6 +16,7 @@ import javax.swing.JComboBox;
|
||||||
import javax.swing.event.PopupMenuEvent;
|
import javax.swing.event.PopupMenuEvent;
|
||||||
import javax.swing.event.PopupMenuListener;
|
import javax.swing.event.PopupMenuListener;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.Language;
|
||||||
import net.sourceforge.filebot.Settings;
|
import net.sourceforge.filebot.Settings;
|
||||||
|
|
||||||
public class LanguageComboBox extends JComboBox {
|
public class LanguageComboBox extends JComboBox {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.ui;
|
package net.sourceforge.filebot.ui;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
|
||||||
|
@ -12,48 +10,46 @@ import javax.swing.border.Border;
|
||||||
import javax.swing.border.CompoundBorder;
|
import javax.swing.border.CompoundBorder;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.Language;
|
||||||
import net.sourceforge.filebot.ResourceManager;
|
import net.sourceforge.filebot.ResourceManager;
|
||||||
import net.sourceforge.tuned.ui.DashedSeparator;
|
import net.sourceforge.tuned.ui.DashedSeparator;
|
||||||
|
|
||||||
|
|
||||||
public class LanguageComboBoxCellRenderer implements ListCellRenderer {
|
public class LanguageComboBoxCellRenderer implements ListCellRenderer {
|
||||||
|
|
||||||
private Border padding = new EmptyBorder(2, 2, 2, 2);
|
private Border padding = new EmptyBorder(2, 2, 2, 2);
|
||||||
|
|
||||||
private Border favoritePadding = new EmptyBorder(0, 6, 0, 6);
|
private Border favoritePadding = new EmptyBorder(0, 6, 0, 6);
|
||||||
|
|
||||||
private ListCellRenderer base;
|
private ListCellRenderer base;
|
||||||
|
|
||||||
|
|
||||||
public LanguageComboBoxCellRenderer(final ListCellRenderer base) {
|
public LanguageComboBoxCellRenderer(final ListCellRenderer base) {
|
||||||
this.base = base;
|
this.base = base;
|
||||||
this.padding = new CompoundBorder(padding, ((JLabel) base).getBorder());
|
this.padding = new CompoundBorder(padding, ((JLabel) base).getBorder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
JLabel c = (JLabel) base.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
JLabel c = (JLabel) base.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||||
|
|
||||||
Language language = (Language) value;
|
Language language = (Language) value;
|
||||||
c.setText(language.getName());
|
c.setText(language.getName());
|
||||||
c.setIcon(ResourceManager.getFlagIcon(language.getCode()));
|
c.setIcon(ResourceManager.getFlagIcon(language.getCode()));
|
||||||
|
|
||||||
// default padding
|
// default padding
|
||||||
c.setBorder(padding);
|
c.setBorder(padding);
|
||||||
|
|
||||||
LanguageComboBoxModel model = (LanguageComboBoxModel) list.getModel();
|
LanguageComboBoxModel model = (LanguageComboBoxModel) list.getModel();
|
||||||
|
|
||||||
if ((index > 0 && index <= model.favorites().size())) {
|
if ((index > 0 && index <= model.favorites().size())) {
|
||||||
// add favorite padding
|
// add favorite padding
|
||||||
c.setBorder(new CompoundBorder(favoritePadding, c.getBorder()));
|
c.setBorder(new CompoundBorder(favoritePadding, c.getBorder()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == 0 || index == model.favorites().size()) {
|
if (index == 0 || index == model.favorites().size()) {
|
||||||
// add separator border
|
// add separator border
|
||||||
c.setBorder(new CompoundBorder(new DashedSeparator(10, 4, Color.lightGray, list.getBackground()), c.getBorder()));
|
c.setBorder(new CompoundBorder(new DashedSeparator(10, 4, Color.lightGray, list.getBackground()), c.getBorder()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.sourceforge.filebot.ui;
|
package net.sourceforge.filebot.ui;
|
||||||
|
|
||||||
import static net.sourceforge.filebot.ui.Language.*;
|
import static net.sourceforge.filebot.Language.*;
|
||||||
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -10,9 +10,11 @@ import java.util.Set;
|
||||||
import javax.swing.AbstractListModel;
|
import javax.swing.AbstractListModel;
|
||||||
import javax.swing.ComboBoxModel;
|
import javax.swing.ComboBoxModel;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.Language;
|
||||||
|
|
||||||
public class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel {
|
public class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel {
|
||||||
|
|
||||||
public static final Language ALL_LANGUAGES = new Language("undefined", "All Languages");
|
public static final Language ALL_LANGUAGES = new Language("", "", "All Languages");
|
||||||
|
|
||||||
private Language defaultLanguage;
|
private Language defaultLanguage;
|
||||||
private Language selection;
|
private Language selection;
|
||||||
|
|
|
@ -32,7 +32,7 @@ import net.sourceforge.filebot.ui.AbstractSearchPanel;
|
||||||
import net.sourceforge.filebot.ui.FileBotList;
|
import net.sourceforge.filebot.ui.FileBotList;
|
||||||
import net.sourceforge.filebot.ui.FileBotListExportHandler;
|
import net.sourceforge.filebot.ui.FileBotListExportHandler;
|
||||||
import net.sourceforge.filebot.ui.FileBotTab;
|
import net.sourceforge.filebot.ui.FileBotTab;
|
||||||
import net.sourceforge.filebot.ui.Language;
|
import net.sourceforge.filebot.Language;
|
||||||
import net.sourceforge.filebot.ui.LanguageComboBox;
|
import net.sourceforge.filebot.ui.LanguageComboBox;
|
||||||
import net.sourceforge.filebot.ui.SelectDialog;
|
import net.sourceforge.filebot.ui.SelectDialog;
|
||||||
import net.sourceforge.filebot.ui.transfer.ArrayTransferable;
|
import net.sourceforge.filebot.ui.transfer.ArrayTransferable;
|
||||||
|
|
|
@ -53,7 +53,7 @@ import net.sourceforge.filebot.StandardRenameAction;
|
||||||
import net.sourceforge.filebot.WebServices;
|
import net.sourceforge.filebot.WebServices;
|
||||||
import net.sourceforge.filebot.format.MediaBindingBean;
|
import net.sourceforge.filebot.format.MediaBindingBean;
|
||||||
import net.sourceforge.filebot.similarity.Match;
|
import net.sourceforge.filebot.similarity.Match;
|
||||||
import net.sourceforge.filebot.ui.Language;
|
import net.sourceforge.filebot.Language;
|
||||||
import net.sourceforge.filebot.ui.rename.FormatDialog.Mode;
|
import net.sourceforge.filebot.ui.rename.FormatDialog.Mode;
|
||||||
import net.sourceforge.filebot.ui.rename.RenameModel.FormattedFuture;
|
import net.sourceforge.filebot.ui.rename.RenameModel.FormattedFuture;
|
||||||
import net.sourceforge.filebot.web.AudioTrack;
|
import net.sourceforge.filebot.web.AudioTrack;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.ui.subtitle;
|
package net.sourceforge.filebot.ui.subtitle;
|
||||||
|
|
||||||
|
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static net.sourceforge.filebot.MediaTypes.*;
|
import static net.sourceforge.filebot.MediaTypes.*;
|
||||||
|
|
||||||
|
@ -20,35 +18,33 @@ import java.util.ResourceBundle;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
import javax.swing.event.SwingPropertyChangeSupport;
|
import javax.swing.event.SwingPropertyChangeSupport;
|
||||||
|
|
||||||
import net.sourceforge.filebot.ui.Language;
|
import net.sourceforge.filebot.Language;
|
||||||
import net.sourceforge.filebot.vfs.ArchiveType;
|
import net.sourceforge.filebot.vfs.ArchiveType;
|
||||||
import net.sourceforge.filebot.vfs.MemoryFile;
|
import net.sourceforge.filebot.vfs.MemoryFile;
|
||||||
import net.sourceforge.filebot.web.SubtitleDescriptor;
|
import net.sourceforge.filebot.web.SubtitleDescriptor;
|
||||||
import net.sourceforge.filebot.web.SubtitleProvider;
|
import net.sourceforge.filebot.web.SubtitleProvider;
|
||||||
import net.sourceforge.tuned.FileUtilities;
|
import net.sourceforge.tuned.FileUtilities;
|
||||||
|
|
||||||
|
|
||||||
public class SubtitlePackage {
|
public class SubtitlePackage {
|
||||||
|
|
||||||
private final SubtitleProvider provider;
|
private final SubtitleProvider provider;
|
||||||
private final SubtitleDescriptor subtitle;
|
private final SubtitleDescriptor subtitle;
|
||||||
private final Language language;
|
private final Language language;
|
||||||
private Download download;
|
private Download download;
|
||||||
|
|
||||||
|
|
||||||
public SubtitlePackage(SubtitleProvider provider, SubtitleDescriptor subtitle) {
|
public SubtitlePackage(SubtitleProvider provider, SubtitleDescriptor subtitle) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
this.subtitle = subtitle;
|
this.subtitle = subtitle;
|
||||||
|
|
||||||
// resolve language name
|
// resolve language name
|
||||||
this.language = new Language(languageCodeByName.get(subtitle.getLanguageName()), subtitle.getLanguageName());
|
this.language = new Language(languageCodeByName.get(subtitle.getLanguageName()), Language.getISO3LanguageCodeByName(subtitle.getLanguageName()), subtitle.getLanguageName());
|
||||||
|
|
||||||
// initialize download worker
|
// initialize download worker
|
||||||
download = new Download(subtitle);
|
download = new Download(subtitle);
|
||||||
|
|
||||||
// forward phase events
|
// forward phase events
|
||||||
download.addPropertyChangeListener(new PropertyChangeListener() {
|
download.addPropertyChangeListener(new PropertyChangeListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
if (evt.getPropertyName().equals("phase")) {
|
if (evt.getPropertyName().equals("phase")) {
|
||||||
|
@ -57,139 +53,119 @@ public class SubtitlePackage {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SubtitleProvider getProvider() {
|
public SubtitleProvider getProvider() {
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return subtitle.getName();
|
return subtitle.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Language getLanguage() {
|
public Language getLanguage() {
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return subtitle.getType();
|
return subtitle.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Download getDownload() {
|
public Download getDownload() {
|
||||||
return download;
|
return download;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
// cancel old download
|
// cancel old download
|
||||||
download.cancel(false);
|
download.cancel(false);
|
||||||
|
|
||||||
// create new download
|
// create new download
|
||||||
Download old = download;
|
Download old = download;
|
||||||
download = new Download(subtitle);
|
download = new Download(subtitle);
|
||||||
|
|
||||||
// transfer listeners
|
// transfer listeners
|
||||||
for (PropertyChangeListener listener : old.getPropertyChangeSupport().getPropertyChangeListeners()) {
|
for (PropertyChangeListener listener : old.getPropertyChangeSupport().getPropertyChangeListeners()) {
|
||||||
old.removePropertyChangeListener(listener);
|
old.removePropertyChangeListener(listener);
|
||||||
download.addPropertyChangeListener(listener);
|
download.addPropertyChangeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
pcs.firePropertyChange("download.phase", old.getPhase(), download.getPhase());
|
pcs.firePropertyChange("download.phase", old.getPhase(), download.getPhase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return subtitle.getName();
|
return subtitle.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final PropertyChangeSupport pcs = new SwingPropertyChangeSupport(this, true);
|
private final PropertyChangeSupport pcs = new SwingPropertyChangeSupport(this, true);
|
||||||
|
|
||||||
|
|
||||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||||
pcs.addPropertyChangeListener(listener);
|
pcs.addPropertyChangeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||||
pcs.removePropertyChangeListener(listener);
|
pcs.removePropertyChangeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Download extends SwingWorker<List<MemoryFile>, Void> {
|
public static class Download extends SwingWorker<List<MemoryFile>, Void> {
|
||||||
|
|
||||||
enum Phase {
|
enum Phase {
|
||||||
PENDING,
|
PENDING, WAITING, DOWNLOADING, EXTRACTING, DONE
|
||||||
WAITING,
|
|
||||||
DOWNLOADING,
|
|
||||||
EXTRACTING,
|
|
||||||
DONE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final SubtitleDescriptor subtitle;
|
private final SubtitleDescriptor subtitle;
|
||||||
|
|
||||||
private Phase current = Phase.PENDING;
|
private Phase current = Phase.PENDING;
|
||||||
|
|
||||||
|
|
||||||
private Download(SubtitleDescriptor descriptor) {
|
private Download(SubtitleDescriptor descriptor) {
|
||||||
this.subtitle = descriptor;
|
this.subtitle = descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
setPhase(Phase.WAITING);
|
setPhase(Phase.WAITING);
|
||||||
|
|
||||||
// enqueue worker
|
// enqueue worker
|
||||||
execute();
|
execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<MemoryFile> doInBackground() throws Exception {
|
protected List<MemoryFile> doInBackground() throws Exception {
|
||||||
setPhase(Phase.DOWNLOADING);
|
setPhase(Phase.DOWNLOADING);
|
||||||
|
|
||||||
// fetch archive
|
// fetch archive
|
||||||
ByteBuffer data = subtitle.fetch();
|
ByteBuffer data = subtitle.fetch();
|
||||||
|
|
||||||
// abort if download has been cancelled
|
// abort if download has been cancelled
|
||||||
if (isCancelled())
|
if (isCancelled())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
setPhase(Phase.EXTRACTING);
|
setPhase(Phase.EXTRACTING);
|
||||||
|
|
||||||
ArchiveType archiveType = ArchiveType.forName(subtitle.getType());
|
ArchiveType archiveType = ArchiveType.forName(subtitle.getType());
|
||||||
|
|
||||||
if (archiveType == ArchiveType.UNKOWN) {
|
if (archiveType == ArchiveType.UNKOWN) {
|
||||||
// cannot extract files from archive
|
// cannot extract files from archive
|
||||||
return singletonList(new MemoryFile(subtitle.getPath(), data));
|
return singletonList(new MemoryFile(subtitle.getPath(), data));
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract contents of the archive
|
// extract contents of the archive
|
||||||
List<MemoryFile> vfs = extract(archiveType, data);
|
List<MemoryFile> vfs = extract(archiveType, data);
|
||||||
|
|
||||||
// if we can't extract files from a rar archive, it might actually be a zip file with the wrong extension
|
// if we can't extract files from a rar archive, it might actually be a zip file with the wrong extension
|
||||||
if (vfs.isEmpty() && archiveType != ArchiveType.ZIP) {
|
if (vfs.isEmpty() && archiveType != ArchiveType.ZIP) {
|
||||||
vfs = extract(ArchiveType.ZIP, data);
|
vfs = extract(ArchiveType.ZIP, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vfs.isEmpty()) {
|
if (vfs.isEmpty()) {
|
||||||
throw new IOException("Cannot extract files from archive");
|
throw new IOException("Cannot extract files from archive");
|
||||||
}
|
}
|
||||||
|
|
||||||
// return file contents
|
// return file contents
|
||||||
return vfs;
|
return vfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<MemoryFile> extract(ArchiveType archiveType, ByteBuffer data) throws IOException {
|
private List<MemoryFile> extract(ArchiveType archiveType, ByteBuffer data) throws IOException {
|
||||||
List<MemoryFile> vfs = new ArrayList<MemoryFile>();
|
List<MemoryFile> vfs = new ArrayList<MemoryFile>();
|
||||||
|
|
||||||
for (MemoryFile file : archiveType.fromData(data)) {
|
for (MemoryFile file : archiveType.fromData(data)) {
|
||||||
if (SUBTITLE_FILES.accept(file.getName())) {
|
if (SUBTITLE_FILES.accept(file.getName())) {
|
||||||
// add subtitle files, ignore non-subtitle files
|
// add subtitle files, ignore non-subtitle files
|
||||||
|
@ -197,59 +173,53 @@ public class SubtitlePackage {
|
||||||
} else {
|
} else {
|
||||||
// check if file is a supported archive
|
// check if file is a supported archive
|
||||||
ArchiveType type = ArchiveType.forName(FileUtilities.getExtension(file.getName()));
|
ArchiveType type = ArchiveType.forName(FileUtilities.getExtension(file.getName()));
|
||||||
|
|
||||||
if (type != ArchiveType.UNKOWN) {
|
if (type != ArchiveType.UNKOWN) {
|
||||||
// extract nested archives recursively
|
// extract nested archives recursively
|
||||||
vfs.addAll(extract(type, file.getData()));
|
vfs.addAll(extract(type, file.getData()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return vfs;
|
return vfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done() {
|
protected void done() {
|
||||||
setPhase(Phase.DONE);
|
setPhase(Phase.DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setPhase(Phase phase) {
|
private void setPhase(Phase phase) {
|
||||||
Phase old = current;
|
Phase old = current;
|
||||||
current = phase;
|
current = phase;
|
||||||
|
|
||||||
firePropertyChange("phase", old, phase);
|
firePropertyChange("phase", old, phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isStarted() {
|
public boolean isStarted() {
|
||||||
return current != Phase.PENDING;
|
return current != Phase.PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Phase getPhase() {
|
public Phase getPhase() {
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map english language name to language code.
|
* Map english language name to language code.
|
||||||
*/
|
*/
|
||||||
private static final Map<String, String> languageCodeByName = mapLanguageCodeByName();
|
private static final Map<String, String> languageCodeByName = mapLanguageCodeByName();
|
||||||
|
|
||||||
|
|
||||||
private static Map<String, String> mapLanguageCodeByName() {
|
private static Map<String, String> mapLanguageCodeByName() {
|
||||||
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName(), Locale.ENGLISH);
|
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName(), Locale.ENGLISH);
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
|
|
||||||
for (String code : bundle.keySet()) {
|
for (String code : bundle.keySet()) {
|
||||||
map.put(bundle.getString(code), code);
|
map.put(bundle.getString(code), code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ import net.sourceforge.filebot.ResourceManager;
|
||||||
import net.sourceforge.filebot.Settings;
|
import net.sourceforge.filebot.Settings;
|
||||||
import net.sourceforge.filebot.WebServices;
|
import net.sourceforge.filebot.WebServices;
|
||||||
import net.sourceforge.filebot.ui.AbstractSearchPanel;
|
import net.sourceforge.filebot.ui.AbstractSearchPanel;
|
||||||
import net.sourceforge.filebot.ui.Language;
|
import net.sourceforge.filebot.Language;
|
||||||
import net.sourceforge.filebot.ui.LanguageComboBox;
|
import net.sourceforge.filebot.ui.LanguageComboBox;
|
||||||
import net.sourceforge.filebot.ui.SelectDialog;
|
import net.sourceforge.filebot.ui.SelectDialog;
|
||||||
import net.sourceforge.filebot.web.OpenSubtitlesClient;
|
import net.sourceforge.filebot.web.OpenSubtitlesClient;
|
||||||
|
|
|
@ -52,7 +52,7 @@ import net.miginfocom.swing.MigLayout;
|
||||||
import net.sourceforge.filebot.Analytics;
|
import net.sourceforge.filebot.Analytics;
|
||||||
import net.sourceforge.filebot.ResourceManager;
|
import net.sourceforge.filebot.ResourceManager;
|
||||||
import net.sourceforge.filebot.media.MediaDetection;
|
import net.sourceforge.filebot.media.MediaDetection;
|
||||||
import net.sourceforge.filebot.ui.Language;
|
import net.sourceforge.filebot.Language;
|
||||||
import net.sourceforge.filebot.ui.LanguageComboBox;
|
import net.sourceforge.filebot.ui.LanguageComboBox;
|
||||||
import net.sourceforge.filebot.ui.SelectDialog;
|
import net.sourceforge.filebot.ui.SelectDialog;
|
||||||
import net.sourceforge.filebot.web.Movie;
|
import net.sourceforge.filebot.web.Movie;
|
||||||
|
@ -423,7 +423,7 @@ public class SubtitleUploadDialog extends JDialog {
|
||||||
icon = ResourceManager.getIcon("database.ok");
|
icon = ResourceManager.getIcon("database.ok");
|
||||||
break;
|
break;
|
||||||
case Identifying:
|
case Identifying:
|
||||||
text = "Auto-detect missing information";
|
text = "Auto-detecting missing information";
|
||||||
icon = ResourceManager.getIcon("action.export");
|
icon = ResourceManager.getIcon("action.export");
|
||||||
break;
|
break;
|
||||||
case IdentificationRequired:
|
case IdentificationRequired:
|
||||||
|
|
Loading…
Reference in New Issue