Skip to content

Commit

Permalink
scrapers: Fix VRBangers Image URLs (xbapps#761)
Browse files Browse the repository at this point in the history
* Fix VRBanger Image URLs

* go fmt

Co-authored-by: crwxaj <[email protected]>
  • Loading branch information
toshski and crwxaj authored Jun 24, 2022
1 parent 5ac6355 commit ec46981
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
32 changes: 32 additions & 0 deletions pkg/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,38 @@ func Migrate() {
return nil
},
},
{
// some site, vrbangers & vrconk have blank covers, & vrbangers gallery images will not render due to double slashes ie .com//
ID: "0035-fix-vrbangers-images",
Migrate: func(tx *gorm.DB) error {
var scenes []models.Scene
err := tx.Where("studio LIKE ?", "VRBangers").Or("images LIKE ?", "%{\"url\":\"\",\"type\":\"gallery\",\"orientation\":\"\"}%").Find(&scenes).Error
if err != nil {
return err
}

for _, scene := range scenes {
changed := false
// check for a blank cover image and remove them
if strings.Contains(scene.Images, ",{\"url\":\"\",\"type\":\"cover\",\"orientation\":\"\"}") {
scene.Images = strings.ReplaceAll(scene.Images, ",{\"url\":\"\",\"type\":\"cover\",\"orientation\":\"\"}", "")
changed = true
}
// remove double slashes from image url for VRBangers
if scene.Studio == "VRBangers" && strings.Contains(scene.Images, ".com//") {
scene.Images = strings.ReplaceAll(scene.Images, ".com//", ".com/")
changed = true
}
if changed {
err = tx.Save(&scene).Error
if err != nil {
return err
}
}
}
return nil
},
},
})

if err := m.Migrate(); err != nil {
Expand Down
20 changes: 12 additions & 8 deletions pkg/models/model_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,21 @@ func SceneCreateUpdateFromExternal(db *gorm.DB, ext ScrapedScene) error {
var images []Image

for i := range ext.Covers {
images = append(images, Image{
URL: ext.Covers[i],
Type: "cover",
})
if ext.Covers[i] != "" {
images = append(images, Image{
URL: ext.Covers[i],
Type: "cover",
})
}
}

for i := range ext.Gallery {
images = append(images, Image{
URL: ext.Gallery[i],
Type: "gallery",
})
if ext.Gallery[i] != "" {
images = append(images, Image{
URL: ext.Gallery[i],
Type: "gallery",
})
}
}

imgTxt, err := json.Marshal(images)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scrape/vrbangers.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func VRBangersSite(wg *sync.WaitGroup, updateSite bool, knownScenes []string, ou
// Gallery - https://content.vrbangers.com/uploads/2021/08/611b4e0ca5c54351494706_XL.jpg
gallerytmp := gjson.Get(JsonMetadata, "data.item.galleryImages.#.previews.#(sizeAlias==XL).permalink")
for _, v := range gallerytmp.Array() {
sc.Gallery = append(sc.Gallery, contentURL+v.Str)
sc.Gallery = append(sc.Gallery, strings.Replace(contentURL+v.Str, ".com//", ".com/", 1))
}

// Synopsis
Expand Down

0 comments on commit ec46981

Please sign in to comment.