diff --git a/README.md b/README.md index 506c94484..d48963518 100644 --- a/README.md +++ b/README.md @@ -600,6 +600,7 @@ Twitter | | ✓ | | | | 网易云音乐 | | ✓ | | | | 音悦台 | | ✓ | | | | 极客时间 | | ✓ | | | | +Pornhub | | ✓ | | | | ## Known issues diff --git a/extractors/pornhub/pornhub.go b/extractors/pornhub/pornhub.go index e7a9eb3a6..9a55f4b30 100644 --- a/extractors/pornhub/pornhub.go +++ b/extractors/pornhub/pornhub.go @@ -2,6 +2,7 @@ package pornhub import ( "encoding/json" + "fmt" "github.com/iawia002/annie/downloader" "github.com/iawia002/annie/request" @@ -9,10 +10,9 @@ import ( ) type pornhubData struct { - DefaultQuality bool `json:"defaultQuality"` - Format string `json:"format"` - Quality string `json:"quality"` - VideoURL string `json:"videoUrl"` + Format string `json:"format"` + Quality string `json:"quality"` + VideoURL string `json:"videoUrl"` } // Extract is the main function for extracting data @@ -38,37 +38,35 @@ func Extract(url string) ([]downloader.Data, error) { return downloader.EmptyList, err } - //TODO add support for different quality - var realURL string - for _, downloadlink := range(pornhubs) { - if downloadlink.VideoURL != "" { - realURL = downloadlink.VideoURL - break + streams := make(map[string]downloader.Stream, len(pornhubs)) + for _, data := range pornhubs { + realURL := data.VideoURL + if realURL == "" { + continue } - } - - size, err := request.Size(realURL, url) - if err != nil { - return downloader.EmptyList, err - } - urlData := downloader.URL{ - URL: realURL, - Size: size, - Ext: "mp4", - } - streams := map[string]downloader.Stream{ - "default": { - URLs: []downloader.URL{urlData}, + size, err := request.Size(realURL, url) + if err != nil { + return downloader.EmptyList, err + } + urlData := downloader.URL{ + URL: realURL, Size: size, - }, + Ext: "mp4", + } + streams[data.Quality] = downloader.Stream{ + URLs: []downloader.URL{urlData}, + Size: size, + Quality: fmt.Sprintf("%sP", data.Quality), + } } + return []downloader.Data{ { - Site: "Pornhub", + Site: "Pornhub pornhub.com", Title: title, Type: "video", Streams: streams, URL: url, }, }, nil -} \ No newline at end of file +} diff --git a/extractors/pornhub/pornhub_test.go b/extractors/pornhub/pornhub_test.go index 5b877cf3d..09d940b92 100644 --- a/extractors/pornhub/pornhub_test.go +++ b/extractors/pornhub/pornhub_test.go @@ -7,8 +7,7 @@ import ( "github.com/iawia002/annie/test" ) - -func TestYoutube(t *testing.T) { +func TestPornhub(t *testing.T) { config.InfoOnly = true config.RetryTimes = 10 tests := []struct { @@ -18,9 +17,10 @@ func TestYoutube(t *testing.T) { { name: "normal test", args: test.Args{ - URL: "https://www.pornhub.com/view_video.php?viewkey=ph5cb5fc41c6ebd", - Title: "Must Watch MILF Drilled by the Fireplace", - Size: 158868371, + URL: "https://www.pornhub.com/view_video.php?viewkey=ph5cb5fc41c6ebd", + Title: "Must watch Milf drilled by the fireplace", + Quality: "720P", + Size: 158868371, }, }, } @@ -31,4 +31,4 @@ func TestYoutube(t *testing.T) { test.Check(t, tt.args, data[0]) }) } -} \ No newline at end of file +}