Handle current translation based on seasons box
This commit is contained in:
@ -63,7 +63,7 @@ public class MetadataController {
|
|||||||
String url = responseResult.getLink();
|
String url = responseResult.getLink();
|
||||||
return extractService.getMetadata(url);
|
return extractService.getMetadata(url);
|
||||||
} catch (KodikExtractionException e) {
|
} catch (KodikExtractionException e) {
|
||||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "cannot retrieve metadat", e);
|
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "cannot retrieve metadata", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "i/o error");
|
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "i/o error");
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@ package com.backend.extractor.kodik.service.anyame_backend.service;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
@ -19,6 +22,8 @@ import com.backend.extractor.kodik.service.anyame_backend.service.model.KodikMet
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class KodikHtmlParserService {
|
public class KodikHtmlParserService {
|
||||||
|
private static final Pattern VIDEO_INFO_TYPE = Pattern.compile("https://kodik\\.info/([^\\s/]+)");
|
||||||
|
|
||||||
public KodikMetadata parseMetadata(String html) {
|
public KodikMetadata parseMetadata(String html) {
|
||||||
Document doc = Jsoup.parse(html);
|
Document doc = Jsoup.parse(html);
|
||||||
|
|
||||||
@ -32,9 +37,9 @@ public class KodikHtmlParserService {
|
|||||||
|
|
||||||
private List<KodikTranslation> parseTranslations(Document doc) {
|
private List<KodikTranslation> parseTranslations(Document doc) {
|
||||||
List<KodikTranslation> translations = new ArrayList<>();
|
List<KodikTranslation> translations = new ArrayList<>();
|
||||||
Elements options = doc.select(".serial-translations-box select option");
|
Elements translationOptions = doc.select(".serial-translations-box select option");
|
||||||
|
|
||||||
for (Element option : options) {
|
for (Element option : translationOptions) {
|
||||||
String id = option.attr("value");
|
String id = option.attr("value");
|
||||||
String title = option.attr("data-title");
|
String title = option.attr("data-title");
|
||||||
String mediaId = option.attr("data-media-id");
|
String mediaId = option.attr("data-media-id");
|
||||||
@ -47,6 +52,20 @@ public class KodikHtmlParserService {
|
|||||||
mediaType, translationType, episodeCount));
|
mediaType, translationType, episodeCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Elements seasonOptions = doc.select(".serial-seasons-box select option");
|
||||||
|
Elements seriesOptions = doc.select(".serial-series-box select option");
|
||||||
|
for (Element option : seasonOptions) {
|
||||||
|
if (!option.hasAttr("selected")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String id = option.attr("value");
|
||||||
|
String title = option.attr("data-translation-title");
|
||||||
|
String mediaId = option.attr("data-serial-id");
|
||||||
|
String mediaHash = option.attr("data-serial-hash");
|
||||||
|
String mediaType = findVideoType(doc.html()).orElse("serial");
|
||||||
|
translations.add(new KodikTranslation(id, title, mediaId, mediaHash, mediaType, "", seriesOptions.size()));
|
||||||
|
}
|
||||||
|
|
||||||
return translations;
|
return translations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +86,11 @@ public class KodikHtmlParserService {
|
|||||||
return episodes;
|
return episodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Optional<String> findVideoType(String html) {
|
||||||
|
Matcher matcher = VIDEO_INFO_TYPE.matcher(html);
|
||||||
|
return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
private static int parseIntSafely(String value) {
|
private static int parseIntSafely(String value) {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(value);
|
return Integer.parseInt(value);
|
||||||
|
Reference in New Issue
Block a user