From 1934ea4d8217ee4a628a93d6ad601d1a233cbb93 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 11 Apr 2018 15:06:08 +0200 Subject: [PATCH] Added character download --- .../download-character-images.go | 59 +++++++++++++++++++ pages/anime/character.pixy | 6 +- pages/anime/character.scarlet | 6 +- pages/character/character.pixy | 17 +++--- pages/character/character.scarlet | 6 ++ scripts/AnimeNotifier.ts | 10 +++- 6 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 jobs/download-character-images/download-character-images.go diff --git a/jobs/download-character-images/download-character-images.go b/jobs/download-character-images/download-character-images.go new file mode 100644 index 00000000..8aa50267 --- /dev/null +++ b/jobs/download-character-images/download-character-images.go @@ -0,0 +1,59 @@ +package main + +import ( + "fmt" + "sort" + "time" + + "github.com/aerogo/http/client" + "github.com/animenotifier/arn" + "github.com/fatih/color" +) + +func main() { + color.Yellow("Updating anime ratings") + + defer color.Green("Finished.") + defer arn.Node.Close() + + characters := arn.FilterCharacters(func(character *arn.Character) bool { + return character.Image.LastModified == 0 + }) + + sort.Slice(characters, func(i, j int) bool { + return characters[i].ID < characters[j].ID + }) + + for index, character := range characters { + fmt.Printf("[%d / %d] %s %s\n", index+1, len(characters), character.ID, color.CyanString(character.String())) + download(character.ID) + } + + time.Sleep(time.Second) +} + +func download(characterID string) { + character, err := arn.GetCharacter(characterID) + + if err != nil { + color.Red(err.Error()) + return + } + + url := fmt.Sprintf("https://media.kitsu.io/characters/images/%s/original%s", character.GetMapping("kitsu/character"), character.Image.Extension) + response, err := client.Get(url).End() + + if err != nil { + color.Red(err.Error()) + return + } + + err = character.SetImageBytes(response.Bytes()) + + if err != nil { + color.Red(err.Error()) + return + } + + character.Save() +} diff --git a/pages/anime/character.pixy b/pages/anime/character.pixy index 476ddd20..5439747b 100644 --- a/pages/anime/character.pixy +++ b/pages/anime/character.pixy @@ -1,7 +1,11 @@ component Character(character *arn.Character) a.character(href="/character/" + character.ID) img.character-image.lazy(data-src=character.ImageLink("medium"), alt=character.Name.Canonical, title=character.Name.Canonical) + .anime-grid-title + .anime-grid-title-text= character.Name.Canonical component CharacterSmall(character *arn.Character) a.character(href="/character/" + character.ID) - img.character-image.character-image-small.lazy(data-src=character.ImageLink("small"), alt=character.Name.Canonical, title=character.Name.Canonical) \ No newline at end of file + img.character-image.character-image-small.lazy(data-src=character.ImageLink("small"), alt=character.Name.Canonical, title=character.Name.Canonical) + .anime-grid-title + .anime-grid-title-text= character.Name.Canonical \ No newline at end of file diff --git a/pages/anime/character.scarlet b/pages/anime/character.scarlet index 69b09822..2cadd9ef 100644 --- a/pages/anime/character.scarlet +++ b/pages/anime/character.scarlet @@ -9,10 +9,8 @@ transform scale(1) :hover - transform scale(1.05) - - // .character-name - // opacity 1 + .anime-grid-title + opacity 1 .character-image border-radius 5% diff --git a/pages/character/character.pixy b/pages/character/character.pixy index 75c94b83..11cc4e6c 100644 --- a/pages/character/character.pixy +++ b/pages/character/character.pixy @@ -9,13 +9,7 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime .character-left-column .character-header .character-image-container.mountable - img.character-image-fullsize(src=character.ImageLink("large"), alt=character.Name.Canonical) - - if user != nil && (user.Role == "editor" || user.Role == "admin") - .buttons - a.button(href=character.Link() + "/edit") - Icon("pencil") - span Edit character + img.character-image-large.lazy(data-src=character.ImageLink("large"), data-webp="true", data-color=character.AverageColor(), alt=character.Name.Canonical) .character-description-container h1.character-name.mountable= character.Name.Canonical @@ -29,6 +23,15 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime Quote(mainQuote) .character-description.mountable!= markdown.Render(character.Description) + + if user != nil && (user.Role == "editor" || user.Role == "admin") + .anime-summary-footer-container + .anime-summary-footer + .spacer + .buttons.anime-buttons + a.button.mountable(href=character.Link() + "/edit") + Icon("pencil") + span Edit character h3.mountable Anime diff --git a/pages/character/character.scarlet b/pages/character/character.scarlet index 73de7810..44e34784 100644 --- a/pages/character/character.scarlet +++ b/pages/character/character.scarlet @@ -18,6 +18,12 @@ align-items center margin-bottom 1rem +.character-image-large + width 225px + height 350px + border-radius ui-element-border-radius + box-shadow shadow-light + .character-description margin-top 1.6rem diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 44f45155..58fdedf1 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -557,6 +557,8 @@ export default class AnimeNotifier { } lazyLoadImage(element: HTMLImageElement) { + let pixelRatio = window.devicePixelRatio + // Once the image becomes visible, load it element["became visible"] = () => { let dataSrc = element.dataset.src @@ -577,9 +579,11 @@ export default class AnimeNotifier { extension = dataSrc.substring(dotPos) } - // Anime images on Retina displays - if(base.includes("/anime/") && window.devicePixelRatio > 1) { - base += "@2" + // Anime and character images on Retina displays + if(pixelRatio > 1) { + if(base.includes("/anime/") || (base.includes("/characters/") && !base.includes("/large/"))) { + base += "@2" + } } let finalSrc = base + extension