Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Removing the folder tosho and put categories.go directly in upload package.

Added category conversion for nyaasi too.
Added tests on category conversion.
Cette révision appartient à :
akuma06 2017-12-24 17:34:57 +01:00
Parent b0d32ff8a3
révision 96fbf786d8
4 fichiers modifiés avec 134 ajouts et 55 suppressions

95
utils/upload/categories.go Fichier normal
Voir le fichier

@ -0,0 +1,95 @@
package upload
import (
"fmt"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
)
// Convert automatically our sukebei cats to platform specified Hentai cats
var sukebeiCategories = []map[string]string{
ttosho: {
"1_1": "12",
"1_2": "12",
"1_3": "14",
"1_4": "13",
"1_5": "4",
"2_1": "4",
"2_2": "15",
},
nyaasi: {
"1_1": "1_1",
"1_2": "1_2",
"1_3": "1_3",
"1_4": "1_4",
"1_5": "1_5",
"2_1": "2_1",
"2_2": "2_2",
},
}
var normalCategories = []map[string]string{
ttosho: {
"3_12": "1",
"3_5": "1",
"3_13": "10",
"3_6": "7",
"2_3": "2",
"2_4": "2",
"4_7": "3",
"4_8": "7",
"4_14": "10",
"5_9": "8",
"5_10": "8",
"5_18": "10",
"5_11": "7",
"6_15": "5",
"6_16": "5",
"1_1": "5",
"1_2": "5",
},
nyaasi: {
"3_12": "1_1",
"3_5": "1_2",
"3_13": "1_3",
"3_6": "1_4",
"2_3": "2_1",
"2_4": "2_2",
"4_7": "3_1",
"4_8": "3_4",
"4_14": "3_3",
"5_9": "4_1",
"5_10": "4_2",
"5_18": "4_3",
"5_11": "4_4",
"6_15": "5_1",
"6_16": "5_2",
"1_1": "6_1",
"1_2": "6_2",
},
}
// Category returns the category converted from nyaa one to tosho one
func Category(platform int, t *models.Torrent) string {
cat := fmt.Sprintf("%d_%d", t.Category, t.SubCategory)
// if we are in sukebei, there are some categories
if config.IsSukebei() {
// check that platform exist in our map for sukebei categories
if platform < len(sukebeiCategories) {
// return the remaped category if it exists
if val, ok := sukebeiCategories[platform][cat]; ok {
return val
}
}
}
// check that platform exist in our map
if platform >= len(normalCategories) {
return ""
}
// return the remaped category if it exists
if val, ok := normalCategories[platform][cat]; ok {
return val
}
return ""
}

Voir le fichier

@ -0,0 +1,38 @@
package upload
import (
"testing"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
"github.com/stretchr/testify/assert"
)
func TestCategory(t *testing.T) {
assert := assert.New(t)
dummyTorrent := &models.Torrent{Category: 1, SubCategory: 1}
tests := []struct {
torrent *models.Torrent
platform int
sukebei bool
expected string
}{
{dummyTorrent, anidex, false, ""},
{dummyTorrent, ttosho, false, "5"},
{dummyTorrent, ttosho, true, "12"},
{dummyTorrent, nyaasi, false, "6_1"},
{dummyTorrent, nyaasi, true, "1_1"},
{dummyTorrent, 20, true, ""},
{&models.Torrent{Category: 33, SubCategory: 33}, nyaasi, true, ""},
}
for _, test := range tests {
if test.sukebei {
// workaround to make the function believe we are in sukebei
config.Get().Models.TorrentsTableName = "sukebei_torrents"
} else {
config.Get().Models.TorrentsTableName = "torrents"
}
assert.Equal(test.expected, Category(test.platform, test.torrent))
}
}

Voir le fichier

@ -16,7 +16,6 @@ import (
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/utils/cache"
"github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/utils/upload/ttosho"
)
const (
@ -151,7 +150,7 @@ func ToTTosho(apiKey string, torrent *models.Torrent) {
//Required
"apikey": apiKey,
"url": torrent.Download(),
"type": ttoshoConfig.Category(torrent),
"type": Category(ttosho, torrent),
"send": "true",
//Optional

Voir le fichier

@ -1,53 +0,0 @@
package ttoshoConfig
import (
"fmt"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
)
// Convert automatically our sukebei cats to anidex Hentai cats
var sukebeiCategories = map[string]string{
"1_1": "12",
"1_2": "12",
"1_3": "14",
"1_4": "13",
"1_5": "4",
"2_1": "4",
"2_2": "15",
}
var normalCategories = map[string]string{
"3_12": "1",
"3_5": "1",
"3_13": "10",
"3_6": "7",
"2_3": "2",
"2_4": "2",
"4_7": "3",
"4_8": "7",
"4_14": "10",
"5_9": "8",
"5_10": "8",
"5_18": "10",
"5_11": "7",
"6_15": "5",
"6_16": "5",
"1_1": "5",
"1_2": "5",
}
// Category returns the category converted from nyaa one to tosho one
func Category(t *models.Torrent) string {
cat := fmt.Sprintf("%d_%d", t.Category, t.SubCategory)
if config.IsSukebei() {
if val, ok := sukebeiCategories[cat]; ok {
return val
}
}
if val, ok := normalCategories[cat]; ok {
return val
}
return ""
}