-
Notifications
You must be signed in to change notification settings - Fork 0
/
browse.go
112 lines (106 loc) · 3.39 KB
/
browse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"fmt"
"strings"
"sort"
"os"
"regexp"
"./xREL"
)
func showCategories(isP2P bool) {
orderedCategories := map[string][]string{}
if (isP2P) {
p2pCategories, err := xREL.GetP2PCategories()
ok(err, "Failed to get p2p categories:\n")
for i := 0; i < len(p2pCategories); i++ {
metaCat := strings.ToUpper(p2pCategories[i].MetaCat)
if p2pCategories[i].SubCat != "" {
orderedCategories[metaCat] = append(orderedCategories[metaCat], p2pCategories[i].SubCat)
} else {
if len(orderedCategories[metaCat]) == 0 {
orderedCategories[metaCat] = []string{}
}
}
}
fmt.Println("Available p2p categories:")
} else {
categories, err := xREL.GetReleaseCategories()
ok(err, "Failed to get scene categories:\n")
for i := 0; i < len(categories); i++ {
category := &categories[i]
if category.ParentCat != "" && category.Name != "" {
orderedCategories[category.ParentCat] = append(orderedCategories[category.ParentCat], category.Name)
} else {
if len(orderedCategories[category.Name]) == 0 {
orderedCategories[category.Name] = []string{}
}
}
}
fmt.Println("Available scene categories:")
}
var keys []string
for k := range orderedCategories {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := orderedCategories[k]
fmt.Println("\n" + k)
for i := 0; i < len(v); i++ {
fmt.Println("\t" + v[i])
}
}
}
func browseCategory(categoryName, extInfoType string, isP2P bool, perPage, page int) {
if (isP2P) {
categoryID, err := findP2PCategoryID(categoryName)
ok(err, "Failed to get category id:\n")
data, err := xREL.GetP2PReleases(perPage, page, categoryID, "", "")
ok(err, "Failed to browse p2p category:\n")
printP2PReleases(data, true, false)
} else {
// Currently all categories are upper case. That might change?
categoryName = strings.ToUpper(categoryName)
data, err := xREL.BrowseReleaseCategory(categoryName, extInfoType, perPage, page)
ok(err, "Failed to browse scene category:\n")
printSceneReleases(data, true, false)
}
}
func showFilters(isP2PFlag bool) {
if (isP2PFlag) {
fmt.Println("There are no P2P filters available.");
os.Exit(1)
}
filters, err := xREL.GetReleaseFilters()
ok(err, "Failed to get filters:\n")
fmt.Println("Available scene filters:\n")
for i := 0; i < len(filters); i++ {
fmt.Println(filters[i].Id + ": " + filters[i].Name)
}
}
func showLatest(filterFlag string, isP2PFlag bool, perPageFlag, pageFlag int) {
if (isP2PFlag) {
data, err := xREL.GetP2PReleases(perPageFlag, pageFlag, "", "", "")
ok(err, "Failed to get latest p2p releases:\n")
printP2PReleases(data, false, false)
} else {
data, err := xREL.GetLatestReleases(perPageFlag, pageFlag, filterFlag, "")
ok(err, "Failed to get latest scene releases:\n")
printSceneReleases(data, false, false)
}
}
func browseArchive(browseArchiveFlag, filterFlag string, isP2PFlag bool, perPageFlag, pageFlag int) {
if (isP2PFlag) {
fmt.Println("Due to API limitations it is impossible to browse the P2P archive.")
os.Exit(1)
} else {
matched, err := regexp.MatchString("^[0-9]{4}-[1-9]{2}$", browseArchiveFlag);
if err == nil && matched {
data, err := xREL.GetLatestReleases(perPageFlag, pageFlag, filterFlag, browseArchiveFlag)
ok(err, "Failed to browse the scene archive:\n")
printSceneReleases(data, false, false)
} else {
fmt.Println("Please use the following format: --browseArchive=YYYY-MM")
}
}
}