mirror of
https://github.com/mitb-archive/filebot
synced 2025-01-11 05:48:01 -05:00
* drop SubtitleSource related code as they now restrict access to their api
This commit is contained in:
parent
13a1b3fa6a
commit
270a0409ca
Binary file not shown.
Before Width: | Height: | Size: 22 KiB |
@ -11,7 +11,6 @@ import net.sourceforge.filebot.web.OpenSubtitlesClient;
|
||||
import net.sourceforge.filebot.web.SublightSubtitleClient;
|
||||
import net.sourceforge.filebot.web.SubsceneSubtitleClient;
|
||||
import net.sourceforge.filebot.web.SubtitleProvider;
|
||||
import net.sourceforge.filebot.web.SubtitleSourceClient;
|
||||
import net.sourceforge.filebot.web.TVDotComClient;
|
||||
import net.sourceforge.filebot.web.TVRageClient;
|
||||
import net.sourceforge.filebot.web.TheTVDBClient;
|
||||
@ -34,7 +33,6 @@ public final class WebServices {
|
||||
public static final OpenSubtitlesClient OpenSubtitles = new OpenSubtitlesClient(String.format("%s %s", getApplicationName(), getApplicationVersion()));
|
||||
public static final SublightSubtitleClient Sublight = new SublightSubtitleClient(getApplicationName(), getApplicationProperty("sublight.apikey"));
|
||||
public static final SubsceneSubtitleClient Subscene = new SubsceneSubtitleClient();
|
||||
public static final SubtitleSourceClient SubtitleSource = new SubtitleSourceClient();
|
||||
|
||||
|
||||
public static EpisodeListProvider[] getEpisodeListProviders() {
|
||||
@ -43,7 +41,7 @@ public final class WebServices {
|
||||
|
||||
|
||||
public static SubtitleProvider[] getSubtitleProviders() {
|
||||
return new SubtitleProvider[] { OpenSubtitles, Subscene, Sublight, SubtitleSource };
|
||||
return new SubtitleProvider[] { OpenSubtitles, Subscene, Sublight };
|
||||
}
|
||||
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 550 B |
@ -1,144 +0,0 @@
|
||||
|
||||
package net.sourceforge.filebot.web;
|
||||
|
||||
|
||||
import static net.sourceforge.filebot.web.WebRequest.*;
|
||||
import static net.sourceforge.tuned.XPathUtilities.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
|
||||
|
||||
public class SubtitleSourceClient implements SubtitleProvider {
|
||||
|
||||
private static final String host = "www.subtitlesource.org";
|
||||
|
||||
private static final int pageSize = 20;
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SubtitleSource";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public URI getLink() {
|
||||
return URI.create("http://www.subtitlesource.org");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("search.subtitlesource");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SearchResult> search(String query) throws Exception {
|
||||
return search(query, "all");
|
||||
}
|
||||
|
||||
|
||||
public List<SearchResult> search(String query, String language) throws Exception {
|
||||
// e.g. http://www.subtitlesource.org/api/xmlsearch/firefly/all/0
|
||||
URL url = new URL("http", host, "/api/xmlsearch/" + URLEncoder.encode(query, "utf-8") + "/" + language + "/0");
|
||||
|
||||
Document dom = getDocument(url);
|
||||
|
||||
Map<Integer, MovieDescriptor> movieMap = new LinkedHashMap<Integer, MovieDescriptor>();
|
||||
|
||||
for (Node node : selectNodes("//sub", dom)) {
|
||||
Integer imdb = Integer.valueOf(getTextContent("imdb", node));
|
||||
|
||||
if (!movieMap.containsKey(imdb)) {
|
||||
String title = getTextContent("title", node);
|
||||
String year = getTextContent("year", node);
|
||||
|
||||
movieMap.put(imdb, new MovieDescriptor(title, Integer.parseInt(year), imdb));
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<SearchResult>(movieMap.values());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SubtitleDescriptor> getSubtitleList(SearchResult searchResult, String languageName) throws Exception {
|
||||
List<SubtitleDescriptor> subtitles = new ArrayList<SubtitleDescriptor>();
|
||||
|
||||
for (SubtitleDescriptor subtitle : getSubtitleList(searchResult)) {
|
||||
if (languageName == null || languageName.equalsIgnoreCase(subtitle.getLanguageName())) {
|
||||
subtitles.add(subtitle);
|
||||
}
|
||||
}
|
||||
|
||||
return subtitles;
|
||||
}
|
||||
|
||||
|
||||
public List<SubtitleDescriptor> getSubtitleList(SearchResult searchResult) throws Exception {
|
||||
List<SubtitleDescriptor> subtitles = new ArrayList<SubtitleDescriptor>();
|
||||
|
||||
for (int offset = 0; true; offset += pageSize) {
|
||||
List<SubtitleDescriptor> page = getSubtitleList(searchResult, offset);
|
||||
|
||||
// add new subtitles
|
||||
subtitles.addAll(page);
|
||||
|
||||
if (page.size() < pageSize) {
|
||||
// last page reached
|
||||
return subtitles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<SubtitleDescriptor> getSubtitleList(SearchResult searchResult, int offset) throws Exception {
|
||||
int imdb = ((MovieDescriptor) searchResult).getImdbId();
|
||||
|
||||
// e.g. http://www.subtitlesource.org/api/xmlsearch/0303461/imdb/0
|
||||
URL url = new URL("http", host, "/api/xmlsearch/" + imdb + "/imdb/" + offset);
|
||||
|
||||
Document dom = getDocument(url);
|
||||
|
||||
List<SubtitleDescriptor> subtitles = new ArrayList<SubtitleDescriptor>();
|
||||
|
||||
for (Node node : selectNodes("//sub", dom)) {
|
||||
int id = Integer.parseInt(getTextContent("id", node));
|
||||
String releaseName = getTextContent("releasename", node);
|
||||
String language = getTextContent("language", node);
|
||||
String title = getTextContent("title", node);
|
||||
int season = Integer.parseInt(getTextContent("season", node));
|
||||
int episode = Integer.parseInt(getTextContent("episode", node));
|
||||
|
||||
// e.g. http://www.subtitlesource.org/download/zip/760
|
||||
URL downloadLink = new URL("http", host, "/download/zip/" + id);
|
||||
|
||||
subtitles.add(new SubtitleSourceSubtitleDescriptor(releaseName, language, title, season, episode, downloadLink));
|
||||
}
|
||||
|
||||
return subtitles;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public URI getSubtitleListLink(SearchResult searchResult, String languageName) {
|
||||
int imdb = ((MovieDescriptor) searchResult).getImdbId();
|
||||
|
||||
return URI.create("http://" + host + "/title/" + String.format("tt%07d", imdb));
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
|
||||
package net.sourceforge.filebot.web;
|
||||
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
public class SubtitleSourceSubtitleDescriptor implements SubtitleDescriptor {
|
||||
|
||||
private final String releaseName;
|
||||
private final String language;
|
||||
|
||||
private final String title;
|
||||
private final int season;
|
||||
private final int episode;
|
||||
|
||||
private final URL downloadLink;
|
||||
|
||||
|
||||
public SubtitleSourceSubtitleDescriptor(String releaseName, String language, String title, int season, int episode, URL downloadLink) {
|
||||
this.releaseName = releaseName;
|
||||
this.language = language;
|
||||
this.title = title;
|
||||
this.season = season;
|
||||
this.episode = episode;
|
||||
this.downloadLink = downloadLink;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (releaseName == null || releaseName.isEmpty()) {
|
||||
if (season == 0 && episode == 0) {
|
||||
return title;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(title).append(" - ");
|
||||
|
||||
if (season != 0) {
|
||||
sb.append(season);
|
||||
|
||||
if (episode != 0) {
|
||||
sb.append("x").append(episode);
|
||||
}
|
||||
} else {
|
||||
// episode cannot be 0 at this point
|
||||
sb.append(episode);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return releaseName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getLanguageName() {
|
||||
return language;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "zip";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ByteBuffer fetch() throws Exception {
|
||||
return WebRequest.fetch(downloadLink);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s [%s]", getName(), getLanguageName());
|
||||
}
|
||||
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
|
||||
package net.sourceforge.filebot.web;
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class SubtitleSourceClientTest {
|
||||
|
||||
private static final SubtitleSourceClient client = new SubtitleSourceClient();
|
||||
|
||||
|
||||
@Test
|
||||
public void search() throws Exception {
|
||||
List<SearchResult> list = client.search("babylon 5");
|
||||
|
||||
MovieDescriptor sample = (MovieDescriptor) list.get(0);
|
||||
|
||||
// check sample entry
|
||||
assertEquals("Babylon 5", sample.getName());
|
||||
assertEquals(105946, sample.getImdbId());
|
||||
|
||||
// check page size
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getSubtitleListAll() throws Exception {
|
||||
List<SubtitleDescriptor> list = client.getSubtitleList(new MovieDescriptor("Buffy", 1997, 118276), "English");
|
||||
|
||||
SubtitleDescriptor sample = list.get(0);
|
||||
|
||||
// check sample entry (order is unpredictable)
|
||||
assertTrue(sample.getName().startsWith("Buffy"));
|
||||
assertEquals("English", sample.getLanguageName());
|
||||
|
||||
// check size
|
||||
assertTrue(list.size() > 100);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getSubtitleListSinglePage() throws Exception {
|
||||
List<SubtitleDescriptor> list = client.getSubtitleList(new MovieDescriptor("Firefly", 2002, 303461), 0);
|
||||
|
||||
SubtitleDescriptor sample = list.get(0);
|
||||
|
||||
// check sample entry (order is unpredictable)
|
||||
assertTrue(sample.getName().startsWith("Firefly"));
|
||||
|
||||
// check page size
|
||||
assertEquals(20, list.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getSubtitleListLink() {
|
||||
assertEquals("http://www.subtitlesource.org/title/tt0303461", client.getSubtitleListLink(new MovieDescriptor("Firefly", 2002, 303461), null).toString());
|
||||
}
|
||||
}
|
@ -8,8 +8,8 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses( { TVDotComClientTest.class, AnidbClientTest.class, TVRageClientTest.class, TheTVDBClientTest.class, TMDbClientTest.class, IMDbClientTest.class, SubsceneSubtitleClientTest.class, SubtitleSourceClientTest.class,
|
||||
SublightSubtitleClientTest.class, OpenSubtitlesXmlRpcTest.class })
|
||||
@SuiteClasses( { TVDotComClientTest.class, AnidbClientTest.class, TVRageClientTest.class, TheTVDBClientTest.class, TMDbClientTest.class, IMDbClientTest.class, SubsceneSubtitleClientTest.class, SublightSubtitleClientTest.class,
|
||||
OpenSubtitlesXmlRpcTest.class })
|
||||
public class WebTestSuite {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user