Images - NASA Image, Video, and Audio Library
Images - NASA Image, Video, and Audio Library
Section titled “Images - NASA Image, Video, and Audio Library”The ImageService provides access to NASA’s Image, Video, and Audio Library. No API key is required.
Methods
Section titled “Methods”| Method | Signature | Description |
|---|---|---|
Search | Search(ctx context.Context, query string, opts ...ImageSearchOption) (*ImageCollection, error) | Search images, videos, and audio |
Asset | Asset(ctx context.Context, nasaID string) (*AssetManifest, error) | Get asset manifest for a NASA ID |
Metadata | Metadata(ctx context.Context, nasaID string) (map[string]any, error) | Get metadata for a NASA ID |
Captions | Captions(ctx context.Context, nasaID string) (string, error) | Get captions for a video |
Search Options
Section titled “Search Options”nasa.ImageWithMediaType("image") // filter by type: image, video, audionasa.ImageWithYearStart(2020) // results from this year or laternasa.ImageWithYearEnd(2024) // results up to this yearnasa.ImageWithCenter("JPL") // filter by NASA centernasa.ImageWithKeywords("mars") // filter by keywordsnasa.ImageWithPage(2) // results page numbernasa.ImageWithPageSize(50) // results per pageResponse Types
Section titled “Response Types”ImageCollection
Section titled “ImageCollection”type ImageCollection struct { Items []*ImageItem TotalHits int NextPage string PrevPage string}ImageItem
Section titled “ImageItem”type ImageItem struct { NasaID string Title string Description string MediaType string Center string DateCreated time.Time Keywords []string Photographer string Location string PreviewURL string AssetURL string}AssetManifest
Section titled “AssetManifest”type AssetManifest struct { Items []AssetItem}
type AssetItem struct { Href string}Example: Search for Apollo 11
Section titled “Example: Search for Apollo 11”package main
import ( "context" "fmt" "log"
"github.com/peteretelej/nasa")
func main() { client := nasa.NewClient()
results, err := client.Images.Search( context.Background(), "apollo 11", nasa.ImageWithMediaType("image"), ) if err != nil { log.Fatal(err) }
fmt.Printf("Total hits: %d\n\n", results.TotalHits) for _, item := range results.Items { fmt.Printf("%s (ID: %s)\n", item.Title, item.NasaID) if item.PreviewURL != "" { fmt.Printf(" Preview: %s\n", item.PreviewURL) } }}Example: Get Asset URLs
Section titled “Example: Get Asset URLs”package main
import ( "context" "fmt" "log"
"github.com/peteretelej/nasa")
func main() { client := nasa.NewClient()
manifest, err := client.Images.Asset(context.Background(), "as11-40-5874") if err != nil { log.Fatal(err) }
for _, asset := range manifest.Items { fmt.Println(asset.Href) }}