Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
new group import.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Dec 4, 2023
1 parent f8e29e8 commit 79d868c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/importer/audiop2p/audiop2p.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package audiop2p

import (
"regexp"
"strconv"
"time"
)

const Name = "AudioP2P"

func NfoDate(body string) ( //nolint:nonamedreturns
year int, month time.Month, day int,
) {
if body == "" {
return 0, 0, 0
}

// Prepared...: 01-27-2015
rx := regexp.MustCompile(`Prepared\.+: (\d\d)\-(\d\d)\-(\d\d\d\d)`)
f := rx.FindStringSubmatch(body)
const expected = 4
if len(f) == expected {
y, _ := strconv.Atoi(f[3])
m, _ := strconv.Atoi(f[1])
d, _ := strconv.Atoi(f[2])
return y, time.Month(m), d
}
return 0, 0, 0
}
36 changes: 36 additions & 0 deletions pkg/importer/audiop2p/audiop2p_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package audiop2p_test

import (
"testing"
"time"

"github.com/Defacto2/df2/pkg/importer/audiop2p"
"github.com/Defacto2/df2/pkg/internal"
"github.com/stretchr/testify/assert"
)

const nfo1 = `####################################################################################
# General Release Information #
####################################################################################
# Type.................: ADDON #
# Platform.............: ALL #
# Audio Format.........: N/A #
# Product WebSite......: www.example.com/?lang=en&page=products/nexus/skin #
# Release..............: 62 #
# Release Title........: ap-xxxx.rar #
# Prepared.............: 07-16-2009 #
# CRC & File Counts....: ap-xxxx.sfv #
####################################################################################`

func TestNfoDate(t *testing.T) {
t.Parallel()
y, m, d := audiop2p.NfoDate(internal.RandStr)
assert.Equal(t, 0, y)
assert.Equal(t, time.Month(0), m)
assert.Equal(t, 0, d)

y, m, d = audiop2p.NfoDate(nfo1)
assert.Equal(t, 2009, y)
assert.Equal(t, time.Month(7), m)
assert.Equal(t, 16, d)
}
3 changes: 3 additions & 0 deletions pkg/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/Defacto2/df2/pkg/importer/amplify"
"github.com/Defacto2/df2/pkg/importer/arcade"
"github.com/Defacto2/df2/pkg/importer/arctic"
"github.com/Defacto2/df2/pkg/importer/audiop2p"
"github.com/Defacto2/df2/pkg/importer/hexwars"
"github.com/Defacto2/df2/pkg/importer/record"
"github.com/Defacto2/df2/pkg/importer/spirit"
Expand Down Expand Up @@ -529,6 +530,8 @@ func Group(key string) string {
return arcade.Name
case "arctic":
return arctic.Name
case "audiop2p":
return audiop2p.Name
case "df2":
return "Defacto2"
case "hexwars":
Expand Down

0 comments on commit 79d868c

Please sign in to comment.