|
| 1 | +package scrape |
| 2 | + |
| 3 | +import ( |
| 4 | +"strconv" |
| 5 | +"strings" |
| 6 | +"sync" |
| 7 | + |
| 8 | +"github.com/gocolly/colly/v2" |
| 9 | +"github.com/mozillazg/go-slugify" |
| 10 | +"github.com/nleeper/goment" |
| 11 | +"github.com/thoas/go-funk" |
| 12 | +"github.com/xbapps/xbvr/pkg/models" |
| 13 | +) |
| 14 | + |
| 15 | +funcVirtualPee(wg*sync.WaitGroup,updateSitebool,knownScenes []string,outchan<- models.ScrapedScene,singleSceneURLstring,singeScrapeAdditionalInfostring,limitScrapingbool)error { |
| 16 | +deferwg.Done() |
| 17 | +scraperID:="virtualpee" |
| 18 | +siteID:="VirtualPee" |
| 19 | +logScrapeStart(scraperID,siteID) |
| 20 | + |
| 21 | +sceneCollector:=createCollector("virtualpee.com") |
| 22 | +siteCollector:=createCollector("virtualpee.com") |
| 23 | + |
| 24 | +sceneCollector.OnHTML(`html`,func(e*colly.HTMLElement) { |
| 25 | +sc:= models.ScrapedScene{} |
| 26 | +sc.ScraperID=scraperID |
| 27 | +sc.SceneType="VR" |
| 28 | +sc.Studio=siteID |
| 29 | +sc.Site=siteID |
| 30 | +sc.HomepageURL=strings.Split(e.Request.URL.String(),"?")[0] |
| 31 | +sc.MembersUrl=strings.Replace(sc.HomepageURL,"https://virtualpee.com","https://members.virtualpee.com",1) |
| 32 | + |
| 33 | +// Scene ID - get from URL |
| 34 | +tmp:=strings.SplitN(sc.HomepageURL,"-",2) |
| 35 | +sc.SiteID=tmp[1] |
| 36 | +sc.SceneID=slugify.Slugify(sc.Site)+"-"+sc.SiteID |
| 37 | + |
| 38 | +// Title |
| 39 | +sc.Title=e.Request.Ctx.Get("title") |
| 40 | + |
| 41 | +// Date |
| 42 | +tmpDate,_:=goment.New(e.Request.Ctx.Get("date"),"MMM DD, YYYY") |
| 43 | +sc.Released=tmpDate.Format("YYYY-MM-DD") |
| 44 | + |
| 45 | +// Duration |
| 46 | +tmpDuration,err:=strconv.Atoi(strings.Split(e.ChildText(`li.vid_duration`),":")[0]) |
| 47 | +iferr==nil { |
| 48 | +sc.Duration=tmpDuration |
| 49 | +} |
| 50 | + |
| 51 | +// Synopsis |
| 52 | +sc.Synopsis=strings.TrimSpace(e.ChildText(`div.col-md-12.right p`)) |
| 53 | + |
| 54 | +// Tags |
| 55 | +e.ForEach(`h5.tags a`,func(idint,e*colly.HTMLElement) { |
| 56 | +sc.Tags=append(sc.Tags,e.Text) |
| 57 | +}) |
| 58 | + |
| 59 | +// Cover |
| 60 | +sc.Covers=append(sc.Covers,e.ChildAttr(`figure span.vid_wrap img`,"src")) |
| 61 | + |
| 62 | +// Gallery |
| 63 | +e.ForEach(`ul.bxslider_pics li a img.lazy`,func(idint,e*colly.HTMLElement) { |
| 64 | +sc.Gallery=append(sc.Gallery,e.Attr("src")) |
| 65 | +}) |
| 66 | + |
| 67 | +// Cast |
| 68 | +sc.ActorDetails=make(map[string]models.ActorDetails) |
| 69 | +e.ForEach(`h2.video_title strong a`,func(idint,e*colly.HTMLElement) { |
| 70 | +name:=strings.TrimSpace(e.Text) |
| 71 | +sc.Cast=append(sc.Cast,name) |
| 72 | +sc.ActorDetails[name]= models.ActorDetails{ |
| 73 | +Source:scraperID+" scrape", |
| 74 | +ProfileUrl:e.Request.AbsoluteURL(e.Attr("href")), |
| 75 | +} |
| 76 | +}) |
| 77 | + |
| 78 | +out<-sc |
| 79 | +}) |
| 80 | + |
| 81 | +siteCollector.OnHTML(`a.next_page`,func(e*colly.HTMLElement) { |
| 82 | +if!limitScraping { |
| 83 | +pageURL:=e.Request.AbsoluteURL(e.Attr("href")) |
| 84 | +siteCollector.Visit(pageURL) |
| 85 | +} |
| 86 | +}) |
| 87 | + |
| 88 | +siteCollector.OnHTML(`li.row`,func(e*colly.HTMLElement) { |
| 89 | +sceneURL:=e.Request.AbsoluteURL(e.ChildAttr(`div.col-md-4.right h2 a`,"href")) |
| 90 | + |
| 91 | +ctx:=colly.NewContext() |
| 92 | +ctx.Put("date",strings.TrimSpace(e.ChildText("figure figcaption ul li strong"))) |
| 93 | +ctx.Put("title",strings.TrimSpace(e.ChildText("div.col-md-4.right h2 a"))) |
| 94 | + |
| 95 | +// If scene exist in database, there's no need to scrape |
| 96 | +if!funk.ContainsString(knownScenes,sceneURL) { |
| 97 | +sceneCollector.Request("GET",sceneURL,nil,ctx,nil) |
| 98 | +} |
| 99 | +}) |
| 100 | + |
| 101 | +ifsingleSceneURL!="" { |
| 102 | +ctx:=colly.NewContext() |
| 103 | +ctx.Put("date","") |
| 104 | + |
| 105 | +sceneCollector.Request("GET",singleSceneURL,nil,ctx,nil) |
| 106 | + |
| 107 | +}else { |
| 108 | +siteCollector.Visit("https://virtualpee.com/videos") |
| 109 | +} |
| 110 | + |
| 111 | +ifupdateSite { |
| 112 | +updateSiteLastUpdate(scraperID) |
| 113 | +} |
| 114 | +logScrapeFinished(scraperID,siteID) |
| 115 | +returnnil |
| 116 | +} |
| 117 | + |
| 118 | +funcinit() { |
| 119 | +registerScraper("virtualpee","VirtualPee","https://media.virtualpee.com/assets/images/logo.png","virtualpee.com",VirtualPee) |
| 120 | +} |