Skip to content

Commit

Permalink
fixing engine crash from search
Browse files Browse the repository at this point in the history
  • Loading branch information
deven96 committed Jan 10, 2021
1 parent f005fcf commit c9d9874
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
59 changes: 40 additions & 19 deletions engine/besthdmovies.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type BestHDEngine struct {

// NewBestHDEngine : A Movie Engine Constructor for BestHDEngine
func NewBestHDEngine() *BestHDEngine {
base := "https://www.besthdmovies.top/"
base := "https://www.besthdmovies.fit/"
baseURL, err := url.Parse(base)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -90,7 +90,7 @@ func (engine *BestHDEngine) parseSingleMovie(el *colly.HTMLElement, index int) (
}

func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collector, movies *[]Movie) {
submissionDetails := make(map[string]string)
// submissionDetails := make(map[string]string)
// Update movie download link if div.post-single-content on page
downloadCollector.OnHTML("div.post-single-content", func(e *colly.HTMLElement) {
movie := &(*movies)[getMovieIndexFromCtx(e.Request)]
Expand Down Expand Up @@ -123,14 +123,16 @@ func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collect
})

downloadCollector.OnHTML("div.content-area", func(e *colly.HTMLElement) {
movie := &(*movies)[getMovieIndexFromCtx(e.Request)]
movieIndex := getMovieIndexFromCtx(e.Request)
movie := &(*movies)[movieIndex]
links := e.ChildAttrs("a", "href")
for _, link := range links {
if strings.HasPrefix(link, "https://zeefiles") || strings.HasPrefix(link, "http://zeefiles") {
// change all http to https
if strings.HasPrefix(link, "http://") {
link = "https://" + strings.TrimPrefix(link, "http://")
}
link = link + "?movieIndex=" + strconv.Itoa(movieIndex)
downloadlink, err := url.Parse(link)
if err == nil {
movie.DownloadLink = downloadlink
Expand All @@ -145,21 +147,13 @@ func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collect
downloadCollector.OnHTML("div.freeDownload", func(e *colly.HTMLElement) {
movieIndex := getMovieIndexFromCtx(e.Request)
movie := &(*movies)[movieIndex]
zeesubmission := make(map[string]string)
if e.ChildAttr("a.link_button", "href") != "" {
downloadlink, err := url.Parse(e.ChildAttr("a.link_button", "href"))
if err == nil {
movie.DownloadLink = downloadlink
}
} else {

inputNames := e.ChildAttrs("input", "name")
inputValues := e.ChildAttrs("input", "value")

for index := range inputNames {
zeesubmission[inputNames[index]] = inputValues[index]
}

zeesubmission := getFormDetails(e)
err := downloadCollector.Post(movie.DownloadLink.String(), zeesubmission)
if err != nil {
log.Fatal(err)
Expand All @@ -172,15 +166,10 @@ func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collect
var err error
movie := &(*movies)[movieIndex]
downloadlink := movie.DownloadLink
inputNames := e.ChildAttrs("input", "name")
inputValues := e.ChildAttrs("input", "value")

for index := range inputNames {
submissionDetails[inputNames[index]] = inputValues[index]
}
submissionDetails := getFormDetails(e)
requestlink := e.Request.URL.String()
if !(strings.HasPrefix(requestlink, "https://zeefiles") || strings.HasPrefix(requestlink, "http://zeefiles")) {
downloadlink, err = url.Parse("https://udown.me/watchonline/?movieIndex=" + strconv.Itoa(movieIndex))
downloadlink, err = url.Parse("https://freeload.best/downloading/?movieIndex=" + strconv.Itoa(movieIndex))
if err == nil {
movie.DownloadLink = downloadlink
}
Expand All @@ -191,6 +180,38 @@ func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collect
}
})

downloadCollector.OnHTML("meta[http-equiv=refresh]", func(e *colly.HTMLElement) {
// Retrieve link when on freeload.best/downloading
movieIndex := getMovieIndexFromCtx(e.Request)
movie := &(*movies)[movieIndex]
content := e.Attr("content")
re := regexp.MustCompile(`url=(.*)`)
link := re.FindStringSubmatch(content)
if len(link) >= 1 {
downloadLink, _ := url.Parse(link[1])
movie.DownloadLink = downloadLink
}
})

downloadCollector.OnHTML("div.freeDownload", func(e *colly.HTMLElement) {
// Retrieve link when on zeefiles.download/id
movieIndex := getMovieIndexFromCtx(e.Request)
movie := &(*movies)[movieIndex]
linkButton := e.ChildAttr("a.link_button", "href")
if linkButton != "" {
movie.DownloadLink, _ = url.Parse(linkButton)
} else {
submissionDetails := getFormDetails(e)
downloadCollector.AllowURLRevisit = true
if !strings.Contains(movie.DownloadLink.String(), "download_token") {
err := downloadCollector.Post(movie.DownloadLink.String(), submissionDetails)
if err != nil {
log.Fatal(err)
}
}
}
})

downloadCollector.OnHTML("video", func(e *colly.HTMLElement) {
downloadlink := e.ChildAttr("source", "src")
movieIndex := getMovieIndexFromCtx(e.Request)
Expand Down
12 changes: 12 additions & 0 deletions engine/engines.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,15 @@ func getMovieIndexFromCtx(r *colly.Request) int {
}
return movieIndex
}

// Get all form details into a neat map
func getFormDetails(element *colly.HTMLElement) map[string]string {
submission := make(map[string]string)
inputNames := element.ChildAttrs("input", "name")
inputValues := element.ChildAttrs("input", "value")

for index := range inputNames {
submission[inputNames[index]] = inputValues[index]
}
return submission
}

0 comments on commit c9d9874

Please sign in to comment.