This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8e29e8
commit 79d868c
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters