Пример #1
0
func main() {
	flag.Parse()
	if *address == "" || *username == "" || *password == "" {
		log.Fatalf("Address, user or password is missing: %s, %s, %s", *address, *username, *password)
	}

	k := kodi.New(*address+"/jsonrpc", *username, *password)

	resp, err := k.Files.GetSources(&kodi.FilesGetSourcesParams{
		Media: kodi.FILES_MEDIA_VIDEO,
	})
	if err != nil {
		fmt.Printf("ERROR: %v\n", err)
		return
	}
	for _, source := range resp.Result.Sources {
		fmt.Println(source.File)
		resp, err := k.Files.GetDirectory(&kodi.FilesGetDirectoryParams{
			Directory: source.File,
			Sort: &kodi.ListSort{
				Method: kodi.SORT_METHOD_TITLE,
			},
		})
		if err != nil {
			fmt.Printf("ERROR: %v\n", err)
		}
		for _, f := range resp.Result.Files {
			fmt.Println(f.File)
		}
	}
}
Пример #2
0
func main() {
	flag.Parse()
	if *address == "" || *username == "" || *password == "" {
		log.Fatalf("Address, user or password is missing: %s, %s, %s", *address, *username, *password)
	}

	k := kodi.New(*address+"/jsonrpc", *username, *password)

	sinceDate := time.Now().Add(-*duration)

	epResult, err := k.VideoLibrary.GetEpisodes(&kodi.VideoLibraryGetEpisodesParams{
		Properties: []kodi.VideoFieldsEpisode{
			kodi.EPISODE_FIELD_SHOW_TITLE,
			kodi.EPISODE_FIELD_TITLE,
			kodi.EPISODE_FIELD_LAST_PLAYED,
		},
		Filter: &kodi.VideoLibraryGetEpisodesFilter{
			ListFilterEpisodes: &kodi.ListFilterEpisodes{
				ListFilterRuleEpisodes: &kodi.ListFilterRuleEpisodes{
					Field:    kodi.EPISODE_FILTER_FIELD_LAST_PLAYED,
					Operator: kodi.OPERATOR_AFTER,
					Value:    sinceDate.Format("2006-01-02"),
				},
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	byDate := map[time.Time]int{}
	for _, edetails := range epResult.Result.Episodes {
		t, err := time.Parse("2006-01-02 15:04:05", edetails.LastPlayed)
		if err != nil {
			log.Fatal(err)
		}
		year, month, day := t.Date()
		d := time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
		v, ok := byDate[d]
		if ok {
			byDate[d] = v + 1
		} else {
			byDate[d] = v + 1
		}
	}
	for s, v := range byDate {
		fmt.Printf("%30s : %d\n", s, v)
	}
}
Пример #3
0
func main() {
	flag.Parse()
	if *address == "" || *username == "" || *password == "" {
		log.Fatalf("Address, user or password is missing: %s, %s, %s", *address, *username, *password)
	}

	k := kodi.New(*address+"/jsonrpc", *username, *password)

	switch *cmd {
	case "list":
		response, err := k.Playlist.GetPlaylists()
		if err != nil {
			log.Fatal(err)
		}
		if response.Error != nil {
			log.Fatal(response.Error)
		}
		for idx, playlist := range response.Result {
			fmt.Printf("%d : %3d : %q\n", idx, playlist.PlaylistId, playlist.PlaylistType)
		}
	case "getitems":
		response, err := k.Playlist.GetItems(
			&kodi.PlaylistGetItemsParams{
				PlaylistId: kodi.PlaylistId(*id),
			})
		if err != nil {
			log.Fatal(err)
		}
		if response.Error != nil {
			log.Fatal(response.Error)
		}
		for idx, item := range response.Result.Items {
			fmt.Printf("%d : %#v\n", idx, item)
		}
	default:
		log.Fatal("Unrecognized command: " + *cmd)
	}
}