Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/main/java/cn/har01d/alist_tvbox/entity/UnavailablePath.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cn.har01d.alist_tvbox.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.TableGenerator;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@TableGenerator(name = "tableGenerator", table = "id_generator", pkColumnName = "entity_name", valueColumnName = "next_id", allocationSize = 1)
public class UnavailablePath {
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "tableGenerator")
private Integer id;
@Column(unique = true)
private String path;
private int count;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cn.har01d.alist_tvbox.entity;

import org.springframework.data.jpa.repository.JpaRepository;

public interface UnavailablePathRepository extends JpaRepository<UnavailablePath, Integer> {
void deleteByPath(String path);

UnavailablePath findByPath(String path);

boolean existsByPath(String path);
}
22 changes: 21 additions & 1 deletion src/main/java/cn/har01d/alist_tvbox/service/AListService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import cn.har01d.alist_tvbox.config.AppProperties;
import cn.har01d.alist_tvbox.dto.FileItem;
import cn.har01d.alist_tvbox.entity.Site;
import cn.har01d.alist_tvbox.entity.UnavailablePath;
import cn.har01d.alist_tvbox.entity.UnavailablePathRepository;
import cn.har01d.alist_tvbox.model.FsDetail;
import cn.har01d.alist_tvbox.model.FsDetailResponse;
import cn.har01d.alist_tvbox.model.FsInfo;
Expand Down Expand Up @@ -48,12 +50,16 @@ public class AListService {
private final RestTemplate restTemplate;
private final SiteService siteService;
private final AppProperties appProperties;
private final UnavailablePathRepository unavailablePathRepository;
private final Cache<String, VideoPreview> cache = Caffeine.newBuilder()
.maximumSize(10)
.expireAfterWrite(Duration.ofSeconds(895))
.build();

public AListService(RestTemplateBuilder builder, SiteService siteService, AppProperties appProperties) {
public AListService(RestTemplateBuilder builder,
SiteService siteService,
AppProperties appProperties,
UnavailablePathRepository unavailablePathRepository) {
this.restTemplate = builder
.defaultHeader(HttpHeaders.ACCEPT, Constants.ACCEPT)
.defaultHeader(HttpHeaders.USER_AGENT, Constants.USER_AGENT)
Expand All @@ -62,6 +68,7 @@ public AListService(RestTemplateBuilder builder, SiteService siteService, AppPro
.build();
this.siteService = siteService;
this.appProperties = appProperties;
this.unavailablePathRepository = unavailablePathRepository;
}

public List<SearchResult> search(Site site, String keyword) {
Expand Down Expand Up @@ -205,6 +212,19 @@ private FsDetail getFileV3(Site site, String path) {
log.debug("call api: {} request: {}", url, request);
FsDetailResponse response = post(site, url, request, FsDetailResponse.class);
logError(response);
if (site.getId() == 1 && response != null) {
if (response.getCode() < 400) {
unavailablePathRepository.deleteByPath(request.getPath());
} else if (response.getMessage() != null && response.getMessage().contains("object not found")) {
var unavailablePath = unavailablePathRepository.findByPath(request.getPath());
if (unavailablePath == null) {
unavailablePath = new UnavailablePath();
unavailablePath.setPath(path);
}
unavailablePath.setCount(unavailablePath.getCount() + 1);
unavailablePathRepository.save(unavailablePath);
}
}
log.debug("get file: {} {}", path, response.getData());
return response.getData();
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/cn/har01d/alist_tvbox/service/TvBoxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cn.har01d.alist_tvbox.entity.ShareRepository;
import cn.har01d.alist_tvbox.entity.Site;
import cn.har01d.alist_tvbox.entity.Tmdb;
import cn.har01d.alist_tvbox.entity.UnavailablePathRepository;
import cn.har01d.alist_tvbox.exception.BadRequestException;
import cn.har01d.alist_tvbox.exception.NotFoundException;
import cn.har01d.alist_tvbox.model.FileNameInfo;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class TvBoxService {
private final AListAliasRepository aliasRepository;
private final ShareRepository shareRepository;
private final MetaRepository metaRepository;
private final UnavailablePathRepository unavailablePathRepository;

private final AListService aListService;
private final IndexService indexService;
Expand Down Expand Up @@ -140,6 +142,7 @@ public TvBoxService(AccountRepository accountRepository,
AListAliasRepository aliasRepository,
ShareRepository shareRepository,
MetaRepository metaRepository,
UnavailablePathRepository unavailablePathRepository,
AListService aListService,
IndexService indexService,
SiteService siteService,
Expand All @@ -154,6 +157,7 @@ public TvBoxService(AccountRepository accountRepository,
this.aliasRepository = aliasRepository;
this.shareRepository = shareRepository;
this.metaRepository = metaRepository;
this.unavailablePathRepository = unavailablePathRepository;
this.aListService = aListService;
this.indexService = indexService;
this.siteService = siteService;
Expand Down Expand Up @@ -376,12 +380,20 @@ public MovieList recommend(String ac, int pg) {
Map<String, List<Meta>> map = new HashMap<>();
Set<String> added = new HashSet<>();
for (Meta meta : page.getContent()) {
if (unavailablePathRepository.existsByPath(meta.getPath())) {
log.debug("ignore {} {}", meta.getId(), meta.getPath());
continue;
}
String name = getName(meta);
List<Meta> metas = map.computeIfAbsent(name, id -> new ArrayList<>());
metas.add(meta);
}

for (Meta meta : page.getContent()) {
if (unavailablePathRepository.existsByPath(meta.getPath())) {
log.debug("ignore {} {}", meta.getId(), meta.getPath());
continue;
}
String name = getName(meta);
if (added.contains(name)) {
log.debug("skip {}: {}", name, meta.getPath());
Expand Down Expand Up @@ -517,6 +529,10 @@ public MovieList search(Integer type, String ac, String keyword, int page) {

if (type != null && type == 0) {
for (Meta meta : metaRepository.findByPathContains(keyword, PageRequest.of(page - 1, appProperties.getMaxSearchResult(), Sort.Direction.DESC, "time", "id"))) {
if (unavailablePathRepository.existsByPath(meta.getPath())) {
log.debug("ignore {} {}", meta.getId(), meta.getPath());
continue;
}
String name = getName(meta);
boolean isMediaFile = isMediaFile(meta.getPath());
String newPath = fixPath(meta.getPath() + (isMediaFile ? "" : PLAYLIST));
Expand Down Expand Up @@ -615,6 +631,10 @@ private List<MovieDetail> searchFromIndexFile(Site site, String ac, String keywo
if (isMediaFile && lines.contains(getParent(raw))) {
continue;
}
if (unavailablePathRepository.existsByPath(line)) {
log.debug("ignore {}", line);
continue;
}
String path = fixPath("/" + line + (isMediaFile ? "" : PLAYLIST));
if (StringUtils.isNotBlank(site.getFolder()) && !"/".equals(site.getFolder())) {
if (path.startsWith(site.getFolder())) {
Expand Down Expand Up @@ -978,6 +998,10 @@ public MovieList getMetaList(String ac, String tid, String filter, String sort,
}

for (Meta meta : list) {
if (unavailablePathRepository.existsByPath(meta.getPath())) {
log.debug("ignore {} {}", meta.getId(), meta.getPath());
continue;
}
String name = getName(meta);
if (added.contains(name)) {
log.debug("skip {}: {}", name, meta.getPath());
Expand Down