Skip to content

Commit

Permalink
date fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lieranderl committed Dec 14, 2024
1 parent 3662b47 commit d36ea80
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {

// print all torrents
for _, torrent := range pipeline.GetTorrents() {
log.Println("Torrent:", torrent.Name, torrent.Size, torrent.Date, torrent.Magnet, torrent.Date)
log.Println("Torrent:", torrent.Name, torrent.Date)
}

elapsed := time.Since(start)
Expand Down
1 change: 0 additions & 1 deletion executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func (p *trackersPipeline) RunTrackersSearchPipeline(isMovie bool) *trackersPipe
5,
)


var allTorrents []*torrents.Torrent
var errs []error

Expand Down
7 changes: 4 additions & 3 deletions internal/trackers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ func ParseInt(s string) (int32, error) {

// ParseDate parses date string using specified format
func ParseDate(dateStr string, format string) (string, error) {
layout := "2006-01-02T15:04:05.000Z"
// ISO 8601 format
layout := "2006-01-02"
timeNow := time.Now()

switch {
case strings.Contains(dateStr, "сегодня"):
return monday.Format(timeNow, layout, monday.LocaleRuRU), nil
case strings.Contains(dateStr, "вчера"):
return monday.Format(timeNow.AddDate(0, 0, -1), layout, monday.LocaleRuRU), nil
default:
// Try parsing with the provided format
if parsedTime, err := monday.Parse(format, dateStr, monday.LocaleRuRU); err == nil {
return monday.Format(parsedTime, layout, monday.LocaleRuRU), nil
}
return "", fmt.Errorf("failed to parse date")
return "", fmt.Errorf("failed to parse date: %s", dateStr)
}
}
4 changes: 2 additions & 2 deletions internal/trackers/config_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewRutorConfig(baseURL string) ParserConfig {
ExcludePatterns: []string{
"PROPER", "REPACK",
},
DateFormat: "02.01.2006",
DateFormat: "02 Jan 06",
TitleSelector: "tr.gai,tr.tum",
SizeSelector: "tr td:nth-child(4)",
SeedsSelector: "tr td:nth-child(5)",
Expand Down Expand Up @@ -44,7 +44,7 @@ func NewKinozalConfig(baseURL string) ParserConfig {
ExcludePatterns: []string{
"Трейлер", "Анонс",
},
DateFormat: "2006-01-02T15:04:05.000Z",
DateFormat: "02.01.2006",
TitleSelector: "tr.bg",
SizeSelector: "td:nth-child(4)",
SeedsSelector: "td:nth-child(5)",
Expand Down
1 change: 0 additions & 1 deletion internal/trackers/kinozal.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func (p *KinozalParser) parseTorrentElement(tds *goquery.Selection, name string)
if leeches, err := ParseInt(tds.Eq(5).Text()); err == nil {
torrent.Leeches = leeches
}

if dateStr := strings.Fields(tds.Eq(6).Text()); len(dateStr) > 0 {
if date, err := ParseDate(dateStr[0], p.config.ParseConfig.DateFormat); err == nil {
torrent.Date = date
Expand Down
2 changes: 1 addition & 1 deletion internal/trackers/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewTrackerProcessor(isMovie bool, configs ...ParserConfig) (*TrackerProcess
func (tp *TrackerProcessor) ProcessURL(url string) ([]*torrents.Torrent, error) {
trackerType := determineTrackerType(url)
parser, exists := tp.parsers[trackerType]

if !exists {
return nil, fmt.Errorf("no parser found for URL: %s", url)
}
Expand Down

0 comments on commit d36ea80

Please sign in to comment.