fetch movie details
This commit is contained in:
parent
c85371528a
commit
2fdcc0d259
|
@ -1,6 +1,9 @@
|
|||
package clients
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"ewintr.nl/emdb/movie"
|
||||
tmdb "github.com/cyruzin/golang-tmdb"
|
||||
)
|
||||
|
||||
|
@ -21,6 +24,39 @@ func NewTMDB(apikey string) (*TMDB, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (t TMDB) Search(query string) (*tmdb.SearchMovies, error) {
|
||||
return t.c.GetSearchMovies(query, nil)
|
||||
func (t TMDB) Search(query string) ([]movie.Movie, error) {
|
||||
results, err := t.c.GetSearchMovies(query, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
movies := make([]movie.Movie, len(results.Results))
|
||||
for i, result := range results.Results {
|
||||
movies[i], err = t.GetMovie(result.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return movies, nil
|
||||
}
|
||||
|
||||
func (t TMDB) GetMovie(id int64) (movie.Movie, error) {
|
||||
result, err := t.c.GetMovieDetails(int(id), nil)
|
||||
if err != nil {
|
||||
return movie.Movie{}, err
|
||||
}
|
||||
|
||||
var year int
|
||||
if release, err := time.Parse("2006-01-02", result.ReleaseDate); err == nil {
|
||||
year = release.Year()
|
||||
}
|
||||
|
||||
return movie.Movie{
|
||||
Title: result.Title,
|
||||
TMDBID: result.ID,
|
||||
Year: year,
|
||||
Summary: result.Overview,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
|
|
@ -15,11 +15,6 @@ func main() {
|
|||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
//
|
||||
//movies, err := tdb.Search("stark fear")
|
||||
//for _, m := range movies.Results {
|
||||
// fmt.Printf("result: %+v\n", m)
|
||||
//}
|
||||
|
||||
p := tui.New(tdb)
|
||||
if _, err := p.Run(); err != nil {
|
||||
|
|
|
@ -15,9 +15,9 @@ func (m Movie) FilterValue() string {
|
|||
}
|
||||
|
||||
func (m Movie) Title() string {
|
||||
return m.m.Title
|
||||
return fmt.Sprintf("%s (%d)", m.m.Title, m.m.Year)
|
||||
}
|
||||
|
||||
func (m Movie) Description() string {
|
||||
return fmt.Sprintf("description: %s", m.m.Title)
|
||||
return fmt.Sprintf("%s", m.m.Summary)
|
||||
}
|
||||
|
|
|
@ -4,12 +4,10 @@ import (
|
|||
"fmt"
|
||||
|
||||
"ewintr.nl/emdb/cmd/terminal-client/clients"
|
||||
"ewintr.nl/emdb/movie"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
"github.com/charmbracelet/bubbles/viewport"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
func New(tmdb *clients.TMDB) *tea.Program {
|
||||
|
@ -51,9 +49,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
case tea.WindowSizeMsg:
|
||||
if !m.ready {
|
||||
m.initialModel(msg.Width, msg.Height)
|
||||
} else {
|
||||
m.logViewport.Width = msg.Width
|
||||
m.logViewport.Height = 10
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,11 +78,15 @@ func (m *model) Search() {
|
|||
return
|
||||
}
|
||||
|
||||
m.Log(fmt.Sprintf("found %d results", len(movies)))
|
||||
items := []list.Item{}
|
||||
for _, res := range movies.Results {
|
||||
items = append(items, Movie{m: movie.Movie{Title: res.Title}})
|
||||
fmt.Printf("result: %+v\n", res.Title)
|
||||
for _, res := range movies {
|
||||
items = append(items, Movie{m: res})
|
||||
//fmt.Printf("result: %+v\n", res.Title)
|
||||
}
|
||||
//for i := 0; i < 10; i++ {
|
||||
// items = append(items, Movie{m: movie.Movie{Title: fmt.Sprintf("title %d", i)}})
|
||||
//}
|
||||
|
||||
m.searchResults.SetItems(items)
|
||||
m.focused = "result"
|
||||
|
@ -97,7 +96,7 @@ func (m model) View() string {
|
|||
if !m.ready {
|
||||
return "\n Initializing..."
|
||||
}
|
||||
return lipgloss.JoinVertical(lipgloss.Left, m.searchInput.View(), m.searchResults.View(), m.logViewport.View())
|
||||
return fmt.Sprintf("%s\n---\n%s\n---\n%s", m.searchInput.View(), m.searchResults.View(), m.logViewport.View())
|
||||
}
|
||||
|
||||
func (m *model) initialModel(width, height int) {
|
||||
|
@ -109,7 +108,7 @@ func (m *model) initialModel(width, height int) {
|
|||
m.searchInput = si
|
||||
m.searchInput.Focus()
|
||||
|
||||
m.searchResults = list.New([]list.Item{}, list.NewDefaultDelegate(), width, height-30)
|
||||
m.searchResults = list.New([]list.Item{}, list.NewDefaultDelegate(), width, height-50)
|
||||
m.searchResults.Title = "Search results"
|
||||
m.searchResults.SetShowHelp(false)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package movie
|
|||
|
||||
type Movie struct {
|
||||
ID string `json:"id"`
|
||||
TMDBID int64 `json:"tmdbID"`
|
||||
IMDBID string `json:"imdbID"`
|
||||
Title string `json:"title"`
|
||||
EnglishTitle string `json:"englishTitle"`
|
||||
|
@ -9,6 +10,7 @@ type Movie struct {
|
|||
Directors []string `json:"directors"`
|
||||
WatchedOn string `json:"watchedOn"`
|
||||
Rating int `json:"rating"`
|
||||
Summary string `json:"summary"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue