mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
feat(filters): skip duplicates (#1711)
* feat(filters): skip duplicates * fix: add interface instead of any * fix(filters): tonullint * feat(filters): skip dupes check month day * chore: cleanup * feat(db): set autoincrement id * feat(filters): add repack and proper to dupe profile * feat(filters): add default dupe profiles * feat(duplicates): check audio and website * feat(duplicates): update tests * feat(duplicates): add toggles on addform * feat(duplicates): fix sqlite upgrade path and initialize duplicate profiles * feat(duplicates): simplify sqlite upgrade avoiding temp table and unwieldy select. Besides, FK constraints are turned off anyway in #229. * feat(duplicates): change CheckIsDuplicateRelease treatment of PROPER and REPACK "Proper" and "Repack" are not parallel to the other conditions like "Title", so they do not belong as dedup conditions. "PROPER" means there was an issue in the previous release, and so a PROPER is never a duplicate, even if it replaces another PROPER. Similarly, "REPACK" means there was an issue in the previous release by that group, and so it is a duplicate only if we previously took a release from a DIFFERENT group. I have not removed Proper and Repack from the UI or the schema yet. * feat(duplicates): update postgres schema to match sqlite * feat(duplicates): fix web build errors * feat(duplicates): fix postgres errors * feat(filters): do leftjoin for duplicate profile * fix(filters): partial update dupe profile * go fmt `internal/domain/filter.go` * feat(duplicates): restore straightforward logic for proper/repack * feat(duplicates): remove mostly duplicate TV duplicate profiles Having one profile seems the cleanest. If somebody wants multiple resolutions then they can add Resolution to the duplicate profile. Tested this profile with both weekly episodic releases and daily show releases. * feat(release): add db indexes and sub_title * feat(release): add IsDuplicate tests * feat(release): update action handler * feat(release): add more tests for skip duplicates * feat(duplicates): check audio * feat(duplicates): add more tests * feat(duplicates): match edition cut and more * fix(duplicates): tests * fix(duplicates): missing imports * fix(duplicates): tests * feat(duplicates): handle sub_title edition and language in ui * fix(duplicates): tests * feat(duplicates): check name against normalized hash * fix(duplicates): tests * chore: update .gitignore to ignore .pnpm-store * fix: tests * fix(filters): tests * fix: bad conflict merge * fix: update release type in test * fix: use vendored hot-toast * fix: release_test.go * fix: rss_test.go * feat(duplicates): improve title hashing for unique check * feat(duplicates): further improve title hashing for unique check with lang * feat(duplicates): fix tests * feat(duplicates): add macros IsDuplicate and DuplicateProfile ID and name * feat(duplicates): add normalized hash match option * fix: headlessui-state prop warning * fix(duplicates): add missing year in daily ep normalize * fix(duplicates): check rejections len --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
d153ac44b8
commit
4009554d10
49 changed files with 3792 additions and 743 deletions
|
@ -33,23 +33,31 @@ func NewReleaseRepo(log logger.Logger, db *DB) domain.ReleaseRepo {
|
|||
}
|
||||
|
||||
func (repo *ReleaseRepo) Store(ctx context.Context, r *domain.Release) error {
|
||||
codecStr := strings.Join(r.Codec, ",")
|
||||
hdrStr := strings.Join(r.HDR, ",")
|
||||
var (
|
||||
codecStr = strings.Join(r.Codec, ",")
|
||||
hdrStr = strings.Join(r.HDR, ",")
|
||||
audioStr = strings.Join(r.Audio, ",")
|
||||
editionStr = strings.Join(r.Edition, ",")
|
||||
cutStr = strings.Join(r.Cut, ",")
|
||||
languageStr = strings.Join(r.Language, ",")
|
||||
)
|
||||
|
||||
queryBuilder := repo.db.squirrel.
|
||||
Insert("release").
|
||||
Columns("filter_status", "rejections", "indexer", "filter", "protocol", "implementation", "timestamp", "announce_type", "group_id", "torrent_id", "info_url", "download_url", "torrent_name", "size", "title", "category", "season", "episode", "year", "month", "day", "resolution", "source", "codec", "container", "hdr", "release_group", "proper", "repack", "website", "type", "origin", "tags", "uploader", "pre_time", "filter_id").
|
||||
Values(r.FilterStatus, pq.Array(r.Rejections), r.Indexer.Identifier, r.FilterName, r.Protocol, r.Implementation, r.Timestamp.Format(time.RFC3339), r.AnnounceType, r.GroupID, r.TorrentID, r.InfoURL, r.DownloadURL, r.TorrentName, r.Size, r.Title, r.Category, r.Season, r.Episode, r.Year, r.Month, r.Day, r.Resolution, r.Source, codecStr, r.Container, hdrStr, r.Group, r.Proper, r.Repack, r.Website, r.Type, r.Origin, pq.Array(r.Tags), r.Uploader, r.PreTime, r.FilterID).
|
||||
Columns("filter_status", "rejections", "indexer", "filter", "protocol", "implementation", "timestamp", "announce_type", "group_id", "torrent_id", "info_url", "download_url", "torrent_name", "normalized_hash", "size", "title", "sub_title", "category", "season", "episode", "year", "month", "day", "resolution", "source", "codec", "container", "hdr", "audio", "audio_channels", "release_group", "proper", "repack", "region", "language", "cut", "edition", "hybrid", "media_processing", "website", "type", "origin", "tags", "uploader", "pre_time", "other", "filter_id").
|
||||
Values(r.FilterStatus, pq.Array(r.Rejections), r.Indexer.Identifier, r.FilterName, r.Protocol, r.Implementation, r.Timestamp.Format(time.RFC3339), r.AnnounceType, r.GroupID, r.TorrentID, r.InfoURL, r.DownloadURL, r.TorrentName, r.NormalizedHash, r.Size, r.Title, r.SubTitle, r.Category, r.Season, r.Episode, r.Year, r.Month, r.Day, r.Resolution, r.Source, codecStr, r.Container, hdrStr, audioStr, r.AudioChannels, r.Group, r.Proper, r.Repack, r.Region, languageStr, cutStr, editionStr, r.Hybrid, r.MediaProcessing, r.Website, r.Type.String(), r.Origin, pq.Array(r.Tags), r.Uploader, r.PreTime, pq.Array(r.Other), r.FilterID).
|
||||
Suffix("RETURNING id").RunWith(repo.db.handler)
|
||||
|
||||
// return values
|
||||
var retID int64
|
||||
|
||||
if err := queryBuilder.QueryRowContext(ctx).Scan(&retID); err != nil {
|
||||
return errors.Wrap(err, "error executing query")
|
||||
q, args, err := queryBuilder.ToSql()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error building query")
|
||||
}
|
||||
|
||||
r.ID = retID
|
||||
repo.log.Debug().Msgf("release.store: %s %v", q, args)
|
||||
|
||||
if err := queryBuilder.QueryRowContext(ctx).Scan(&r.ID); err != nil {
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
repo.log.Debug().Msgf("release.store: %+v", r)
|
||||
|
||||
|
@ -102,14 +110,9 @@ func (repo *ReleaseRepo) StoreReleaseActionStatus(ctx context.Context, status *d
|
|||
Values(status.Status, status.Action, status.ActionID, status.Type, status.Client, status.Filter, status.FilterID, pq.Array(status.Rejections), status.Timestamp.Format(time.RFC3339), status.ReleaseID).
|
||||
Suffix("RETURNING id").RunWith(repo.db.handler)
|
||||
|
||||
// return values
|
||||
var retID int64
|
||||
|
||||
if err := queryBuilder.QueryRowContext(ctx).Scan(&retID); err != nil {
|
||||
if err := queryBuilder.QueryRowContext(ctx).Scan(&status.ID); err != nil {
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
status.ID = retID
|
||||
}
|
||||
|
||||
repo.log.Trace().Msgf("release.store_release_action_status: %+v", status)
|
||||
|
@ -117,6 +120,62 @@ func (repo *ReleaseRepo) StoreReleaseActionStatus(ctx context.Context, status *d
|
|||
return nil
|
||||
}
|
||||
|
||||
func (repo *ReleaseRepo) StoreDuplicateProfile(ctx context.Context, profile *domain.DuplicateReleaseProfile) error {
|
||||
if profile.ID == 0 {
|
||||
queryBuilder := repo.db.squirrel.
|
||||
Insert("release_profile_duplicate").
|
||||
Columns("name", "protocol", "release_name", "hash", "title", "sub_title", "season", "episode", "year", "month", "day", "resolution", "source", "codec", "container", "dynamic_range", "audio", "release_group", "website", "proper", "repack").
|
||||
Values(profile.Name, profile.Protocol, profile.ReleaseName, profile.Hash, profile.Title, profile.SubTitle, profile.Season, profile.Episode, profile.Year, profile.Month, profile.Day, profile.Resolution, profile.Source, profile.Codec, profile.Container, profile.DynamicRange, profile.Audio, profile.Group, profile.Website, profile.Proper, profile.Repack).
|
||||
Suffix("RETURNING id").
|
||||
RunWith(repo.db.handler)
|
||||
|
||||
// return values
|
||||
var retID int64
|
||||
|
||||
err := queryBuilder.QueryRowContext(ctx).Scan(&retID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
profile.ID = retID
|
||||
} else {
|
||||
queryBuilder := repo.db.squirrel.
|
||||
Update("release_profile_duplicate").
|
||||
Set("name", profile.Name).
|
||||
Set("protocol", profile.Protocol).
|
||||
Set("release_name", profile.ReleaseName).
|
||||
Set("hash", profile.Hash).
|
||||
Set("title", profile.Title).
|
||||
Set("sub_title", profile.SubTitle).
|
||||
Set("season", profile.Season).
|
||||
Set("episode", profile.Episode).
|
||||
Set("year", profile.Year).
|
||||
Set("month", profile.Month).
|
||||
Set("day", profile.Day).
|
||||
Set("resolution", profile.Resolution).
|
||||
Set("source", profile.Source).
|
||||
Set("codec", profile.Codec).
|
||||
Set("container", profile.Container).
|
||||
Set("dynamic_range", profile.DynamicRange).
|
||||
Set("audio", profile.Audio).
|
||||
Set("release_group", profile.Group).
|
||||
Set("website", profile.Website).
|
||||
Set("proper", profile.Proper).
|
||||
Set("repack", profile.Repack).
|
||||
Where(sq.Eq{"id": profile.ID}).
|
||||
RunWith(repo.db.handler)
|
||||
|
||||
_, err := queryBuilder.ExecContext(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
}
|
||||
|
||||
repo.log.Debug().Msgf("release.StoreDuplicateProfile: %+v", profile)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *ReleaseRepo) Find(ctx context.Context, params domain.ReleaseQueryParams) (*domain.FindReleasesResponse, error) {
|
||||
tx, err := repo.db.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelReadCommitted})
|
||||
if err != nil {
|
||||
|
@ -192,7 +251,7 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain
|
|||
|
||||
whereQuery, _, err := whereQueryBuilder.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error building wherequery")
|
||||
return nil, errors.Wrap(err, "error building where query")
|
||||
}
|
||||
|
||||
subQueryBuilder := repo.db.squirrel.
|
||||
|
@ -230,8 +289,49 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain
|
|||
}
|
||||
|
||||
queryBuilder := repo.db.squirrel.
|
||||
Select("r.id", "r.filter_status", "r.rejections", "r.indexer", "i.id", "i.name", "i.identifier_external", "r.filter", "r.protocol", "r.announce_type", "r.info_url", "r.download_url", "r.title", "r.torrent_name", "r.size", "r.category", "r.season", "r.episode", "r.year", "r.resolution", "r.source", "r.codec", "r.container", "r.release_group", "r.timestamp",
|
||||
"ras.id", "ras.status", "ras.action", "ras.action_id", "ras.type", "ras.client", "ras.filter", "ras.filter_id", "ras.release_id", "ras.rejections", "ras.timestamp").
|
||||
Select(
|
||||
"r.id",
|
||||
"r.filter_status",
|
||||
"r.rejections",
|
||||
"r.indexer",
|
||||
"i.id",
|
||||
"i.name",
|
||||
"i.identifier_external",
|
||||
"r.filter",
|
||||
"r.protocol",
|
||||
"r.announce_type",
|
||||
"r.info_url",
|
||||
"r.download_url",
|
||||
"r.title",
|
||||
"r.sub_title",
|
||||
"r.torrent_name",
|
||||
"r.normalized_hash",
|
||||
"r.size",
|
||||
"r.category",
|
||||
"r.season",
|
||||
"r.episode",
|
||||
"r.year",
|
||||
"r.resolution",
|
||||
"r.source",
|
||||
"r.codec",
|
||||
"r.container",
|
||||
"r.hdr",
|
||||
"r.audio",
|
||||
"r.audio_channels",
|
||||
"r.release_group",
|
||||
"r.region",
|
||||
"r.language",
|
||||
"r.edition",
|
||||
"r.cut",
|
||||
"r.hybrid",
|
||||
"r.proper",
|
||||
"r.repack",
|
||||
"r.website",
|
||||
"r.media_processing",
|
||||
"r.type",
|
||||
"r.timestamp",
|
||||
"ras.id", "ras.status", "ras.action", "ras.action_id", "ras.type", "ras.client", "ras.filter", "ras.filter_id", "ras.release_id", "ras.rejections", "ras.timestamp",
|
||||
).
|
||||
Column(sq.Alias(countQuery, "page_total")).
|
||||
From("release r").
|
||||
OrderBy("r.id DESC").
|
||||
|
@ -267,7 +367,7 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain
|
|||
var rls domain.Release
|
||||
var ras domain.ReleaseActionStatus
|
||||
|
||||
var rlsIndexer, rlsIndexerName, rlsIndexerExternalName, rlsFilter, rlsAnnounceType, infoUrl, downloadUrl, codec sql.NullString
|
||||
var rlsIndexer, rlsIndexerName, rlsIndexerExternalName, rlsFilter, rlsAnnounceType, infoUrl, downloadUrl, subTitle, normalizedHash, codec, hdr, rlsType, audioStr, languageStr, editionStr, cutStr, website sql.NullString
|
||||
|
||||
var rlsIndexerID sql.NullInt64
|
||||
var rasId, rasFilterId, rasReleaseId, rasActionId sql.NullInt64
|
||||
|
@ -275,7 +375,49 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain
|
|||
var rasRejections []sql.NullString
|
||||
var rasTimestamp sql.NullTime
|
||||
|
||||
if err := rows.Scan(&rls.ID, &rls.FilterStatus, pq.Array(&rls.Rejections), &rlsIndexer, &rlsIndexerID, &rlsIndexerName, &rlsIndexerExternalName, &rlsFilter, &rls.Protocol, &rlsAnnounceType, &infoUrl, &downloadUrl, &rls.Title, &rls.TorrentName, &rls.Size, &rls.Category, &rls.Season, &rls.Episode, &rls.Year, &rls.Resolution, &rls.Source, &codec, &rls.Container, &rls.Group, &rls.Timestamp, &rasId, &rasStatus, &rasAction, &rasActionId, &rasType, &rasClient, &rasFilter, &rasFilterId, &rasReleaseId, pq.Array(&rasRejections), &rasTimestamp, &resp.TotalCount); err != nil {
|
||||
if err := rows.Scan(
|
||||
&rls.ID,
|
||||
&rls.FilterStatus,
|
||||
pq.Array(&rls.Rejections),
|
||||
&rlsIndexer,
|
||||
&rlsIndexerID,
|
||||
&rlsIndexerName,
|
||||
&rlsIndexerExternalName,
|
||||
&rlsFilter,
|
||||
&rls.Protocol,
|
||||
&rlsAnnounceType,
|
||||
&infoUrl,
|
||||
&downloadUrl,
|
||||
&rls.Title,
|
||||
&subTitle,
|
||||
&rls.TorrentName,
|
||||
&normalizedHash,
|
||||
&rls.Size,
|
||||
&rls.Category,
|
||||
&rls.Season,
|
||||
&rls.Episode,
|
||||
&rls.Year,
|
||||
&rls.Resolution,
|
||||
&rls.Source,
|
||||
&codec,
|
||||
&rls.Container,
|
||||
&hdr,
|
||||
&audioStr,
|
||||
&rls.AudioChannels,
|
||||
&rls.Group,
|
||||
&rls.Region,
|
||||
&languageStr,
|
||||
&editionStr,
|
||||
&cutStr,
|
||||
&rls.Hybrid,
|
||||
&rls.Proper,
|
||||
&rls.Repack,
|
||||
&website,
|
||||
&rls.MediaProcessing,
|
||||
&rlsType,
|
||||
&rls.Timestamp,
|
||||
&rasId, &rasStatus, &rasAction, &rasActionId, &rasType, &rasClient, &rasFilter, &rasFilterId, &rasReleaseId, pq.Array(&rasRejections), &rasTimestamp, &resp.TotalCount,
|
||||
); err != nil {
|
||||
return resp, errors.Wrap(err, "error scanning row")
|
||||
}
|
||||
|
||||
|
@ -324,7 +466,19 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain
|
|||
rls.ActionStatus = make([]domain.ReleaseActionStatus, 0)
|
||||
rls.InfoURL = infoUrl.String
|
||||
rls.DownloadURL = downloadUrl.String
|
||||
rls.SubTitle = subTitle.String
|
||||
rls.NormalizedHash = normalizedHash.String
|
||||
rls.Codec = strings.Split(codec.String, ",")
|
||||
rls.HDR = strings.Split(hdr.String, ",")
|
||||
rls.Audio = strings.Split(audioStr.String, ",")
|
||||
rls.Language = strings.Split(languageStr.String, ",")
|
||||
rls.Edition = strings.Split(editionStr.String, ",")
|
||||
rls.Cut = strings.Split(cutStr.String, ",")
|
||||
rls.Website = website.String
|
||||
//rls.Type = rlsType.String
|
||||
if rlsType.Valid {
|
||||
rls.ParseType(rlsType.String)
|
||||
}
|
||||
|
||||
// only add ActionStatus if it's not empty
|
||||
if ras.ID > 0 {
|
||||
|
@ -342,6 +496,66 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func (repo *ReleaseRepo) FindDuplicateReleaseProfiles(ctx context.Context) ([]*domain.DuplicateReleaseProfile, error) {
|
||||
queryBuilder := repo.db.squirrel.
|
||||
Select(
|
||||
"id",
|
||||
"name",
|
||||
"protocol",
|
||||
"release_name",
|
||||
"hash",
|
||||
"title",
|
||||
"sub_title",
|
||||
"year",
|
||||
"month",
|
||||
"day",
|
||||
"source",
|
||||
"resolution",
|
||||
"codec",
|
||||
"container",
|
||||
"dynamic_range",
|
||||
"audio",
|
||||
"release_group",
|
||||
"season",
|
||||
"episode",
|
||||
"website",
|
||||
"proper",
|
||||
"repack",
|
||||
).
|
||||
From("release_profile_duplicate")
|
||||
|
||||
query, args, err := queryBuilder.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error building query")
|
||||
}
|
||||
|
||||
rows, err := repo.db.handler.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, errors.Wrap(err, "error rows FindDuplicateReleaseProfiles")
|
||||
}
|
||||
|
||||
res := make([]*domain.DuplicateReleaseProfile, 0)
|
||||
|
||||
for rows.Next() {
|
||||
var p domain.DuplicateReleaseProfile
|
||||
|
||||
err := rows.Scan(&p.ID, &p.Name, &p.Protocol, &p.ReleaseName, &p.Hash, &p.Title, &p.SubTitle, &p.Year, &p.Month, &p.Day, &p.Source, &p.Resolution, &p.Codec, &p.Container, &p.DynamicRange, &p.Audio, &p.Group, &p.Season, &p.Episode, &p.Website, &p.Proper, &p.Repack)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error scanning row")
|
||||
}
|
||||
|
||||
res = append(res, &p)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (repo *ReleaseRepo) GetIndexerOptions(ctx context.Context) ([]string, error) {
|
||||
query := `SELECT DISTINCT indexer FROM "release" UNION SELECT DISTINCT identifier indexer FROM indexer;`
|
||||
|
||||
|
@ -420,7 +634,7 @@ func (repo *ReleaseRepo) GetActionStatusByReleaseID(ctx context.Context, release
|
|||
|
||||
func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest) (*domain.Release, error) {
|
||||
queryBuilder := repo.db.squirrel.
|
||||
Select("r.id", "r.filter_status", "r.rejections", "r.indexer", "r.filter", "r.filter_id", "r.protocol", "r.implementation", "r.announce_type", "r.info_url", "r.download_url", "r.title", "r.torrent_name", "r.category", "r.size", "r.group_id", "r.torrent_id", "r.uploader", "r.timestamp").
|
||||
Select("r.id", "r.filter_status", "r.rejections", "r.indexer", "r.filter", "r.filter_id", "r.protocol", "r.implementation", "r.announce_type", "r.info_url", "r.download_url", "r.title", "r.sub_title", "r.torrent_name", "r.category", "r.size", "r.group_id", "r.torrent_id", "r.uploader", "r.timestamp").
|
||||
From("release r").
|
||||
OrderBy("r.id DESC").
|
||||
Where(sq.Eq{"r.id": req.Id})
|
||||
|
@ -439,10 +653,10 @@ func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest)
|
|||
|
||||
var rls domain.Release
|
||||
|
||||
var indexerName, filterName, announceType, infoUrl, downloadUrl, groupId, torrentId, category, uploader sql.NullString
|
||||
var indexerName, filterName, announceType, infoUrl, downloadUrl, subTitle, groupId, torrentId, category, uploader sql.NullString
|
||||
var filterId sql.NullInt64
|
||||
|
||||
if err := row.Scan(&rls.ID, &rls.FilterStatus, pq.Array(&rls.Rejections), &indexerName, &filterName, &filterId, &rls.Protocol, &rls.Implementation, &announceType, &infoUrl, &downloadUrl, &rls.Title, &rls.TorrentName, &category, &rls.Size, &groupId, &torrentId, &uploader, &rls.Timestamp); err != nil {
|
||||
if err := row.Scan(&rls.ID, &rls.FilterStatus, pq.Array(&rls.Rejections), &indexerName, &filterName, &filterId, &rls.Protocol, &rls.Implementation, &announceType, &infoUrl, &downloadUrl, &rls.Title, &subTitle, &rls.TorrentName, &category, &rls.Size, &groupId, &torrentId, &uploader, &rls.Timestamp); err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrRecordNotFound
|
||||
}
|
||||
|
@ -457,6 +671,7 @@ func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest)
|
|||
rls.AnnounceType = domain.AnnounceType(announceType.String)
|
||||
rls.InfoURL = infoUrl.String
|
||||
rls.DownloadURL = downloadUrl.String
|
||||
rls.SubTitle = subTitle.String
|
||||
rls.Category = category.String
|
||||
rls.GroupID = groupId.String
|
||||
rls.TorrentID = torrentId.String
|
||||
|
@ -670,6 +885,31 @@ func (repo *ReleaseRepo) Delete(ctx context.Context, req *domain.DeleteReleaseRe
|
|||
return nil
|
||||
}
|
||||
|
||||
func (repo *ReleaseRepo) DeleteReleaseProfileDuplicate(ctx context.Context, id int64) error {
|
||||
qb := repo.db.squirrel.Delete("release_profile_duplicate").Where(sq.Eq{"id": id})
|
||||
|
||||
query, args, err := qb.ToSql()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error building SQL query")
|
||||
}
|
||||
|
||||
_, err = repo.db.handler.ExecContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing delete query")
|
||||
}
|
||||
|
||||
//deletedRows, err := result.RowsAffected()
|
||||
//if err != nil {
|
||||
// return errors.Wrap(err, "error fetching rows affected")
|
||||
//}
|
||||
//
|
||||
//repo.log.Debug().Msgf("deleted %d rows from release table", deletedRows)
|
||||
|
||||
repo.log.Debug().Msgf("deleted duplicate release profile: %d", id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *ReleaseRepo) CheckSmartEpisodeCanDownload(ctx context.Context, p *domain.SmartEpisodeParams) (bool, error) {
|
||||
queryBuilder := repo.db.squirrel.
|
||||
Select("COUNT(*)").
|
||||
|
@ -793,3 +1033,200 @@ func (repo *ReleaseRepo) UpdateBaseURL(ctx context.Context, indexer string, oldB
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *ReleaseRepo) CheckIsDuplicateRelease(ctx context.Context, profile *domain.DuplicateReleaseProfile, release *domain.Release) (bool, error) {
|
||||
queryBuilder := repo.db.squirrel.
|
||||
Select("r.id, r.torrent_name, r.normalized_hash, r.title, ras.action, ras.status").
|
||||
From("release r").
|
||||
LeftJoin("release_action_status ras ON r.id = ras.release_id").
|
||||
Where("ras.status = 'PUSH_APPROVED'")
|
||||
|
||||
if profile.ReleaseName && profile.Hash {
|
||||
//queryBuilder = queryBuilder.Where(repo.db.ILike("r.torrent_name", release.TorrentName))
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.normalized_hash": release.NormalizedHash})
|
||||
} else {
|
||||
if profile.Title {
|
||||
queryBuilder = queryBuilder.Where(repo.db.ILike("r.title", release.Title))
|
||||
}
|
||||
|
||||
if profile.SubTitle {
|
||||
queryBuilder = queryBuilder.Where(repo.db.ILike("r.sub_title", release.SubTitle))
|
||||
}
|
||||
|
||||
if profile.ReleaseName && profile.Hash {
|
||||
//queryBuilder = queryBuilder.Where(repo.db.ILike("r.torrent_name", release.TorrentName))
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.normalized_hash": release.NormalizedHash})
|
||||
}
|
||||
|
||||
if profile.Year {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.year": release.Year})
|
||||
}
|
||||
|
||||
if profile.Month {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.month": release.Month})
|
||||
}
|
||||
|
||||
if profile.Day {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.day": release.Day})
|
||||
}
|
||||
|
||||
if profile.Source {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.source": release.Source})
|
||||
}
|
||||
|
||||
if profile.Container {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.container": release.Container})
|
||||
}
|
||||
|
||||
if profile.Edition {
|
||||
//queryBuilder = queryBuilder.Where(sq.Eq{"r.cut": release.Cut})
|
||||
if len(release.Cut) > 1 {
|
||||
var and sq.And
|
||||
for _, cut := range release.Cut {
|
||||
//and = append(and, sq.Eq{"r.cut": "%" + cut + "%"})
|
||||
and = append(and, repo.db.ILike("r.cut", "%"+cut+"%"))
|
||||
}
|
||||
queryBuilder = queryBuilder.Where(and)
|
||||
} else if len(release.Cut) == 1 {
|
||||
queryBuilder = queryBuilder.Where(repo.db.ILike("r.cut", "%"+release.Cut[0]+"%"))
|
||||
}
|
||||
|
||||
//queryBuilder = queryBuilder.Where(sq.Eq{"r.edition": release.Edition})
|
||||
if len(release.Edition) > 1 {
|
||||
var and sq.And
|
||||
for _, edition := range release.Edition {
|
||||
and = append(and, repo.db.ILike("r.edition", "%"+edition+"%"))
|
||||
}
|
||||
queryBuilder = queryBuilder.Where(and)
|
||||
} else if len(release.Edition) == 1 {
|
||||
queryBuilder = queryBuilder.Where(repo.db.ILike("r.edition", "%"+release.Edition[0]+"%"))
|
||||
}
|
||||
}
|
||||
|
||||
// video features (hybrid, remux)
|
||||
if release.IsTypeVideo() {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.hybrid": release.Hybrid})
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.media_processing": release.MediaProcessing})
|
||||
}
|
||||
|
||||
if profile.Language {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.region": release.Region})
|
||||
|
||||
if len(release.Language) > 0 {
|
||||
var and sq.And
|
||||
for _, lang := range release.Language {
|
||||
and = append(and, repo.db.ILike("r.language", "%"+lang+"%"))
|
||||
}
|
||||
|
||||
queryBuilder = queryBuilder.Where(and)
|
||||
} else {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.language": ""})
|
||||
}
|
||||
}
|
||||
|
||||
if profile.Codec {
|
||||
if len(release.Codec) > 1 {
|
||||
var and sq.And
|
||||
for _, codec := range release.Codec {
|
||||
and = append(and, repo.db.ILike("r.codec", "%"+codec+"%"))
|
||||
}
|
||||
queryBuilder = queryBuilder.Where(and)
|
||||
} else {
|
||||
// FIXME this does an IN (arg)
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.codec": release.Codec})
|
||||
}
|
||||
}
|
||||
|
||||
if profile.Resolution {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.resolution": release.Resolution})
|
||||
}
|
||||
|
||||
if profile.DynamicRange {
|
||||
//if len(release.HDR) > 1 {
|
||||
// var and sq.And
|
||||
// for _, hdr := range release.HDR {
|
||||
// and = append(and, repo.db.ILike("r.hdr", "%"+hdr+"%"))
|
||||
// }
|
||||
// queryBuilder = queryBuilder.Where(and)
|
||||
//} else {
|
||||
// queryBuilder = queryBuilder.Where(sq.Eq{"r.hdr": release.HDR})
|
||||
//}
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.hdr": strings.Join(release.HDR, ",")})
|
||||
}
|
||||
|
||||
if profile.Audio {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.audio": strings.Join(release.Audio, ",")})
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.audio_channels": release.AudioChannels})
|
||||
}
|
||||
|
||||
if profile.Group {
|
||||
queryBuilder = queryBuilder.Where(repo.db.ILike("r.release_group", release.Group))
|
||||
}
|
||||
|
||||
if profile.Season {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.season": release.Season})
|
||||
}
|
||||
|
||||
if profile.Episode {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.episode": release.Episode})
|
||||
}
|
||||
|
||||
if profile.Website {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.website": release.Website})
|
||||
}
|
||||
|
||||
if profile.Proper {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"r.proper": release.Proper})
|
||||
}
|
||||
|
||||
if profile.Repack {
|
||||
queryBuilder = queryBuilder.Where(sq.And{
|
||||
sq.Eq{"r.repack": release.Repack},
|
||||
repo.db.ILike("r.release_group", release.Group),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
query, args, err := queryBuilder.ToSql()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "error building query")
|
||||
}
|
||||
|
||||
repo.log.Trace().Str("database", "release.FindDuplicateReleases").Msgf("query: %q, args: %q", query, args)
|
||||
|
||||
rows, err := repo.db.handler.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return false, errors.Wrap(err, "error rows CheckIsDuplicateRelease")
|
||||
}
|
||||
|
||||
type result struct {
|
||||
id int
|
||||
release string
|
||||
hash string
|
||||
title string
|
||||
action string
|
||||
status string
|
||||
}
|
||||
|
||||
var res []result
|
||||
|
||||
for rows.Next() {
|
||||
r := result{}
|
||||
if err := rows.Scan(&r.id, &r.release, &r.hash, &r.title, &r.action, &r.status); err != nil {
|
||||
return false, errors.Wrap(err, "error scan CheckIsDuplicateRelease")
|
||||
}
|
||||
res = append(res, r)
|
||||
}
|
||||
|
||||
repo.log.Trace().Str("database", "release.FindDuplicateReleases").Msgf("found duplicate releases: %+v", res)
|
||||
|
||||
if len(res) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue