Ejemplo n.º 1
0
func findP2PCategoryID(categoryName string) (string, error) {
	var (
		categoryID string
		err        error
		categories []types.P2PCategory
	)

	categories, err = xrel.GetP2PCategories()
	if err == nil {
		for i := 0; i < len(categories); i++ {
			category := categories[i]
			if category.SubCat != "" {
				if strings.ToLower(category.SubCat) == strings.ToLower(categoryName) {
					categoryID = category.ID
				}
			} else if strings.ToLower(category.MetaCat) == strings.ToLower(categoryName) {
				categoryID = category.ID
			}
			if categoryID != "" {
				break
			}
		}
		if categoryID == "" {
			err = errors.New("Category not found. Please choose one of --categories --p2p.")
		}
	}

	return categoryID, err
}
Ejemplo n.º 2
0
func showCategories(isP2P bool) {
	orderedCategories := map[string][]string{}
	if isP2P {
		p2pCategories, err := xrel.GetP2PCategories()
		categoryCount := len(p2pCategories)
		if categoryCount == 0 {
			fmt.Println("No p2p categories found.")
			os.Exit(1)
		}
		ok(err, "Failed to get p2p categories: ")
		for i := 0; i < categoryCount; 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()
		categoryCount := len(categories)
		if categoryCount == 0 {
			fmt.Println("No categories found.")
			os.Exit(1)
		}
		ok(err, "Failed to get scene categories: ")
		for i := 0; i < categoryCount; 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])
		}
	}
}