Added character download
This commit is contained in:
parent
65b51ef2b2
commit
1934ea4d82
59
jobs/download-character-images/download-character-images.go
Normal file
59
jobs/download-character-images/download-character-images.go
Normal 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()
|
||||
}
|
@ -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)
|
||||
.anime-grid-title
|
||||
.anime-grid-title-text= character.Name.Canonical
|
@ -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%
|
||||
|
@ -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
|
||||
@ -30,6 +24,15 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime
|
||||
|
||||
.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
|
||||
|
||||
.character-anime.mountable
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,10 +579,12 @@ export default class AnimeNotifier {
|
||||
extension = dataSrc.substring(dotPos)
|
||||
}
|
||||
|
||||
// Anime images on Retina displays
|
||||
if(base.includes("/anime/") && window.devicePixelRatio > 1) {
|
||||
// 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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user