Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torznab permalinks #377

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions internal/model/torrents.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package model

import (
"github.com/bitmagnet-io/bitmagnet/internal/lexer"
"github.com/facette/natsort"
"gorm.io/gorm"
"net/url"
"sort"
"strconv"
"strings"
"time"

"github.com/bitmagnet-io/bitmagnet/internal/lexer"
"github.com/facette/natsort"
"gorm.io/gorm"
)

func (t *Torrent) AfterFind(tx *gorm.DB) error {
Expand Down Expand Up @@ -76,6 +77,10 @@ func (t Torrent) MagnetUri() string {
"&xl=" + strconv.FormatUint(uint64(t.Size), 10)
}

func (t Torrent) PermaLink() string {
return "/webui/torrents/permalink/" + t.InfoHash.String()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A permalink would need to be a fully qualified URL


// HasFilesInfo returns true if we know about the files in this torrent.
func (t Torrent) HasFilesInfo() bool {
return t.FilesStatus == FilesStatusSingle || t.FilesStatus == FilesStatusMulti || len(t.Files) > 0
Expand Down
6 changes: 6 additions & 0 deletions internal/torznab/adapter/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ func (a adapter) transformSearchResult(req torznab.SearchRequest, res search.Tor
AttrName: torznab.AttrPublishDate,
AttrValue: item.PublishedAt.Format(torznab.RssDateDefaultFormat),
},
{
AttrName: torznab.AttrCoverUrl,
AttrValue: item.Torrent.PermaLink(),
},
}
seeders := item.Torrent.Seeders()
leechers := item.Torrent.Leechers()
Expand Down Expand Up @@ -297,6 +301,8 @@ func (a adapter) transformSearchResult(req torznab.SearchRequest, res search.Tor
Category: category,
GUID: item.InfoHash.String(),
PubDate: torznab.RssDate(item.PublishedAt),
Comments: item.Torrent.PermaLink(),
Link: item.Torrent.PermaLink(),
Enclosure: torznab.SearchResultItemEnclosure{
URL: item.Torrent.MagnetUri(),
Type: "application/x-bittorrent;x-scheme-handler/magnet",
Expand Down
1 change: 1 addition & 0 deletions internal/torznab/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ const (
AttrResolution = "resolution"
AttrTeam = "team"
AttrImdb = "imdb"
AttrCoverUrl = "coverurl"
)