Added character download

This commit is contained in:
Eduard Urbach 2018-04-11 15:06:08 +02:00
parent 65b51ef2b2
commit 1934ea4d82
6 changed files with 89 additions and 15 deletions

View File

@ -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()
}

View File

@ -1,7 +1,11 @@
component Character(character *arn.Character) component Character(character *arn.Character)
a.character(href="/character/" + character.ID) a.character(href="/character/" + character.ID)
img.character-image.lazy(data-src=character.ImageLink("medium"), alt=character.Name.Canonical, title=character.Name.Canonical) 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) component CharacterSmall(character *arn.Character)
a.character(href="/character/" + character.ID) 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) 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

View File

@ -9,10 +9,8 @@
transform scale(1) transform scale(1)
:hover :hover
transform scale(1.05) .anime-grid-title
opacity 1
// .character-name
// opacity 1
.character-image .character-image
border-radius 5% border-radius 5%

View File

@ -9,13 +9,7 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime
.character-left-column .character-left-column
.character-header .character-header
.character-image-container.mountable .character-image-container.mountable
img.character-image-fullsize(src=character.ImageLink("large"), alt=character.Name.Canonical) img.character-image-large.lazy(data-src=character.ImageLink("large"), data-webp="true", data-color=character.AverageColor(), 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
.character-description-container .character-description-container
h1.character-name.mountable= character.Name.Canonical h1.character-name.mountable= character.Name.Canonical
@ -29,6 +23,15 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime
Quote(mainQuote) Quote(mainQuote)
.character-description.mountable!= markdown.Render(character.Description) .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 h3.mountable Anime

View File

@ -18,6 +18,12 @@
align-items center align-items center
margin-bottom 1rem margin-bottom 1rem
.character-image-large
width 225px
height 350px
border-radius ui-element-border-radius
box-shadow shadow-light
.character-description .character-description
margin-top 1.6rem margin-top 1.6rem

View File

@ -557,6 +557,8 @@ export default class AnimeNotifier {
} }
lazyLoadImage(element: HTMLImageElement) { lazyLoadImage(element: HTMLImageElement) {
let pixelRatio = window.devicePixelRatio
// Once the image becomes visible, load it // Once the image becomes visible, load it
element["became visible"] = () => { element["became visible"] = () => {
let dataSrc = element.dataset.src let dataSrc = element.dataset.src
@ -577,9 +579,11 @@ export default class AnimeNotifier {
extension = dataSrc.substring(dotPos) extension = dataSrc.substring(dotPos)
} }
// Anime images on Retina displays // Anime and character images on Retina displays
if(base.includes("/anime/") && window.devicePixelRatio > 1) { if(pixelRatio > 1) {
base += "@2" if(base.includes("/anime/") || (base.includes("/characters/") && !base.includes("/large/"))) {
base += "@2"
}
} }
let finalSrc = base + extension let finalSrc = base + extension