mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 16:28:51 -05:00
* use http gzip compression in TheTVDBClient if possible
* minor refactoring
This commit is contained in:
parent
ab18c0f61d
commit
333b362da0
@ -36,7 +36,7 @@ public final class Settings {
|
||||
// special handling for web start
|
||||
if (System.getProperty("javawebstart.version") != null) {
|
||||
// can't use working directory for web start applications
|
||||
File folder = new File(System.getProperty("user.home"), ".filebot");
|
||||
File folder = new File(System.getProperty("user.home"), "." + getApplicationName().toLowerCase());
|
||||
|
||||
// create folder if necessary
|
||||
if (!folder.exists()) {
|
||||
|
@ -14,7 +14,6 @@ public class SubStationAlphaReader extends SubtitleReader {
|
||||
private final DateFormat timeFormat = new SubtitleTimeFormat();
|
||||
private final Pattern newline = Pattern.compile(Pattern.quote("\\n"), Pattern.CASE_INSENSITIVE);
|
||||
private final Pattern tag = Pattern.compile("[{]\\\\[^}]+[}]");
|
||||
private final Pattern separator = Pattern.compile("\\s*,\\s*");
|
||||
|
||||
private String[] format;
|
||||
private int formatIndexStart;
|
||||
@ -36,12 +35,17 @@ public class SubStationAlphaReader extends SubtitleReader {
|
||||
throw new InputMismatchException("Illegal format header: " + Arrays.toString(event));
|
||||
|
||||
// read columns
|
||||
format = separator.split(event[1]);
|
||||
format = event[1].split(",");
|
||||
|
||||
// normalize column names
|
||||
for (int i = 0; i < format.length; i++) {
|
||||
format[i] = format[i].trim().toLowerCase();
|
||||
}
|
||||
|
||||
List<String> lookup = Arrays.asList(format);
|
||||
formatIndexStart = lookup.indexOf("Start");
|
||||
formatIndexEnd = lookup.indexOf("End");
|
||||
formatIndexText = lookup.indexOf("Text");
|
||||
formatIndexStart = lookup.indexOf("start");
|
||||
formatIndexEnd = lookup.indexOf("end");
|
||||
formatIndexText = lookup.indexOf("text");
|
||||
}
|
||||
|
||||
|
||||
@ -71,11 +75,11 @@ public class SubStationAlphaReader extends SubtitleReader {
|
||||
throw new InputMismatchException("Illegal dialogue event: " + Arrays.toString(event));
|
||||
|
||||
// extract information
|
||||
String[] values = separator.split(event[1], format.length);
|
||||
String[] values = event[1].split(",", format.length);
|
||||
|
||||
long start = timeFormat.parse(values[formatIndexStart]).getTime();
|
||||
long end = timeFormat.parse(values[formatIndexEnd]).getTime();
|
||||
String text = values[formatIndexText];
|
||||
long start = timeFormat.parse(values[formatIndexStart].trim()).getTime();
|
||||
long end = timeFormat.parse(values[formatIndexEnd].trim()).getTime();
|
||||
String text = values[formatIndexText].trim();
|
||||
|
||||
return new SubtitleElement(start, end, resolve(text));
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class RarArchive implements Iterable<MemoryFile> {
|
||||
} catch (OutOfMemoryError e) {
|
||||
// ignore, there seems to be bug with JUnRar allocating lots of memory for no apparent reason
|
||||
// @see https://sourceforge.net/forum/forum.php?thread_id=2773018&forum_id=706772
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Cannot extract " + header.getFileNameString());
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to extract " + header.getFileNameString(), e);
|
||||
}
|
||||
}
|
||||
} catch (RarException e) {
|
||||
|
@ -3,6 +3,7 @@ package net.sourceforge.filebot.web;
|
||||
|
||||
|
||||
import static net.sourceforge.filebot.web.EpisodeListUtilities.*;
|
||||
import static net.sourceforge.filebot.web.WebRequest.*;
|
||||
import static net.sourceforge.tuned.XPathUtilities.*;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@ -78,8 +79,8 @@ public class TheTVDBClient implements EpisodeListProvider {
|
||||
|
||||
|
||||
public List<SearchResult> search(String query, Locale language) throws Exception {
|
||||
|
||||
Document dom = getXmlDocument("/api/GetSeries.php?seriesname=" + URLEncoder.encode(query, "UTF-8") + "&language=" + language.getLanguage());
|
||||
URL url = getResource(null, "/api/GetSeries.php?seriesname=" + URLEncoder.encode(query, "UTF-8") + "&language=" + language.getLanguage());
|
||||
Document dom = getDocument(url);
|
||||
|
||||
List<Node> nodes = selectNodes("Data/Series", dom);
|
||||
List<SearchResult> searchResults = new ArrayList<SearchResult>(nodes.size());
|
||||
@ -115,7 +116,6 @@ public class TheTVDBClient implements EpisodeListProvider {
|
||||
|
||||
|
||||
public List<Episode> getEpisodeList(TheTVDBSearchResult searchResult, Locale language) throws Exception {
|
||||
|
||||
List<Episode> episodes = cache.getEpisodeList(searchResult.getSeriesId(), language);
|
||||
|
||||
if (episodes != null)
|
||||
@ -156,8 +156,7 @@ public class TheTVDBClient implements EpisodeListProvider {
|
||||
|
||||
|
||||
public Document getSeriesRecord(TheTVDBSearchResult searchResult, Locale language) throws Exception {
|
||||
|
||||
URL seriesRecord = new URL(getMirror(MirrorType.ZIP) + "/api/" + apikey + "/series/" + searchResult.getSeriesId() + "/all/" + language.getLanguage() + ".zip");
|
||||
URL seriesRecord = getResource(MirrorType.ZIP, "/api/" + apikey + "/series/" + searchResult.getSeriesId() + "/all/" + language.getLanguage() + ".zip");
|
||||
|
||||
ZipInputStream zipInputStream = new ZipInputStream(seriesRecord.openStream());
|
||||
ZipEntry zipEntry;
|
||||
@ -196,10 +195,10 @@ public class TheTVDBClient implements EpisodeListProvider {
|
||||
|
||||
if (seasonId == null) {
|
||||
// get episode xml from first episode of given season
|
||||
Document dom = getXmlDocument("/api/" + apikey + "/series/" + seriesId + "/default/" + season + "/1/en.xml");
|
||||
URL url = getResource(MirrorType.XML, "/api/" + apikey + "/series/" + seriesId + "/default/" + season + "/1/en.xml");
|
||||
Document dom = getDocument(url);
|
||||
|
||||
seasonId = Integer.valueOf(selectString("Data/Episode/seasonid", dom));
|
||||
|
||||
cache.putSeasonId(seriesId, season, seasonId);
|
||||
}
|
||||
|
||||
@ -217,7 +216,7 @@ public class TheTVDBClient implements EpisodeListProvider {
|
||||
synchronized (mirrors) {
|
||||
if (mirrors.isEmpty()) {
|
||||
// initialize mirrors
|
||||
Document dom = getXmlDocument("/api/" + apikey + "/mirrors.xml");
|
||||
Document dom = getDocument(getResource(null, "/api/" + apikey + "/mirrors.xml"));
|
||||
|
||||
// all mirrors by type
|
||||
Map<MirrorType, List<String>> mirrorListMap = new EnumMap<MirrorType, List<String>>(MirrorType.class);
|
||||
@ -256,9 +255,13 @@ public class TheTVDBClient implements EpisodeListProvider {
|
||||
}
|
||||
|
||||
|
||||
protected Document getXmlDocument(String path) throws Exception {
|
||||
URL url = new URL("http", host, path);
|
||||
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openStream());
|
||||
protected URL getResource(MirrorType mirrorType, String path) throws Exception {
|
||||
// use default server
|
||||
if (mirrorType == null)
|
||||
return new URL("http", host, path);
|
||||
|
||||
// use mirror
|
||||
return new URL(getMirror(mirrorType) + path);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user