<commit_before>package sb.tasks.jobs.trupd;

import com.jcabi.http.request.JdkRequest;
import com.jcabi.http.response.JsoupResponse;
import com.jcabi.http.response.XmlResponse;
import com.jcabi.http.wire.CookieOptimizingWire;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import sb.tasks.jobs.Agent;
import sb.tasks.jobs.trupd.metafile.Metafile;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class AnLostFilm implements Agent<TrNotif> {

    private final org.bson.Document document;
    private final String session;
    private final String uid;
    private final String quality;

    public AnLostFilm(org.bson.Document document, String session, String uid, String quality) {
        this.document = document;
        this.session = session;
        this.uid = uid;
        this.quality = quality;
    }

    private String name(Document document) throws IOException {
        for (Element item : document.getElementsByClass("inner-box--item")) {
            if (item.getElementsByClass("inner-box--label").get(0).text().equals(quality)) {
                return item
                        .getElementsByClass("main").get(0)
                        .getElementsByTag("a").get(0)
                        .text();
            }
        }
        throw new IOException("Name not parsed");
    }

    private String torrentUrl(Document document) throws IOException {
        for (Element item : document.getElementsByClass("inner-box--item")) {
            if (item.getElementsByClass("inner-box--label").get(0).text().equals(quality)) {
                return item
                        .getElementsByClass("main").get(0)
                        .getElementsByTag("a").get(0)
                        .attr("href");
            }
        }
        throw new IOException("URL not found");
    }

    @Override
    public List<TrNotif> perform() throws IOException {
        List<String> items = new LfRequest(new JdkRequest("http://lostfilm.tv/rss.xml"))
                .fetch()
                .as(XmlResponse.class)
                .xml()
                .xpath("//item/link/text()");
        for (String str : items) {
            if (str.startsWith(document.getString("url"))) {
                Document root = Jsoup.parse(
                        new LfRequest(new JdkRequest(str)).fetch().as(JsoupResponse.class).body(),
                        document.getString("url")
                );
                Matcher m = Pattern.compile("PlayEpisode\\('(\\d+)','(\\d+)','(\\d+)'\\)")
                        .matcher(
                                root.getElementsByClass("external-btn").attr("onclick")
                        );<commit_msg>func fix<commit_after>package sb.tasks.jobs.trupd;

import com.jcabi.http.request.JdkRequest;
import com.jcabi.http.response.JsoupResponse;
import com.jcabi.http.response.XmlResponse;
import com.jcabi.http.wire.CookieOptimizingWire;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import sb.tasks.jobs.Agent;
import sb.tasks.jobs.trupd.metafile.Metafile;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class AnLostFilm implements Agent<TrNotif> {

    private final org.bson.Document document;
    private final String session;
    private final String uid;
    private final String quality;

    public AnLostFilm(org.bson.Document document, String session, String uid, String quality) {
        this.document = document;
        this.session = session;
        this.uid = uid;
        this.quality = quality;
    }

    private String name(Document document) throws IOException {
        for (Element item : document.getElementsByClass("inner-box--item")) {
            if (item.getElementsByClass("inner-box--label").get(0).text().equals(quality)) {
                return item
                        .getElementsByClass("main").get(0)
                        .getElementsByTag("a").get(0)
                        .text();
            }
        }
        throw new IOException("Name not parsed");
    }

    private String torrentUrl(Document document) throws IOException {
        for (Element item : document.getElementsByClass("inner-box--item")) {
            if (item.getElementsByClass("inner-box--label").get(0).text().equals(quality)) {
                return item
                        .getElementsByClass("main").get(0)
                        .getElementsByTag("a").get(0)
                        .attr("href");
            }
        }
        throw new IOException("URL not found");
    }

    @Override
    public List<TrNotif> perform() throws IOException {
        List<String> items = new LfRequest(new JdkRequest("http://lostfilm.tv/rss.xml"))
                .fetch()
                .as(XmlResponse.class)
                .xml()
                .xpath("//item/link/text()");
        for (String str : items) {
            if (str.startsWith(document.getString("url"))) {
                Document root = Jsoup.parse(
                        new LfRequest(new JdkRequest(str)).fetch().as(JsoupResponse.class).body(),
                        document.getString("url")
                );
                Matcher m = Pattern.compile("PlayEpisode\\('(\\d{3})(\\d{3})(\\d{3})'\\)")
                        .matcher(
                                root.getElementsByClass("external-btn").attr("onclick")
                        );
{'fraction_non_alphanumeric': 0.12640399358174362, 'fraction_numerical': 0.002674273489035479, 'mean_word_length': 2.0226293103448274, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6298', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1503, 'n_words': 293}