2020-01-04 16:39:33 +00:00
package scraper
import (
2020-07-21 04:06:25 +00:00
"fmt"
"net/http"
"net/http/httptest"
2020-01-04 16:39:33 +00:00
"strings"
"testing"
"github.com/antchfx/htmlquery"
"github.com/stashapp/stash/pkg/models"
2020-07-21 04:06:25 +00:00
"github.com/stretchr/testify/assert"
2020-01-04 16:39:33 +00:00
"gopkg.in/yaml.v2"
)
// adapted from https://www.freeones.com/html/m_links/bio_Mia_Malkova.php
const htmlDoc1 = `
< ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
< html xmlns = "http://www.w3.org/1999/xhtml" xml : lang = "en" lang = "en" dir = "ltr" >
< head >
< title > Freeones : Mia Malkova Biography < / title >
< / head >
< body data - babe = "Mia Malkova" >
< div class = "ContentBlock Block1" >
< div class = "ContentBlockBody" style = "padding: 0px;" >
< table id = "biographyTable" border = "0" cellspacing = "0" cellpadding = "0" width = "100%" >
< tbody >
< tr >
< td class = "paramname" >
< div > < b > Babe Name : < / b > < / div >
< / td >
< td class = "paramvalue" >
< a href = "/html/m_links/Mia_Malkova/" > Mia Malkova < / a > & nbsp ;
< / td >
< / tr >
< tr >
< td class = "paramname" >
< div > < b > Profession : < / b > < / div >
< / td >
< td class = "paramvalue" > Porn Star
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Ethnicity : < / b >
< / td >
< td class = "paramvalue" >
Caucasian & nbsp ;
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Country of Origin : < / b >
< / td >
< td class = "paramvalue" >
< span class = "country-us" >
United States
< span >
< / span > < / span > < / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Date of Birth : < / b >
< / td >
< td class = "paramvalue" >
July 1 , 1992 ( 27 years old ) & nbsp ;
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Aliases : < / b >
< / td >
< td class = "paramvalue" >
Mia Bliss , Madison Clover , Madison Swan , Mia Mountain , Jessica & nbsp ;
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Eye Color : < / b >
< / td >
< td class = "paramvalue" >
Hazel & nbsp ;
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Hair Color : < / b >
< / td >
< td class = "paramvalue" >
Blonde & nbsp ;
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Height : < / b >
< / td >
< td class = "paramvalue" >
2020-08-12 01:17:43 +00:00
5 ft7
2020-01-04 16:39:33 +00:00
< / td >
< / tr >
2021-04-16 06:06:35 +00:00
< tr >
< td class = "paramname" >
< b > Weight : < / b >
< / td >
< td class = "paramvalue" >
2021-04-26 03:31:25 +00:00
126
2021-04-16 06:06:35 +00:00
< / td >
< / tr >
2020-01-04 16:39:33 +00:00
< tr >
< td class = "paramname" >
< b > Measurements : < / b >
< / td >
< td class = "paramvalue" >
34 C - 26 - 36
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Fake boobs : < / b >
< / td >
< td class = "paramvalue" >
No & nbsp ;
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Career Start And End < / b >
< / td >
< td class = "paramvalue" >
2012 - 2019
( 7 Years In The Business )
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Tattoos : < / b >
< / td >
< td class = "paramvalue" >
None & nbsp ;
< / td >
< / tr >
< tr >
< td class = "paramname" >
< b > Piercings : < / b >
< / td >
< td class = "paramvalue" >
2020-08-23 07:39:15 +00:00
< ! -- None -- > ;
2020-01-04 16:39:33 +00:00
< / td >
< / tr >
2021-04-16 06:06:35 +00:00
< tr >
< td class = "paramname" >
< b > Details : < / b >
< / td >
< td class = "paramvalue" >
Some girls are so damn hot that they can get you bent out of shape , and you will not even be mad at them for doing so . Well , tawny blonde Mia Malkova can bend her body into any shape she pleases , and that ’ s sure to satisfy all of the horny cocks and wet pussies out there . This girl has acrobatic and contortionist abilities that could even twist a pretzel into a new knot , which can be very helpful in the ... arrow_drop_down Some girls are so damn hot that they can get you bent out of shape , and you will not even be mad at them for doing so . Well , tawny blonde Mia Malkova can bend her body into any shape she pleases , and that ’ s sure to satisfy all of the horny cocks and wet pussies out there . This girl has acrobatic and contortionist abilities that could even twist a pretzel into a new knot , which can be very helpful in the VR Porn movies – trust us . Ankles behind her neck and feet over her back so she can kiss her toes , turned , twisted and gyrating , she can fuck any which way she wants ( and that ass ! ) , will surely make you fall in love with this hot Virtual Reality Porn slut , as she is one of the finest of them all . Talking about perfection , maybe it ’ s all the acrobatic work that keeps it in such gorgeous shape ? Who cares really , because you just want to take a big bite out of it and never let go . But it ’ s not all about the body . Mia ’ s also got a great smile , which might not sound kinky , but believe us , it is a smile that will heat up your innards and drop your pants . Is it her golden skin , her innocent pink lips or that heart - shaped face ? There is just too much good stuff going on with Mia Malkova , which is maybe why these past few years have heaped awards upon awards on this Southern California native . Mia came to VR Bangers for her first VR Porn video , so you know she ’ s only going for top - notch scenes with top - game performers , men , and women . Better hit up that yoga studio if you ever dream of being able to bang a flexible and talented chick like lady Malkova .
< / td >
< / tr >
2020-01-04 16:39:33 +00:00
< tr >
< td class = "paramname" >
< div > < b > Social Network Links : < / b > < / div >
< / td >
< td class = "paramvalue" >
< ul id = "socialmedia" >
2021-04-29 01:38:55 +00:00
< ! -- Adding twitter twice to verify distict post - processing -- >
< li class = "twitter" > < a href = "https://twitter.com/MiaMalkova" target = "_blank" alt = "Mia Malkova Twitter" title = "Mia Malkova Twitter" > Twitter < / a > < / li >
2020-01-04 16:39:33 +00:00
< li class = "twitter" > < a href = "https://twitter.com/MiaMalkova" target = "_blank" alt = "Mia Malkova Twitter" title = "Mia Malkova Twitter" > Twitter < / a > < / li >
< li class = "facebook" > < a href = "https://www.facebook.com/MiaMalcove" target = "_blank" alt = "Mia Malkova Facebook" title = "Mia Malkova Facebook" > Facebook < / a > < / li >
< li class = "youtube" > < a href = "https://www.youtube.com/channel/UCEPR0sZKa_ScMoyhemfB7nA" target = "_blank" alt = "Mia Malkova YouTube" title = "Mia Malkova YouTube" > YouTube < / a > < / li >
< li class = "instagram" > < a href = "https://www.instagram.com/mia_malkova/" target = "_blank" alt = "Mia Malkova Instagram" title = "Mia Malkova Instagram" > Instagram < / a > < / li >
< / ul >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
< / div >
< / body >
< / html >
`
func makeCommonXPath ( attr string ) string {
return ` //table[@id="biographyTable"]//tr/td[@class="paramname"]//b[text() = ' ` + attr + ` ']/ancestor::tr/td[@class="paramvalue"] `
}
2020-07-21 04:06:25 +00:00
func makeSimpleAttrConfig ( str string ) mappedScraperAttrConfig {
return mappedScraperAttrConfig {
Selector : str ,
}
}
func makeReplaceRegex ( regex string , with string ) mappedRegexConfig {
ret := mappedRegexConfig {
Regex : regex ,
With : with ,
}
2020-01-31 22:17:40 +00:00
return ret
}
2020-07-21 04:06:25 +00:00
func makeXPathConfig ( ) mappedPerformerScraperConfig {
config := mappedPerformerScraperConfig {
mappedConfig : make ( mappedConfig ) ,
}
2020-01-04 16:39:33 +00:00
2020-07-21 04:06:25 +00:00
config . mappedConfig [ "Name" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Babe Name:" ) + ` /a ` )
config . mappedConfig [ "Ethnicity" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Ethnicity:" ) )
config . mappedConfig [ "Aliases" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Aliases:" ) )
config . mappedConfig [ "EyeColor" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Eye Color:" ) )
config . mappedConfig [ "Measurements" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Measurements:" ) )
config . mappedConfig [ "FakeTits" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Fake boobs:" ) )
config . mappedConfig [ "Tattoos" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Tattoos:" ) )
2020-08-23 07:39:15 +00:00
config . mappedConfig [ "Piercings" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Piercings:" ) + "/comment()" )
2021-04-16 06:06:35 +00:00
config . mappedConfig [ "Details" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Details:" ) )
config . mappedConfig [ "HairColor" ] = makeSimpleAttrConfig ( makeCommonXPath ( "Hair Color:" ) )
2020-01-04 16:39:33 +00:00
2020-01-31 22:17:40 +00:00
// special handling for birthdate
2020-07-21 04:06:25 +00:00
birthdateAttrConfig := makeSimpleAttrConfig ( makeCommonXPath ( "Date of Birth:" ) )
2020-01-31 22:17:40 +00:00
2020-07-21 04:06:25 +00:00
var birthdateReplace mappedRegexConfigs
// make this leave the trailing space to test existing scrapers that do so
birthdateReplace = append ( birthdateReplace , makeReplaceRegex ( ` \(.* years old\) ` , "" ) )
2020-01-31 22:17:40 +00:00
2020-07-21 04:06:25 +00:00
birthdateReplaceAction := postProcessReplace ( birthdateReplace )
birthdateParseDate := postProcessParseDate ( "January 2, 2006" ) // "July 1, 1992 (27 years old) "
birthdateAttrConfig . postProcessActions = [ ] postProcessAction {
& birthdateReplaceAction ,
& birthdateParseDate ,
}
config . mappedConfig [ "Birthdate" ] = birthdateAttrConfig
2020-01-31 22:17:40 +00:00
// special handling for career length
// no colon in attribute header
2020-07-21 04:06:25 +00:00
careerLengthAttrConfig := makeSimpleAttrConfig ( makeCommonXPath ( "Career Start And End" ) )
2020-01-31 22:17:40 +00:00
2020-07-21 04:06:25 +00:00
var careerLengthReplace mappedRegexConfigs
2020-01-31 22:17:40 +00:00
careerLengthReplace = append ( careerLengthReplace , makeReplaceRegex ( ` \s+\(.*\) ` , "" ) )
2020-07-21 04:06:25 +00:00
careerLengthReplaceAction := postProcessReplace ( careerLengthReplace )
careerLengthAttrConfig . postProcessActions = [ ] postProcessAction {
& careerLengthReplaceAction ,
}
config . mappedConfig [ "CareerLength" ] = careerLengthAttrConfig
2020-01-31 22:17:40 +00:00
2020-07-21 04:06:25 +00:00
// use map post-process action for gender
genderConfig := makeSimpleAttrConfig ( makeCommonXPath ( "Profession:" ) )
genderMapAction := make ( postProcessMap )
genderMapAction [ "Porn Star" ] = "Female"
genderConfig . postProcessActions = [ ] postProcessAction {
& genderMapAction ,
}
config . mappedConfig [ "Gender" ] = genderConfig
2021-04-26 03:31:25 +00:00
// use fixed for Country
2020-08-12 01:17:43 +00:00
config . mappedConfig [ "Country" ] = mappedScraperAttrConfig {
Fixed : "United States" ,
2020-07-21 04:06:25 +00:00
}
2020-01-31 22:17:40 +00:00
2020-08-12 01:17:43 +00:00
heightConfig := makeSimpleAttrConfig ( makeCommonXPath ( "Height:" ) )
heightConvAction := postProcessFeetToCm ( true )
heightConfig . postProcessActions = [ ] postProcessAction {
& heightConvAction ,
}
config . mappedConfig [ "Height" ] = heightConfig
2021-04-26 03:31:25 +00:00
weightConfig := makeSimpleAttrConfig ( makeCommonXPath ( "Weight:" ) )
weightConvAction := postProcessLbToKg ( true )
weightConfig . postProcessActions = [ ] postProcessAction {
& weightConvAction ,
}
config . mappedConfig [ "Weight" ] = weightConfig
2021-04-29 01:38:55 +00:00
tagConfig := mappedScraperAttrConfig {
Selector : ` //ul[@id="socialmedia"]//a ` ,
}
config . Tags = make ( mappedConfig )
config . Tags [ "Name" ] = tagConfig
2020-01-04 16:39:33 +00:00
return config
}
func verifyField ( t * testing . T , expected string , actual * string , field string ) {
t . Helper ( )
if actual == nil || * actual != expected {
if actual == nil {
t . Errorf ( "Expected %s to be set to %s, instead got nil" , field , expected )
} else {
t . Errorf ( "Expected %s to be set to %s, instead got %s" , field , expected , * actual )
}
}
}
func TestScrapePerformerXPath ( t * testing . T ) {
reader := strings . NewReader ( htmlDoc1 )
doc , err := htmlquery . Parse ( reader )
if err != nil {
t . Errorf ( "Error loading document: %s" , err . Error ( ) )
return
}
xpathConfig := makeXPathConfig ( )
2020-07-21 04:06:25 +00:00
scraper := mappedScraper {
Performer : & xpathConfig ,
}
q := & xpathQuery {
doc : doc ,
2020-01-04 16:39:33 +00:00
}
2020-07-21 04:06:25 +00:00
performer , err := scraper . scrapePerformer ( q )
2020-01-04 16:39:33 +00:00
if err != nil {
t . Errorf ( "Error scraping performer: %s" , err . Error ( ) )
return
}
const performerName = "Mia Malkova"
const ethnicity = "Caucasian"
const country = "United States"
2020-01-31 22:17:40 +00:00
const birthdate = "1992-07-01"
2020-01-04 16:39:33 +00:00
const aliases = "Mia Bliss, Madison Clover, Madison Swan, Mia Mountain, Jessica"
const eyeColor = "Hazel"
const measurements = "34C-26-36"
const fakeTits = "No"
const careerLength = "2012 - 2019"
2020-08-23 07:39:15 +00:00
const tattoos = "None"
const piercings = "<!-- None -->"
2020-07-21 04:06:25 +00:00
const gender = "Female"
2021-04-26 03:31:25 +00:00
const height = "170" // 5ft7
2021-04-16 06:06:35 +00:00
const details = "Some girls are so damn hot that they can get you bent out of shape, and you will not even be mad at them for doing so. Well, tawny blonde Mia Malkova can bend her body into any shape she pleases, and that’ s sure to satisfy all of the horny cocks and wet pussies out there. This girl has acrobatic and contortionist abilities that could even twist a pretzel into a new knot, which can be very helpful in the ... arrow_drop_down Some girls are so damn hot that they can get you bent out of shape, and you will not even be mad at them for doing so. Well, tawny blonde Mia Malkova can bend her body into any shape she pleases, and that’ s sure to satisfy all of the horny cocks and wet pussies out there. This girl has acrobatic and contortionist abilities that could even twist a pretzel into a new knot, which can be very helpful in the VR Porn movies – trust us. Ankles behind her neck and feet over her back so she can kiss her toes, turned, twisted and gyrating, she can fuck any which way she wants (and that ass!), will surely make you fall in love with this hot Virtual Reality Porn slut, as she is one of the finest of them all. Talking about perfection, maybe it’ s all the acrobatic work that keeps it in such gorgeous shape? Who cares really, because you just want to take a big bite out of it and never let go. But it’ s not all about the body. Mia’ s also got a great smile, which might not sound kinky, but believe us, it is a smile that will heat up your innards and drop your pants. Is it her golden skin, her innocent pink lips or that heart-shaped face? There is just too much good stuff going on with Mia Malkova, which is maybe why these past few years have heaped awards upon awards on this Southern California native. Mia came to VR Bangers for her first VR Porn video, so you know she’ s only going for top-notch scenes with top-game performers, men, and women. Better hit up that yoga studio if you ever dream of being able to bang a flexible and talented chick like lady Malkova."
const hairColor = "Blonde"
2021-04-26 03:31:25 +00:00
const weight = "57" // 126 lb
2020-01-04 16:39:33 +00:00
verifyField ( t , performerName , performer . Name , "Name" )
2020-07-21 04:06:25 +00:00
verifyField ( t , gender , performer . Gender , "Gender" )
2020-01-04 16:39:33 +00:00
verifyField ( t , ethnicity , performer . Ethnicity , "Ethnicity" )
verifyField ( t , country , performer . Country , "Country" )
2020-01-31 22:17:40 +00:00
2020-01-04 16:39:33 +00:00
verifyField ( t , birthdate , performer . Birthdate , "Birthdate" )
2020-01-31 22:17:40 +00:00
2020-01-04 16:39:33 +00:00
verifyField ( t , aliases , performer . Aliases , "Aliases" )
verifyField ( t , eyeColor , performer . EyeColor , "EyeColor" )
verifyField ( t , measurements , performer . Measurements , "Measurements" )
verifyField ( t , fakeTits , performer . FakeTits , "FakeTits" )
2020-01-31 22:17:40 +00:00
verifyField ( t , careerLength , performer . CareerLength , "CareerLength" )
2020-01-04 16:39:33 +00:00
2020-08-23 07:39:15 +00:00
verifyField ( t , tattoos , performer . Tattoos , "Tattoos" )
verifyField ( t , piercings , performer . Piercings , "Piercings" )
2020-08-12 01:17:43 +00:00
verifyField ( t , height , performer . Height , "Height" )
2021-04-16 06:06:35 +00:00
verifyField ( t , details , performer . Details , "Details" )
verifyField ( t , hairColor , performer . HairColor , "HairColor" )
verifyField ( t , weight , performer . Weight , "Weight" )
2021-04-29 01:38:55 +00:00
expectedTagNames := [ ] string {
"Twitter" ,
"Facebook" ,
"YouTube" ,
"Instagram" ,
}
for i , expected := range expectedTagNames {
verifyField ( t , expected , & performer . Tags [ i ] . Name , "TagName" )
}
2020-01-04 16:39:33 +00:00
}
2020-01-31 22:17:40 +00:00
func TestConcatXPath ( t * testing . T ) {
const firstName = "FirstName"
const lastName = "LastName"
const eyeColor = "EyeColor"
const separator = " "
const testDoc = `
< html >
< div > ` + firstName + ` < / div >
< div > ` + lastName + ` < / div >
< span > ` + eyeColor + ` < / span >
< / html >
`
reader := strings . NewReader ( testDoc )
doc , err := htmlquery . Parse ( reader )
if err != nil {
t . Errorf ( "Error loading document: %s" , err . Error ( ) )
return
}
2020-07-21 04:06:25 +00:00
xpathConfig := make ( mappedConfig )
nameAttrConfig := mappedScraperAttrConfig {
Selector : "//div" ,
Concat : separator ,
}
2020-01-31 22:17:40 +00:00
xpathConfig [ "Name" ] = nameAttrConfig
2020-07-21 04:06:25 +00:00
xpathConfig [ "EyeColor" ] = makeSimpleAttrConfig ( "//span" )
scraper := mappedScraper {
Performer : & mappedPerformerScraperConfig {
mappedConfig : xpathConfig ,
} ,
}
2020-01-31 22:17:40 +00:00
2020-07-21 04:06:25 +00:00
q := & xpathQuery {
doc : doc ,
2020-01-31 22:17:40 +00:00
}
2020-07-21 04:06:25 +00:00
performer , err := scraper . scrapePerformer ( q )
2020-01-31 22:17:40 +00:00
if err != nil {
t . Errorf ( "Error scraping performer: %s" , err . Error ( ) )
return
}
const performerName = firstName + separator + lastName
verifyField ( t , performerName , performer . Name , "Name" )
verifyField ( t , eyeColor , performer . EyeColor , "EyeColor" )
}
2020-01-04 16:39:33 +00:00
const sceneHTML = `
< ! DOCTYPE html >
< head >
< title > Test Video - Pornhub . com < / title >
< meta property = "og:title" content = "Test Video" / >
< script type = "application/ld+json" >
{
"name" : "Test Video" ,
"uploadDate" : "2019-10-13T00:33:51+00:00" ,
2020-07-21 04:06:25 +00:00
"author" : "Mia Malkova"
2020-01-04 16:39:33 +00:00
}
< / script >
< / head >
< body class = "logged-out" >
< div class = "container " >
2020-07-21 04:06:25 +00:00
< div id = "main-container" class = "clearfix" >
2020-01-04 16:39:33 +00:00
< div id = "vpContentContainer" >
< div id = "hd-leftColVideoPage" >
< div class = "video-wrapper" >
2020-07-21 04:06:25 +00:00
< div class = "title-container" >
< i class = "isMe tooltipTrig" data - title = "Video of verified member" > < / i >
2020-01-04 16:39:33 +00:00
< h1 class = "title" >
< span class = "inlineFree" > Test Video < / span >
< / h1 >
< / div >
< div class = "video-actions-container" >
< div class = "video-actions-tabs" >
< div class = "video-action-tab about-tab active" >
< div class = "video-detailed-info" >
< div class = "video-info-row" >
From : & nbsp ;
2020-07-21 04:06:25 +00:00
< div class = "usernameWrap clearfix" data - type = "channel" >
2020-01-04 16:39:33 +00:00
< a rel = "" href = "/channels/sis-loves-me" class = "bolded" > Sis Loves Me < / a >
< / div >
< / div >
< div class = "video-info-row" >
< div class = "pornstarsWrapper" >
Pornstars : & nbsp ;
< a class = "pstar-list-btn js-mxp" data - mxptype = "Pornstar"
2020-07-21 04:06:25 +00:00
data - mxptext = "Alex D" href = "/pornstar/alex-d" > Alex D
2020-01-04 16:39:33 +00:00
< / a >
, < a class = "pstar-list-btn js-mxp" data - mxptype = "Pornstar"
2020-07-21 04:06:25 +00:00
data - mxptext = "Mia Malkova" href = "/pornstar/mia-malkova" >
2020-01-04 16:39:33 +00:00
< / a >
, < a class = "pstar-list-btn js-mxp" data - mxptype = "Pornstar"
2020-07-21 04:06:25 +00:00
data - mxptext = "Riley Reid" href = "/pornstar/riley-reid" > Riley Reid
2020-01-04 16:39:33 +00:00
< / a >
< div class = "tooltipTrig suggestBtn" data - title = "Add a pornstar" >
< a class = "add-btn-small add-pornstar-btn-2" > +
< span > Suggest < / span > < / a >
< / div >
< / div >
< / div >
< div class = "video-info-row showLess" >
< div class = "categoriesWrapper" >
Categories : & nbsp ;
< a href = "/video?c=3"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > Amateur < / a > ,
< a href = "/categories/babe"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > Babe < / a > ,
< a href = "/video?c=13"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > Blowjob < / a > ,
< a href = "/video?c=115"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > Exclusive < / a > ,
< a href = "/hd"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > HD
Porn < / a > , < a href = "/categories/pornstar"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > Pornstar < / a > ,
< a href = "/video?c=24"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > Public < / a > ,
< a href = "/video?c=131"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > Pussy
Licking < / a > , < a href = "/video?c=65"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > Threesome < / a > ,
< a href = "/video?c=139"
onclick = "ga('send', 'event', 'Watch Page', 'click', 'Category');" > Verified
Models < / a >
< div class = "tooltipTrig suggestBtn" data - title = "Suggest Categories" >
< a id = "categoryLink" class = "add-btn-small " > +
< span > Suggest < / span > < / a >
< / div >
< / div >
< / div >
< div class = "video-info-row showLess" >
< div class = "tagsWrapper" >
Tags : & nbsp ;
< a href = "/video/search?search=3some" > 3 some < / a > , < a
href = "/video?c=9" > blonde < / a > , < a href = "/video?c=59" > small tits < / a > ,
< a href = "/video/search?search=butt" > butt < / a > , < a
href = "/video/search?search=natural+tits" > natural tits < / a > , < a
href = "/video/search?search=petite" > petite < / a > , < a
href = "/video?c=24" > public < / a > , < a
href = "/video/search?search=outside" > outside < / a > , < a
href = "/video/search?search=car" > car < / a > , < a
href = "/video/search?search=garage" > garage < / a > , < a
href = "/video?c=65" > threesome < / a > , < a
href = "/video/search?search=bgg" > bgg < / a > , < a
href = "/video/search?search=girlfrien+d" > girlfrien d < / a > , < a
href = "/video/search?search=parking" > parking < / a > , < a
href = "/video/search?search=sex" > sex < / a > , < a
href = "/video/search?search=gagging" > gagging < / a > , < a
href = "/video?c=13" > blowjob < / a > , < a
href = "/video/search?search=bj" > bj < / a > , < a
href = "/video/search?search=double" > double < / a > , < a
href = "/video/search?search=ass" > ass < / a >
< div class = "tooltipTrig suggestBtn" data - title = "Suggest Tags" >
< a id = "tagLink" class = "add-btn-small" > + < span > Suggest < / span > < / a >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / body >
< / html > `
2020-07-21 04:06:25 +00:00
func makeSceneXPathConfig ( ) mappedScraper {
common := make ( commonMappedConfig )
2020-01-04 16:39:33 +00:00
common [ "$performerElem" ] = ` //div[@class="pornstarsWrapper"]/a[@data-mxptype="Pornstar"] `
common [ "$studioElem" ] = ` //div[@data-type="channel"]/a `
2020-07-21 04:06:25 +00:00
config := mappedSceneScraperConfig {
mappedConfig : make ( mappedConfig ) ,
}
2020-01-04 16:39:33 +00:00
2020-07-21 04:06:25 +00:00
config . mappedConfig [ "Title" ] = makeSimpleAttrConfig ( ` //meta[@property="og:title"]/@content ` )
2020-01-04 16:39:33 +00:00
// this needs post-processing
2020-07-21 04:06:25 +00:00
config . mappedConfig [ "Date" ] = makeSimpleAttrConfig ( ` //script[@type="application/ld+json"] ` )
2020-01-04 16:39:33 +00:00
2020-07-21 04:06:25 +00:00
tagConfig := make ( mappedConfig )
tagConfig [ "Name" ] = makeSimpleAttrConfig ( ` //div[@class="categoriesWrapper"]//a[not(@class="add-btn-small ")] ` )
config . Tags = tagConfig
2020-01-04 16:39:33 +00:00
2020-07-21 04:06:25 +00:00
performerConfig := make ( mappedConfig )
performerConfig [ "Name" ] = makeSimpleAttrConfig ( ` $performerElem/@data-mxptext ` )
performerConfig [ "URL" ] = makeSimpleAttrConfig ( ` $performerElem/@href ` )
2021-03-10 01:25:51 +00:00
config . Performers . mappedConfig = performerConfig
2020-01-04 16:39:33 +00:00
2020-07-21 04:06:25 +00:00
studioConfig := make ( mappedConfig )
studioConfig [ "Name" ] = makeSimpleAttrConfig ( ` $studioElem ` )
studioConfig [ "URL" ] = makeSimpleAttrConfig ( ` $studioElem/@href ` )
config . Studio = studioConfig
2020-01-04 16:39:33 +00:00
2020-06-18 00:47:10 +00:00
const sep = " "
2020-07-21 04:06:25 +00:00
moviesNameConfig := mappedScraperAttrConfig {
Selector : ` //i[@class="isMe tooltipTrig"]/@data-title ` ,
Split : sep ,
}
moviesConfig := make ( mappedConfig )
2020-06-18 00:47:10 +00:00
moviesConfig [ "Name" ] = moviesNameConfig
2020-07-21 04:06:25 +00:00
config . Movies = moviesConfig
2020-06-18 00:47:10 +00:00
2020-07-21 04:06:25 +00:00
scraper := mappedScraper {
Scene : & config ,
2020-01-04 16:39:33 +00:00
Common : common ,
}
return scraper
}
func verifyTags ( t * testing . T , expectedTagNames [ ] string , actualTags [ ] * models . ScrapedSceneTag ) {
t . Helper ( )
i := 0
for i < len ( expectedTagNames ) || i < len ( actualTags ) {
expectedTag := ""
actualTag := ""
if i < len ( expectedTagNames ) {
expectedTag = expectedTagNames [ i ]
}
if i < len ( actualTags ) {
actualTag = actualTags [ i ] . Name
}
if expectedTag != actualTag {
t . Errorf ( "Expected tag %s, got %s" , expectedTag , actualTag )
}
i ++
}
}
2020-06-18 00:47:10 +00:00
func verifyMovies ( t * testing . T , expectedMovieNames [ ] string , actualMovies [ ] * models . ScrapedSceneMovie ) {
t . Helper ( )
i := 0
for i < len ( expectedMovieNames ) || i < len ( actualMovies ) {
expectedMovie := ""
actualMovie := ""
if i < len ( expectedMovieNames ) {
expectedMovie = expectedMovieNames [ i ]
}
if i < len ( actualMovies ) {
actualMovie = actualMovies [ i ] . Name
}
if expectedMovie != actualMovie {
t . Errorf ( "Expected movie %s, got %s" , expectedMovie , actualMovie )
}
i ++
}
}
2020-01-04 16:39:33 +00:00
func verifyPerformers ( t * testing . T , expectedNames [ ] string , expectedURLs [ ] string , actualPerformers [ ] * models . ScrapedScenePerformer ) {
t . Helper ( )
i := 0
for i < len ( expectedNames ) || i < len ( actualPerformers ) {
expectedName := ""
actualName := ""
expectedURL := ""
actualURL := ""
if i < len ( expectedNames ) {
expectedName = expectedNames [ i ]
}
if i < len ( expectedURLs ) {
expectedURL = expectedURLs [ i ]
}
if i < len ( actualPerformers ) {
actualName = actualPerformers [ i ] . Name
if actualPerformers [ i ] . URL != nil {
actualURL = * actualPerformers [ i ] . URL
}
}
if expectedName != actualName {
t . Errorf ( "Expected performer name %s, got %s" , expectedName , actualName )
}
if expectedURL != actualURL {
t . Errorf ( "Expected perfromer URL %s, got %s" , expectedName , actualName )
}
i ++
}
}
func TestApplySceneXPathConfig ( t * testing . T ) {
reader := strings . NewReader ( sceneHTML )
doc , err := htmlquery . Parse ( reader )
if err != nil {
t . Errorf ( "Error loading document: %s" , err . Error ( ) )
return
}
scraper := makeSceneXPathConfig ( )
2020-07-21 04:06:25 +00:00
q := & xpathQuery {
doc : doc ,
}
scene , err := scraper . scrapeScene ( q )
2020-01-04 16:39:33 +00:00
if err != nil {
t . Errorf ( "Error scraping scene: %s" , err . Error ( ) )
return
}
const title = "Test Video"
verifyField ( t , title , scene . Title , "Title" )
// verify tags
expectedTags := [ ] string {
"Amateur" ,
"Babe" ,
"Blowjob" ,
"Exclusive" ,
"HD Porn" ,
"Pornstar" ,
"Public" ,
"Pussy Licking" ,
"Threesome" ,
"Verified Models" ,
}
verifyTags ( t , expectedTags , scene . Tags )
2020-06-18 00:47:10 +00:00
// verify movies
expectedMovies := [ ] string {
"Video" ,
"of" ,
"verified" ,
"member" ,
}
verifyMovies ( t , expectedMovies , scene . Movies )
2020-01-04 16:39:33 +00:00
expectedPerformerNames := [ ] string {
"Alex D" ,
"Mia Malkova" ,
"Riley Reid" ,
}
expectedPerformerURLs := [ ] string {
"/pornstar/alex-d" ,
"/pornstar/mia-malkova" ,
"/pornstar/riley-reid" ,
}
verifyPerformers ( t , expectedPerformerNames , expectedPerformerURLs , scene . Performers )
const expectedStudioName = "Sis Loves Me"
const expectedStudioURL = "/channels/sis-loves-me"
verifyField ( t , expectedStudioName , & scene . Studio . Name , "Studio.Name" )
verifyField ( t , expectedStudioURL , scene . Studio . URL , "Studio.URL" )
}
func TestLoadXPathScraperFromYAML ( t * testing . T ) {
const yamlStr = ` name : Test
performerByURL :
- action : scrapeXPath
url :
- test . com
scraper : performerScraper
xPathScrapers :
performerScraper :
performer :
name : //h1[@itemprop="name"]
2020-07-21 04:06:25 +00:00
sceneScraper :
scene :
Title :
selector : //title
postProcess :
- parseDate : January 2 , 2006
Tags :
Name : //tags
Movies :
Name : //movies
Performers :
Name : //performers
Studio :
Name : //studio
2020-01-04 16:39:33 +00:00
`
2020-07-21 04:06:25 +00:00
c := & config { }
err := yaml . Unmarshal ( [ ] byte ( yamlStr ) , & c )
2020-01-04 16:39:33 +00:00
if err != nil {
t . Errorf ( "Error loading yaml: %s" , err . Error ( ) )
return
}
2020-07-21 04:06:25 +00:00
// ensure fields are filled in correctly
sceneScraper := c . XPathScrapers [ "sceneScraper" ]
sceneConfig := sceneScraper . Scene
assert . Equal ( t , "//title" , sceneConfig . mappedConfig [ "Title" ] . Selector )
assert . Equal ( t , "//tags" , sceneConfig . Tags [ "Name" ] . Selector )
assert . Equal ( t , "//movies" , sceneConfig . Movies [ "Name" ] . Selector )
2021-03-10 01:25:51 +00:00
assert . Equal ( t , "//performers" , sceneConfig . Performers . mappedConfig [ "Name" ] . Selector )
2020-07-21 04:06:25 +00:00
assert . Equal ( t , "//studio" , sceneConfig . Studio [ "Name" ] . Selector )
postProcess := sceneConfig . mappedConfig [ "Title" ] . postProcessActions
parseDate := postProcess [ 0 ] . ( * postProcessParseDate )
assert . Equal ( t , "January 2, 2006" , string ( * parseDate ) )
2020-01-04 16:39:33 +00:00
}
2020-01-25 03:36:24 +00:00
func TestLoadInvalidXPath ( t * testing . T ) {
2020-07-21 04:06:25 +00:00
config := make ( mappedConfig )
2020-01-25 03:36:24 +00:00
2020-07-21 04:06:25 +00:00
config [ "Name" ] = makeSimpleAttrConfig ( ` //a[id=']/span ` )
2020-01-25 03:36:24 +00:00
reader := strings . NewReader ( htmlDoc1 )
doc , err := htmlquery . Parse ( reader )
if err != nil {
t . Errorf ( "Error loading document: %s" , err . Error ( ) )
return
}
2020-07-21 04:06:25 +00:00
q := & xpathQuery {
doc : doc ,
}
config . process ( q , nil )
}
2021-04-11 23:31:33 +00:00
type mockGlobalConfig struct { }
func ( mockGlobalConfig ) GetScraperUserAgent ( ) string {
return ""
}
func ( mockGlobalConfig ) GetScrapersPath ( ) string {
return ""
}
func ( mockGlobalConfig ) GetScraperCDPPath ( ) string {
return ""
}
func ( mockGlobalConfig ) GetScraperCertCheck ( ) bool {
return false
}
2020-07-21 04:06:25 +00:00
func TestSubScrape ( t * testing . T ) {
retHTML := `
< div >
< a href = "/getName" > A link < / a >
< / div >
`
ssHTML := `
< span > The name < / span >
`
ts := httptest . NewServer ( http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) {
if r . URL . Path == "/getName" {
fmt . Fprint ( w , ssHTML )
} else {
fmt . Fprint ( w , retHTML )
}
} ) )
defer ts . Close ( )
yamlStr := ` name : Test
performerByURL :
- action : scrapeXPath
url :
- ` + ts.URL + `
scraper : performerScraper
xPathScrapers :
performerScraper :
performer :
Name :
selector : //div/a/@href
postProcess :
- replace :
- regex : ^
with : ` + ts.URL + `
- subScraper :
selector : //span
`
c := & config { }
err := yaml . Unmarshal ( [ ] byte ( yamlStr ) , & c )
if err != nil {
t . Errorf ( "Error loading yaml: %s" , err . Error ( ) )
return
}
2021-04-11 23:31:33 +00:00
globalConfig := mockGlobalConfig { }
2020-07-21 04:06:25 +00:00
2021-01-18 01:23:20 +00:00
performer , err := c . ScrapePerformerURL ( ts . URL , nil , globalConfig )
2020-07-21 04:06:25 +00:00
if err != nil {
t . Errorf ( "Error scraping performer: %s" , err . Error ( ) )
return
}
verifyField ( t , "The name" , performer . Name , "Name" )
2020-01-25 03:36:24 +00:00
}