-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
84 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package extractors | ||
|
||
import ( | ||
"github.com/iawia002/annie/downloader" | ||
"github.com/iawia002/annie/parser" | ||
"github.com/iawia002/annie/request" | ||
"github.com/iawia002/annie/utils" | ||
) | ||
|
||
// Pixivision download function | ||
func Pixivision(url string) downloader.VideoData { | ||
html := request.Get(url) | ||
title, urls := parser.GetImages(url, html, "am__work__illust ", nil) | ||
data := downloader.VideoData{ | ||
Site: "pixivision pixivision.net", | ||
Title: utils.FileName(title), | ||
Type: "image", | ||
URLs: urls, | ||
Size: 0, | ||
} | ||
data.Download(url) | ||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package parser | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/PuerkitoBio/goquery" | ||
|
||
"github.com/iawia002/annie/downloader" | ||
"github.com/iawia002/annie/request" | ||
"github.com/iawia002/annie/utils" | ||
) | ||
|
||
// GetDoc return Document object of the HTML string | ||
func GetDoc(html string) *goquery.Document { | ||
doc, err := goquery.NewDocumentFromReader(strings.NewReader(html)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return doc | ||
} | ||
|
||
// GetImages find the img with a given class name | ||
func GetImages( | ||
url, html, imgClass string, urlHandler func(string) string, | ||
) (string, []downloader.URLData) { | ||
doc := GetDoc(html) | ||
title := strings.TrimSpace(doc.Find("h1").First().Text()) | ||
urls := []downloader.URLData{} | ||
urlData := downloader.URLData{} | ||
doc.Find(fmt.Sprintf("img[class=\"%s\"]", imgClass)).Each( | ||
func(i int, s *goquery.Selection) { | ||
urlData.URL, _ = s.Attr("src") | ||
if urlHandler != nil { | ||
urlData.URL = urlHandler(urlData.URL) | ||
} | ||
urlData.Size = request.Size(urlData.URL, url) | ||
_, urlData.Ext = utils.GetNameAndExt(urlData.URL) | ||
urls = append(urls, urlData) | ||
}, | ||
) | ||
return title, urls | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters