-
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.
Merge pull request #450 from guanw/judew-support-porn
Pornhub Support
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package pornhub | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/iawia002/annie/downloader" | ||
"github.com/iawia002/annie/request" | ||
"github.com/iawia002/annie/utils" | ||
) | ||
|
||
type pornhubData struct { | ||
DefaultQuality bool `json:"defaultQuality"` | ||
Format string `json:"format"` | ||
Quality string `json:"quality"` | ||
VideoURL string `json:"videoUrl"` | ||
} | ||
|
||
// Extract is the main function for extracting data | ||
func Extract(url string) ([]downloader.Data, error) { | ||
var err error | ||
html, err := request.Get(url, url, nil) | ||
if err != nil { | ||
return downloader.EmptyList, err | ||
} | ||
var title string | ||
desc := utils.MatchOneOf(html, `<span class="inlineFree">(.+?)</span>`) | ||
if desc != nil { | ||
title = desc[1] | ||
} else { | ||
title = "pornhub video" | ||
} | ||
|
||
realURLs := utils.MatchOneOf(html, `"mediaDefinitions":(.+?),"isVertical"`) | ||
|
||
var pornhubs []pornhubData | ||
err = json.Unmarshal([]byte(realURLs[1]), &pornhubs) | ||
if err != nil { | ||
return downloader.EmptyList, err | ||
} | ||
|
||
//TODO add support for different quality | ||
var realURL string | ||
for _, downloadlink := range(pornhubs) { | ||
if downloadlink.VideoURL != "" { | ||
realURL = downloadlink.VideoURL | ||
break | ||
} | ||
} | ||
|
||
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: size, | ||
}, | ||
} | ||
return []downloader.Data{ | ||
{ | ||
Site: "Pornhub", | ||
Title: title, | ||
Type: "video", | ||
Streams: streams, | ||
URL: url, | ||
}, | ||
}, nil | ||
} |
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,34 @@ | ||
package pornhub | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/iawia002/annie/config" | ||
"github.com/iawia002/annie/test" | ||
) | ||
|
||
|
||
func TestYoutube(t *testing.T) { | ||
config.InfoOnly = true | ||
config.RetryTimes = 10 | ||
tests := []struct { | ||
name string | ||
args test.Args | ||
}{ | ||
{ | ||
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, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
data, err := Extract(tt.args.URL) | ||
test.CheckError(t, err) | ||
test.Check(t, tt.args, data[0]) | ||
}) | ||
} | ||
} |
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