1
0
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:
Reinhard Pointner 2009-08-18 16:15:58 +00:00
parent ab18c0f61d
commit 333b362da0
4 changed files with 29 additions and 22 deletions

View File

@ -36,7 +36,7 @@ public final class Settings {
// special handling for web start // special handling for web start
if (System.getProperty("javawebstart.version") != null) { if (System.getProperty("javawebstart.version") != null) {
// can't use working directory for web start applications // 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 // create folder if necessary
if (!folder.exists()) { if (!folder.exists()) {

View File

@ -14,7 +14,6 @@ public class SubStationAlphaReader extends SubtitleReader {
private final DateFormat timeFormat = new SubtitleTimeFormat(); private final DateFormat timeFormat = new SubtitleTimeFormat();
private final Pattern newline = Pattern.compile(Pattern.quote("\\n"), Pattern.CASE_INSENSITIVE); private final Pattern newline = Pattern.compile(Pattern.quote("\\n"), Pattern.CASE_INSENSITIVE);
private final Pattern tag = Pattern.compile("[{]\\\\[^}]+[}]"); private final Pattern tag = Pattern.compile("[{]\\\\[^}]+[}]");
private final Pattern separator = Pattern.compile("\\s*,\\s*");
private String[] format; private String[] format;
private int formatIndexStart; private int formatIndexStart;
@ -36,12 +35,17 @@ public class SubStationAlphaReader extends SubtitleReader {
throw new InputMismatchException("Illegal format header: " + Arrays.toString(event)); throw new InputMismatchException("Illegal format header: " + Arrays.toString(event));
// read columns // 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); List<String> lookup = Arrays.asList(format);
formatIndexStart = lookup.indexOf("Start"); formatIndexStart = lookup.indexOf("start");
formatIndexEnd = lookup.indexOf("End"); formatIndexEnd = lookup.indexOf("end");
formatIndexText = lookup.indexOf("Text"); formatIndexText = lookup.indexOf("text");
} }
@ -71,11 +75,11 @@ public class SubStationAlphaReader extends SubtitleReader {
throw new InputMismatchException("Illegal dialogue event: " + Arrays.toString(event)); throw new InputMismatchException("Illegal dialogue event: " + Arrays.toString(event));
// extract information // 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 start = timeFormat.parse(values[formatIndexStart].trim()).getTime();
long end = timeFormat.parse(values[formatIndexEnd]).getTime(); long end = timeFormat.parse(values[formatIndexEnd].trim()).getTime();
String text = values[formatIndexText]; String text = values[formatIndexText].trim();
return new SubtitleElement(start, end, resolve(text)); return new SubtitleElement(start, end, resolve(text));
} }

View File

@ -63,7 +63,7 @@ class RarArchive implements Iterable<MemoryFile> {
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
// ignore, there seems to be bug with JUnRar allocating lots of memory for no apparent reason // 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 // @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) { } catch (RarException e) {

View File

@ -3,6 +3,7 @@ package net.sourceforge.filebot.web;
import static net.sourceforge.filebot.web.EpisodeListUtilities.*; import static net.sourceforge.filebot.web.EpisodeListUtilities.*;
import static net.sourceforge.filebot.web.WebRequest.*;
import static net.sourceforge.tuned.XPathUtilities.*; import static net.sourceforge.tuned.XPathUtilities.*;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -78,8 +79,8 @@ public class TheTVDBClient implements EpisodeListProvider {
public List<SearchResult> search(String query, Locale language) throws Exception { public List<SearchResult> search(String query, Locale language) throws Exception {
URL url = getResource(null, "/api/GetSeries.php?seriesname=" + URLEncoder.encode(query, "UTF-8") + "&language=" + language.getLanguage());
Document dom = getXmlDocument("/api/GetSeries.php?seriesname=" + URLEncoder.encode(query, "UTF-8") + "&language=" + language.getLanguage()); Document dom = getDocument(url);
List<Node> nodes = selectNodes("Data/Series", dom); List<Node> nodes = selectNodes("Data/Series", dom);
List<SearchResult> searchResults = new ArrayList<SearchResult>(nodes.size()); 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 { public List<Episode> getEpisodeList(TheTVDBSearchResult searchResult, Locale language) throws Exception {
List<Episode> episodes = cache.getEpisodeList(searchResult.getSeriesId(), language); List<Episode> episodes = cache.getEpisodeList(searchResult.getSeriesId(), language);
if (episodes != null) if (episodes != null)
@ -156,8 +156,7 @@ public class TheTVDBClient implements EpisodeListProvider {
public Document getSeriesRecord(TheTVDBSearchResult searchResult, Locale language) throws Exception { public Document getSeriesRecord(TheTVDBSearchResult searchResult, Locale language) throws Exception {
URL seriesRecord = getResource(MirrorType.ZIP, "/api/" + apikey + "/series/" + searchResult.getSeriesId() + "/all/" + language.getLanguage() + ".zip");
URL seriesRecord = new URL(getMirror(MirrorType.ZIP) + "/api/" + apikey + "/series/" + searchResult.getSeriesId() + "/all/" + language.getLanguage() + ".zip");
ZipInputStream zipInputStream = new ZipInputStream(seriesRecord.openStream()); ZipInputStream zipInputStream = new ZipInputStream(seriesRecord.openStream());
ZipEntry zipEntry; ZipEntry zipEntry;
@ -196,10 +195,10 @@ public class TheTVDBClient implements EpisodeListProvider {
if (seasonId == null) { if (seasonId == null) {
// get episode xml from first episode of given season // 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)); seasonId = Integer.valueOf(selectString("Data/Episode/seasonid", dom));
cache.putSeasonId(seriesId, season, seasonId); cache.putSeasonId(seriesId, season, seasonId);
} }
@ -217,7 +216,7 @@ public class TheTVDBClient implements EpisodeListProvider {
synchronized (mirrors) { synchronized (mirrors) {
if (mirrors.isEmpty()) { if (mirrors.isEmpty()) {
// initialize mirrors // initialize mirrors
Document dom = getXmlDocument("/api/" + apikey + "/mirrors.xml"); Document dom = getDocument(getResource(null, "/api/" + apikey + "/mirrors.xml"));
// all mirrors by type // all mirrors by type
Map<MirrorType, List<String>> mirrorListMap = new EnumMap<MirrorType, List<String>>(MirrorType.class); 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 { protected URL getResource(MirrorType mirrorType, String path) throws Exception {
URL url = new URL("http", host, path); // use default server
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openStream()); if (mirrorType == null)
return new URL("http", host, path);
// use mirror
return new URL(getMirror(mirrorType) + path);
} }