Search in sources :

Example 1 with NewznabXmlItem

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem in project nzbhydra2 by theotherp.

the class RssMappingTest method shouldParseResponseFromCardigann.

@Test
public void shouldParseResponseFromCardigann() throws Exception {
    NewznabXmlRoot rssRoot = getRssRootFromXml("btnJackettResponse.xml");
    NewznabXmlChannel channel = rssRoot.getRssChannel();
    assertThat(channel.getDescription(), is("Needs no description.."));
    NewznabXmlResponse newznabResponse = channel.getNewznabResponse();
    assertThat(newznabResponse, is(nullValue()));
    List<NewznabXmlItem> items = channel.getItems();
    assertThat(items.size(), is(3));
    NewznabXmlItem item = items.get(0);
    assertThat(item.getTitle(), is("The.Challenge.S30.Special.14.Times.Our.Challengers.Found.Their.Shit.1080p.WEB.x264-CookieMonster"));
    assertThat(item.getRssGuid().getGuid(), is("https://unicasthe.net/torrents.php?action=download&id=799031&authkey=authkey&torrent_pass=torrentPass"));
    assertThat(item.getLink(), startsWith("http://127.0.0.1:9117/dl/unicasthenet/jackettApiKey?path=linkstuff&file=The.Challenge.S30.Special.14.Times.Our.Challengers.Found.Their.Shit.1080p.WEB.x264-CookieMonster.torrent"));
    assertThat(item.getCategory(), is("5000"));
    assertThat(item.getEnclosure().getLength(), is(1459519537L));
    assertThat(item.getTorznabAttributes().size(), is(6));
    assertThat(item.getTorznabAttributes().get(0).getName(), is("rageid"));
    assertThat(item.getTorznabAttributes().get(0).getValue(), is("6126"));
}
Also used : NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) NewznabXmlChannel(org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel) NewznabXmlResponse(org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse) Test(org.junit.Test)

Example 2 with NewznabXmlItem

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem in project nzbhydra2 by theotherp.

the class TorznabMappingTest method testMappingFromXml.

@Test
public void testMappingFromXml() throws Exception {
    NewznabXmlRoot rssRoot = getRssRootFromXml("cardigann.xml");
    NewznabXmlChannel channel = rssRoot.getRssChannel();
    assertThat(channel.getTitle(), is("some-torrents"));
    assertThat(channel.getLink(), is("https://some-torrents.com/"));
    assertThat(channel.getLanguage(), is("en-us"));
    List<NewznabXmlItem> items = channel.getItems();
    assertThat(items.size(), is(2));
    NewznabXmlItem item = items.get(0);
    assertThat(item.getLink(), is("http://127.0.0.1:5060/download/111.torrent"));
    assertThat(item.getPubDate(), is(Instant.ofEpochSecond(1493900064)));
    assertThat(item.getComments(), is("https://some-torrents.com/details.php?id=111&page=0#startcomments"));
    NewznabXmlGuid rssGuid = item.getRssGuid();
    assertThat(rssGuid.getGuid(), is("https://some-torrents.com/details.php?id=111"));
    NewznabXmlEnclosure enclosure = item.getEnclosure();
    assertThat(enclosure.getUrl(), is("http://127.0.0.1:5060/download/111.torrent"));
    List<NewznabAttribute> attributes = item.getTorznabAttributes();
    assertThat(attributes.size(), is(8));
    assertThat(attributes.get(1).getName(), is("seeders"));
    assertThat(attributes.get(1).getValue(), is("11"));
    assertThat(attributes.get(5).getName(), is("size"));
    assertThat(attributes.get(5).getValue(), is("620000000"));
}
Also used : NewznabXmlEnclosure(org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure) NewznabXmlGuid(org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabAttribute(org.nzbhydra.mapping.newznab.xml.NewznabAttribute) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) NewznabXmlChannel(org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel) Test(org.junit.Test)

Example 3 with NewznabXmlItem

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem in project nzbhydra2 by theotherp.

the class NzbIndex method getSearchResultItems.

@Override
protected List<SearchResultItem> getSearchResultItems(NewznabXmlRoot rssRoot) {
    if (rssRoot.getRssChannel().getItems() == null || rssRoot.getRssChannel().getItems().isEmpty()) {
        debug("No results found");
        return Collections.emptyList();
    }
    List<SearchResultItem> items = new ArrayList<>();
    for (NewznabXmlItem rssItem : rssRoot.getRssChannel().getItems()) {
        SearchResultItem item = new SearchResultItem();
        item.setPubDate(rssItem.getPubDate());
        String nzbIndexLink = rssItem.getLink();
        // Use the NZB name as title because it's already somewhat cleaned up
        item.setTitle(nzbIndexLink.substring(nzbIndexLink.lastIndexOf('/') + 1, nzbIndexLink.length() - 4));
        item.setAgePrecise(true);
        item.setGroup(rssItem.getCategory().replace("a.b", "alt.binaries"));
        item.setLink(rssItem.getEnclosure().getUrl());
        item.setSize(rssItem.getEnclosure().getLength());
        Matcher matcher = GUID_PATTERN.matcher(nzbIndexLink);
        boolean found = matcher.find();
        if (!found) {
            logger.error("Unable to parse '{}' result for link. Skipping it", nzbIndexLink);
            continue;
        }
        item.setIndexerGuid(matcher.group(1));
        item.setCategory(categoryProvider.getNotAvailable());
        item.setOriginalCategory("N/A");
        item.setIndexerScore(config.getScore().orElse(0));
        item.setHasNfo(rssItem.getDescription().contains("1 NFO") ? HasNfo.YES : HasNfo.NO);
        item.setIndexer(this);
        item.setDownloadType(DownloadType.NZB);
        items.add(item);
    }
    return items;
}
Also used : Matcher(java.util.regex.Matcher) SearchResultItem(org.nzbhydra.searching.SearchResultItem) ArrayList(java.util.ArrayList) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)

Example 4 with NewznabXmlItem

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem in project nzbhydra2 by theotherp.

the class Anizb method getSearchResultItems.

@Override
protected List<SearchResultItem> getSearchResultItems(NewznabXmlRoot rssRoot) throws IndexerParsingException {
    List<SearchResultItem> items = new ArrayList<>();
    for (NewznabXmlItem rssItem : rssRoot.getRssChannel().getItems()) {
        SearchResultItem item = new SearchResultItem();
        item.setOriginalCategory("Anime");
        item.setTitle(rssItem.getTitle());
        item.setLink(rssItem.getLink());
        item.setIndexerGuid(rssItem.getRssGuid().getGuid());
        item.setSize(rssItem.getEnclosure().getLength());
        item.setPubDate(rssItem.getPubDate());
        item.setIndexerScore(config.getScore().orElse(0));
        item.setHasNfo(HasNfo.NO);
        item.setAgePrecise(true);
        item.setCategory(categoryProvider.getByInternalName("Anime"));
        item.setIndexer(this);
        item.setDownloadType(DownloadType.NZB);
        items.add(item);
    }
    return items;
}
Also used : SearchResultItem(org.nzbhydra.searching.SearchResultItem) ArrayList(java.util.ArrayList) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)

Example 5 with NewznabXmlItem

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem in project nzbhydra2 by theotherp.

the class DevIndexer method getAndStoreResultToDatabase.

protected Xml getAndStoreResultToDatabase(URI uri, IndexerApiAccessType apiAccessType) throws IndexerAccessException {
    NewznabXmlRoot rssRoot = new NewznabXmlRoot();
    if (uri.toString().contains("oneduplicate")) {
        NewznabMockRequest mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("oneresult").titleWords(Collections.emptyList()).total(1).build();
        rssRoot = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getNewznabResponse().setTotal(1);
        rssRoot.getRssChannel().getItems().get(0).getEnclosure().setLength(100000L);
        rssRoot.getRssChannel().getItems().get(0).getNewznabAttributes().clear();
    } else if (uri.toString().contains("duplicatesandtitlegroups")) {
        // One duplicate
        NewznabMockRequest mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("oneresult").titleWords(Collections.emptyList()).total(1).build();
        rssRoot = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getItems().get(0).getEnclosure().setLength(100000L);
        rssRoot.getRssChannel().getItems().get(0).getNewznabAttributes().clear();
        rssRoot.getRssChannel().getItems().get(0).getTorznabAttributes().clear();
        rssRoot.getRssChannel().getItems().get(0).getNewznabAttributes().add(new NewznabAttribute("grabs", "100"));
        // Another duplicate in the same title group
        mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("oneresult").titleWords(Collections.emptyList()).total(1).build();
        NewznabXmlRoot rssRoot3 = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot3.getRssChannel().getItems().get(0).getEnclosure().setLength(200000L);
        rssRoot3.getRssChannel().getItems().get(0).getNewznabAttributes().clear();
        rssRoot3.getRssChannel().getItems().get(0).getTorznabAttributes().clear();
        rssRoot3.getRssChannel().getItems().get(0).getNewznabAttributes().add(new NewznabAttribute("grabs", "2000"));
        // Otherwise it will result in a unique key exception
        rssRoot3.getRssChannel().getItems().get(0).setLink("anotherlink");
        rssRoot.getRssChannel().getItems().add(rssRoot3.getRssChannel().getItems().get(0));
        // Will be a grouped title but have no duplicates
        mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("anotherresult").titleWords(Collections.emptyList()).total(1).build();
        NewznabXmlRoot rssRoot2 = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getItems().add(rssRoot2.getRssChannel().getItems().get(0));
        rssRoot.getRssChannel().getNewznabResponse().setTotal(3);
    } else if (uri.toString().contains("duplicates")) {
        NewznabMockRequest mockRequest = NewznabMockRequest.builder().numberOfResults(10).titleBase("duplicates").titleWords(Collections.emptyList()).total(10).build();
        rssRoot = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getNewznabResponse().setTotal(10);
        for (NewznabXmlItem rssItem : rssRoot.getRssChannel().getItems()) {
            rssItem.getEnclosure().setLength(100000L);
            rssItem.getNewznabAttributes().clear();
            rssItem.setPubDate(Instant.now());
            rssItem.setDescription("Indexer: " + getName() + ", title:" + rssItem.getTitle());
        }
    } else if (uri.toString().contains("tworesults")) {
        rssRoot = NewznabMockBuilder.generateResponse(0, 2, "results", false, Collections.emptyList());
        rssRoot.getRssChannel().getNewznabResponse().setTotal(2);
    } else {
        rssRoot = NewznabMockBuilder.generateResponse(0, 100, "results", false, Collections.emptyList());
        rssRoot.getRssChannel().getNewznabResponse().setTotal(100);
    }
    if (uri.toString().contains("punkte")) {
        rssRoot.getRssChannel().getItems().get(0).setTitle("a a");
        rssRoot.getRssChannel().getItems().get(1).setTitle("ab");
        rssRoot.getRssChannel().getItems().get(2).setTitle("a.c");
    }
    return rssRoot;
}
Also used : NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabMockRequest(org.nzbhydra.mapping.newznab.mock.NewznabMockRequest) NewznabAttribute(org.nzbhydra.mapping.newznab.xml.NewznabAttribute) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)

Aggregations

NewznabXmlItem (org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)17 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)11 NewznabAttribute (org.nzbhydra.mapping.newznab.xml.NewznabAttribute)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)7 MockResponse (okhttp3.mockwebserver.MockResponse)6 Dispatcher (okhttp3.mockwebserver.Dispatcher)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 NewznabXmlChannel (org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel)4 NewznabXmlEnclosure (org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure)4 NewznabXmlGuid (org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid)4 Matcher (java.util.regex.Matcher)3 NewznabXmlResponse (org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)3 SearchResultItem (org.nzbhydra.searching.SearchResultItem)3 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)2 NzbhydraMockMvcTest (org.nzbhydra.tests.NzbhydraMockMvcTest)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1