From d5dcd9c909019dceadaa43dff6a2c7e611b3d79c Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 28 Jun 2017 00:16:45 +0200 Subject: [PATCH] Tracks have permalinks now --- jobs/main.go | 13 ++++++----- jobs/refresh-track-titles/main.go | 37 +++++++++++++++++++++++++++++++ jobs/sync-anime/main.go | 2 +- main.go | 2 ++ mixins/SoundTrack.pixy | 13 +++++++++-- pages/dashboard/dashboard.pixy | 4 ++-- pages/posts/posts.go | 4 +++- pages/tracks/tracks.go | 21 ++++++++++++++++++ pages/tracks/tracks.pixy | 5 +++++ 9 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 jobs/refresh-track-titles/main.go create mode 100644 pages/tracks/tracks.go create mode 100644 pages/tracks/tracks.pixy diff --git a/jobs/main.go b/jobs/main.go index 54db996b..9368da98 100644 --- a/jobs/main.go +++ b/jobs/main.go @@ -23,12 +23,13 @@ var colorPool = []*color.Color{ } var jobs = map[string]time.Duration{ - "active-users": 1 * time.Minute, - "avatars": 1 * time.Hour, - "sync-anime": 10 * time.Hour, - "popular-anime": 11 * time.Hour, - "airing-anime": 12 * time.Hour, - "search-index": 13 * time.Hour, + "active-users": 1 * time.Minute, + "avatars": 1 * time.Hour, + "refresh-track-titles": 10 * time.Hour, + "sync-anime": 12 * time.Hour, + "popular-anime": 12 * time.Hour, + "airing-anime": 12 * time.Hour, + "search-index": 12 * time.Hour, } func main() { diff --git a/jobs/refresh-track-titles/main.go b/jobs/refresh-track-titles/main.go new file mode 100644 index 00000000..7bd9dd15 --- /dev/null +++ b/jobs/refresh-track-titles/main.go @@ -0,0 +1,37 @@ +package main + +import ( + "github.com/animenotifier/arn" + "github.com/fatih/color" +) + +func main() { + color.Yellow("Refreshing track titles") + + // Get a stream of all soundtracks + soundtracks, err := arn.StreamSoundTracks() + + if err != nil { + panic(err) + } + + // Iterate over the stream + for track := range soundtracks { + sync(track) + } + + color.Green("Finished.") +} + +func sync(track *arn.SoundTrack) { + for _, media := range track.Media { + media.RefreshMetaData() + println(media.Service, media.Title) + } + + err := track.Save() + + if err != nil { + panic(err) + } +} diff --git a/jobs/sync-anime/main.go b/jobs/sync-anime/main.go index 3ccdcacb..2f6fa7ec 100644 --- a/jobs/sync-anime/main.go +++ b/jobs/sync-anime/main.go @@ -22,7 +22,7 @@ func main() { sync(anime) } - println("Finished.") + color.Green("Finished.") } func sync(data *kitsu.Anime) { diff --git a/main.go b/main.go index 07e61e83..7dcf0e0c 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ import ( "github.com/animenotifier/notify.moe/pages/search" "github.com/animenotifier/notify.moe/pages/settings" "github.com/animenotifier/notify.moe/pages/threads" + "github.com/animenotifier/notify.moe/pages/tracks" "github.com/animenotifier/notify.moe/pages/user" "github.com/animenotifier/notify.moe/pages/users" "github.com/animenotifier/notify.moe/pages/webdev" @@ -61,6 +62,7 @@ func configure(app *aero.Application) *aero.Application { app.Ajax("/forum/:tag", forum.Get) app.Ajax("/threads/:id", threads.Get) app.Ajax("/posts/:id", posts.Get) + app.Ajax("/tracks/:id", tracks.Get) app.Ajax("/user", user.Get) app.Ajax("/user/:nick", profile.Get) app.Ajax("/user/:nick/threads", profile.GetThreadsByUser) diff --git a/mixins/SoundTrack.pixy b/mixins/SoundTrack.pixy index 301e853c..d7e9f85e 100644 --- a/mixins/SoundTrack.pixy +++ b/mixins/SoundTrack.pixy @@ -1,10 +1,19 @@ component SoundTrack(track *arn.SoundTrack) + SoundTrackMedia(track, track.Media[0]) + +component SoundTrackAllMedia(track *arn.SoundTrack) + each media in track.Media + SoundTrackMedia(track, media) + +component SoundTrackMedia(track *arn.SoundTrack, media *arn.ExternalMedia) .sound-track.mountable(id=track.ID) .sound-track-content a.sound-track-anime-link.ajax(href="/anime/" + track.MainAnime().ID) img.sound-track-anime-image.lazy(data-src=track.MainAnime().Image.Small, alt=track.MainAnime().Title.Canonical, title=track.MainAnime().Title.Canonical) - iframe.lazy(data-src=track.Media[0].EmbedLink()) + iframe.lazy(data-src=media.EmbedLink()) .sound-track-footer + a.ajax(href=track.Link()) + Icon("music") span posted by - a.ajax(href=track.CreatedByUser().Link())= track.CreatedByUser().Nick \ No newline at end of file + a.ajax(href=track.CreatedByUser().Link())= track.CreatedByUser().Nick + " " \ No newline at end of file diff --git a/pages/dashboard/dashboard.pixy b/pages/dashboard/dashboard.pixy index 588b8a1c..c6037c90 100644 --- a/pages/dashboard/dashboard.pixy +++ b/pages/dashboard/dashboard.pixy @@ -34,10 +34,10 @@ component Dashboard(posts []*arn.Post, soundTracks []*arn.SoundTrack, following for i := 0; i <= 4; i++ if i < len(soundTracks) - a.widget-element.ajax(href="/music") + a.widget-element.ajax(href=soundTracks[i].Link()) .widget-element-text Icon("music") - span= soundTracks[i].MainAnime().Title.Canonical + span= soundTracks[i].Media[0].Title else .widget-element .widget-element-text diff --git a/pages/posts/posts.go b/pages/posts/posts.go index de0e45bd..5e705172 100644 --- a/pages/posts/posts.go +++ b/pages/posts/posts.go @@ -1,6 +1,8 @@ package posts import ( + "net/http" + "github.com/aerogo/aero" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" @@ -12,7 +14,7 @@ func Get(ctx *aero.Context) string { post, err := arn.GetPost(id) if err != nil { - return ctx.Error(404, "Post not found", err) + return ctx.Error(http.StatusNotFound, "Post not found", err) } return ctx.HTML(components.Post(post)) diff --git a/pages/tracks/tracks.go b/pages/tracks/tracks.go new file mode 100644 index 00000000..deb9efdb --- /dev/null +++ b/pages/tracks/tracks.go @@ -0,0 +1,21 @@ +package tracks + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" +) + +// Get post. +func Get(ctx *aero.Context) string { + id := ctx.Get("id") + track, err := arn.GetSoundTrack(id) + + if err != nil { + return ctx.Error(http.StatusNotFound, "Track not found", err) + } + + return ctx.HTML(components.Track(track)) +} diff --git a/pages/tracks/tracks.pixy b/pages/tracks/tracks.pixy new file mode 100644 index 00000000..cb510210 --- /dev/null +++ b/pages/tracks/tracks.pixy @@ -0,0 +1,5 @@ +component Track(track *arn.SoundTrack) + h2= track.Media[0].Title + + .sound-tracks + SoundTrackAllMedia(track) \ No newline at end of file