ph-scraper-api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +120 -0
- package/index.js +1 -0
- package/package.json +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 suneththarind
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# 🚀 PornHub Scraper API
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A high-performance, lightweight **Node.js** library to search videos and extract direct **HLS (m3u8)** streaming links and metadata from PornHub.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## ✨ Features
|
|
12
|
+
|
|
13
|
+
* 🔍 **Smart Search**: Search videos with customizable result limits.
|
|
14
|
+
* 📊 **Deep Metadata**: Extract titles, views, duration, and high-quality thumbnails.
|
|
15
|
+
* ⚡ **Stream Extractor**: Get direct HLS links for all available qualities (1080p, 720p, 480p, etc.).
|
|
16
|
+
* 📥 **Buffer Downloader**: Built-in support to process HLS streams into Buffers using FFmpeg.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## ⚙️ Prerequisites
|
|
21
|
+
|
|
22
|
+
To use the **`downloadBuffer()`** feature, you must have **FFmpeg** installed on your system.
|
|
23
|
+
|
|
24
|
+
* **Termux:** `pkg install ffmpeg`
|
|
25
|
+
* **Linux:** `sudo apt install ffmpeg`
|
|
26
|
+
* **Windows:** Install via [ffmpeg.org](https://ffmpeg.org/download.html)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 🛠️ Installation
|
|
31
|
+
|
|
32
|
+
Install the package via npm:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install ph-scraper-api
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
🚀 Usage Guide
|
|
39
|
+
After installing, you can import and use the scraper in your project:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
const ph = require('ph-scraper-api');
|
|
43
|
+
|
|
44
|
+
(async () => {
|
|
45
|
+
try {
|
|
46
|
+
// 1. Search for videos
|
|
47
|
+
const results = await ph.search('funny', 2);
|
|
48
|
+
console.log(results);
|
|
49
|
+
|
|
50
|
+
// 2. Extract Metadata & HLS Links
|
|
51
|
+
if (results.length > 0) {
|
|
52
|
+
const videoData = await ph.download(results[0].vkey);
|
|
53
|
+
console.log(videoData);
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.error("Scraper Error:", err.message);
|
|
57
|
+
}
|
|
58
|
+
})();
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
📊 Example Outputs
|
|
63
|
+
🔍 Search Result Example (.search())
|
|
64
|
+
The search function returns an Array of Objects:
|
|
65
|
+
```bash
|
|
66
|
+
[
|
|
67
|
+
{
|
|
68
|
+
"title": "Funny Prank Video",
|
|
69
|
+
"vkey": "ph64xxxxxxxx",
|
|
70
|
+
"duration": "10:05",
|
|
71
|
+
"views": "1.2M",
|
|
72
|
+
"url": "[https://www.pornhub.com/view_video.php?viewkey=ph64xxxxxxxx](https://www.pornhub.com/view_video.php?viewkey=ph64xxxxxxxx)",
|
|
73
|
+
"thumb": "[https://ei.phncdn.com/videos/.../original/1.jpg](https://ei.phncdn.com/videos/.../original/1.jpg)"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"title": "Another Funny Clip",
|
|
77
|
+
"vkey": "ph65yyyyyyyy",
|
|
78
|
+
"duration": "05:20",
|
|
79
|
+
"views": "500K",
|
|
80
|
+
"url": "[https://www.pornhub.com/view_video.php?viewkey=ph65yyyyyyyy](https://www.pornhub.com/view_video.php?viewkey=ph65yyyyyyyy)",
|
|
81
|
+
"thumb": "[https://ei.phncdn.com/videos/.../original/2.jpg](https://ei.phncdn.com/videos/.../original/2.jpg)"
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
```
|
|
85
|
+
⚡ Download Info Example
|
|
86
|
+
The download function returns a Single Object with all available stream qualities:
|
|
87
|
+
```bash
|
|
88
|
+
{
|
|
89
|
+
"title": "Funny Prank Video",
|
|
90
|
+
"thumb": "[https://ei.phncdn.com/videos/.../original/1.jpg](https://ei.phncdn.com/videos/.../original/1.jpg)",
|
|
91
|
+
"duration": "10:05",
|
|
92
|
+
"hls": {
|
|
93
|
+
"1080p": "[https://km-h.phncdn.com/hls/.../1080P_4000K.m3u8?token=](https://km-h.phncdn.com/hls/.../1080P_4000K.m3u8?token=)...",
|
|
94
|
+
"720p": "[https://km-h.phncdn.com/hls/.../720P_2000K.m3u8?token=](https://km-h.phncdn.com/hls/.../720P_2000K.m3u8?token=)...",
|
|
95
|
+
"480p": "[https://km-h.phncdn.com/hls/.../480P_1000K.m3u8?token=](https://km-h.phncdn.com/hls/.../480P_1000K.m3u8?token=)...",
|
|
96
|
+
"240p": "[https://km-h.phncdn.com/hls/.../240P_400K.m3u8?token=](https://km-h.phncdn.com/hls/.../240P_400K.m3u8?token=)..."
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
📊 API Reference
|
|
103
|
+
|
|
104
|
+
.search(query, limit)
|
|
105
|
+
query (String): Search keyword.
|
|
106
|
+
limit (Number): Max results (default is 10).
|
|
107
|
+
|
|
108
|
+
.download(vkey_or_url)
|
|
109
|
+
vkey_or_url (String): The video vkey or the full PornHub URL.
|
|
110
|
+
Returns: Metadata object with HLS links.
|
|
111
|
+
|
|
112
|
+
.downloadBuffer(vkey, quality)
|
|
113
|
+
vkey (String): The video identifier.
|
|
114
|
+
quality (String): Video quality (e.g., '1080', '720', '480').
|
|
115
|
+
|
|
116
|
+
👨💻 Author
|
|
117
|
+
Keshara Liyanaarachchi
|
|
118
|
+
|
|
119
|
+
📜 License
|
|
120
|
+
MIT License. For educational purposes only.
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function a0_0x1a2d(){const _0x4a234d=['find','sort','each','_extractMediaDefinitions','script[type=\x22application/ld+json\x22]','match','html','thumbnailUrl','child_process','phdl-','hls','11160lnbbqX','message','replace','1084076OqrSsa','text','filter','attr','6670899UTUTFk','first','li[data-video-vkey]','videoUrl','data-video-vkey','ffmpeg\x20-v\x20quiet\x20-y\x20-user_agent\x20\x22','mediaDefinitions','/video/search?search=','444pumfXS','img','quality','baseUrl','No\x20video\x20qualities\x20found.','316Xzebjx','2607336xgnQDX','duration','_parseDuration','indexOf','format','title','get','trim','720','h1.title\x20span','parse','thumb','/view_video.php?viewkey=','forEach','.duration','.views\x20var','values','Search\x20failed:\x20','79568wzlqSn','downloadBuffer','download','padStart','Mozilla/5.0\x20(Linux;\x20Android\x2011;\x20Redmi\x20Note\x208)\x20AppleWebKit/537.36\x20(KHTML,\x20like\x20Gecko)\x20Chrome/120.0.0.0\x20Mobile\x20Safari/537.36','promises','\x22\x20-t\x20300\x20-c\x20copy\x20-bsf:a\x20aac_adtstoasc\x20\x22','exports','https://www.pornhub.com','.title\x20a','length','includes','553TwyfGZ','No\x20Title','push','search','5333120SkgReY','15605PuUQrv','map'];a0_0x1a2d=function(){return _0x4a234d;};return a0_0x1a2d();}const a0_0x31751d=a0_0x1cbe;(function(_0x3a0010,_0x24bfa){const _0x9f2360=a0_0x1cbe,_0x1d66ae=_0x3a0010();while(!![]){try{const _0x5527de=-parseInt(_0x9f2360(0x1f0))/0x1+-parseInt(_0x9f2360(0x1ed))/0x2*(-parseInt(_0x9f2360(0x1fc))/0x3)+-parseInt(_0x9f2360(0x201))/0x4*(-parseInt(_0x9f2360(0x225))/0x5)+-parseInt(_0x9f2360(0x202))/0x6+-parseInt(_0x9f2360(0x220))/0x7*(-parseInt(_0x9f2360(0x214))/0x8)+parseInt(_0x9f2360(0x1f4))/0x9+-parseInt(_0x9f2360(0x224))/0xa;if(_0x5527de===_0x24bfa)break;else _0x1d66ae['push'](_0x1d66ae['shift']());}catch(_0x33d86b){_0x1d66ae['push'](_0x1d66ae['shift']());}}}(a0_0x1a2d,0x85a48));function a0_0x1cbe(_0x57809d,_0x17e54e){_0x57809d=_0x57809d-0x1e6;const _0x1a2dfa=a0_0x1a2d();let _0x1cbef0=_0x1a2dfa[_0x57809d];return _0x1cbef0;}const axios=require('axios'),cheerio=require('cheerio'),{exec}=require(a0_0x31751d(0x1ea)),{promisify}=require('util'),{mkdtemp,rm,readFile}=require('fs')[a0_0x31751d(0x219)],{join}=require('path'),{tmpdir}=require('os'),execAsync=promisify(exec),UA=a0_0x31751d(0x218);class PornHub{constructor(){const _0x2e50c4=a0_0x31751d;this[_0x2e50c4(0x1ff)]=_0x2e50c4(0x21c);}['_parseDuration'](_0x41cce3){const _0x4f7509=a0_0x31751d;if(!_0x41cce3)return null;const _0x4c2d92=_0x41cce3[_0x4f7509(0x1e7)](/PT(\d+)H(\d+)M(\d+)S/);if(!_0x4c2d92)return _0x41cce3;const _0x430c9d=parseInt(_0x4c2d92[0x1]),_0x3fba77=parseInt(_0x4c2d92[0x2]),_0x29097a=parseInt(_0x4c2d92[0x3]);if(_0x430c9d>0x0)return _0x430c9d+':'+String(_0x3fba77)[_0x4f7509(0x217)](0x2,'0')+':'+String(_0x29097a)['padStart'](0x2,'0');return _0x3fba77+':'+String(_0x29097a)[_0x4f7509(0x217)](0x2,'0');}[a0_0x31751d(0x22a)](_0x2a3786){const _0x44ec06=a0_0x31751d,_0x22a544=_0x2a3786[_0x44ec06(0x205)](_0x44ec06(0x1fa));if(_0x22a544===-0x1)return null;const _0x14c786=_0x2a3786[_0x44ec06(0x205)]('[',_0x22a544);if(_0x14c786===-0x1)return null;let _0x115e1e=0x0,_0x48012f=-0x1;for(let _0xc70f2c=_0x14c786;_0xc70f2c<_0x2a3786[_0x44ec06(0x21e)];_0xc70f2c++){if(_0x2a3786[_0xc70f2c]==='[')_0x115e1e++;else{if(_0x2a3786[_0xc70f2c]===']'){_0x115e1e--;if(_0x115e1e===0x0){_0x48012f=_0xc70f2c;break;}}}}try{return JSON[_0x44ec06(0x20c)](_0x2a3786['slice'](_0x14c786,_0x48012f+0x1)[_0x44ec06(0x1ef)](/\\\//g,'/'));}catch{return null;}}async[a0_0x31751d(0x223)](_0x5c8ab5,_0x3c6f26=0xa){const _0x374cdf=a0_0x31751d;try{const {data:_0x4ebb65}=await axios[_0x374cdf(0x208)](this['baseUrl']+_0x374cdf(0x1fb)+encodeURIComponent(_0x5c8ab5),{'headers':{'User-Agent':UA},'timeout':0x2ee0}),_0x46070d=cheerio['load'](_0x4ebb65),_0x3d1b05=[];return _0x46070d(_0x374cdf(0x1f6))[_0x374cdf(0x229)]((_0x49c19c,_0x5f262b)=>{const _0x5dcfea=_0x374cdf;if(_0x3d1b05[_0x5dcfea(0x21e)]>=_0x3c6f26)return![];const _0x51aa46=_0x46070d(_0x5f262b)[_0x5dcfea(0x1f3)](_0x5dcfea(0x1f8)),_0xce57e7=_0x46070d(_0x5f262b)[_0x5dcfea(0x227)](_0x5dcfea(0x21d))[_0x5dcfea(0x1f5)]()['text']()['trim']();_0x51aa46&&_0xce57e7&&_0x3d1b05[_0x5dcfea(0x222)]({'title':_0xce57e7,'vkey':_0x51aa46,'duration':_0x46070d(_0x5f262b)[_0x5dcfea(0x227)](_0x5dcfea(0x210))[_0x5dcfea(0x1f1)]()[_0x5dcfea(0x209)](),'views':_0x46070d(_0x5f262b)['find'](_0x5dcfea(0x211))[_0x5dcfea(0x1f1)]()[_0x5dcfea(0x209)](),'url':this[_0x5dcfea(0x1ff)]+_0x5dcfea(0x20e)+_0x51aa46,'thumb':_0x46070d(_0x5f262b)[_0x5dcfea(0x227)](_0x5dcfea(0x1fd))[_0x5dcfea(0x1f3)]('src')});}),_0x3d1b05;}catch(_0x3d7d2d){throw new Error(_0x374cdf(0x213)+_0x3d7d2d[_0x374cdf(0x1ee)]);}}async[a0_0x31751d(0x216)](_0x5041ae){const _0xbb11de=a0_0x31751d,_0x4abefc=_0x5041ae[_0xbb11de(0x21f)]('viewkey=')?_0x5041ae:this[_0xbb11de(0x1ff)]+_0xbb11de(0x20e)+_0x5041ae,{data:_0x4d58e4}=await axios['get'](_0x4abefc,{'headers':{'User-Agent':UA},'timeout':0x2ee0}),_0x2ae564=cheerio['load'](_0x4d58e4),_0x5c69d9=_0x2ae564('script')[_0xbb11de(0x226)]((_0x3812ee,_0x1835d1)=>_0x2ae564(_0x1835d1)[_0xbb11de(0x1e8)]())['get']();let _0x181db7=null;for(const _0x4b463d of _0x5c69d9){if(!_0x4b463d||!_0x4b463d[_0xbb11de(0x21f)](_0xbb11de(0x1fa)))continue;_0x181db7=this['_extractMediaDefinitions'](_0x4b463d);if(_0x181db7)break;}if(!_0x181db7)throw new Error(_0xbb11de(0x200));const _0x7e383c=_0x181db7[_0xbb11de(0x1f2)](_0x1d251a=>_0x1d251a[_0xbb11de(0x206)]===_0xbb11de(0x1ec)&&_0x1d251a[_0xbb11de(0x1f7)]&&_0x1d251a[_0xbb11de(0x1fe)])[_0xbb11de(0x228)]((_0x5de5b4,_0x119696)=>parseInt(_0x119696['quality'])-parseInt(_0x5de5b4[_0xbb11de(0x1fe)])),_0x42222c=_0x2ae564(_0xbb11de(0x1e6))[_0xbb11de(0x1f5)]()['html']();let _0x596eb8={'title':null,'thumb':null,'duration':null,'hls':{}};if(_0x42222c)try{const _0x17c4c4=JSON[_0xbb11de(0x20c)](_0x42222c);_0x596eb8[_0xbb11de(0x207)]=_0x17c4c4['name']||null,_0x596eb8[_0xbb11de(0x20d)]=_0x17c4c4[_0xbb11de(0x1e9)]||null,_0x596eb8['duration']=this[_0xbb11de(0x204)](_0x17c4c4[_0xbb11de(0x203)]);}catch{}if(!_0x596eb8[_0xbb11de(0x207)])_0x596eb8['title']=_0x2ae564(_0xbb11de(0x20b))[_0xbb11de(0x1f1)]()['trim']()||_0xbb11de(0x221);return _0x7e383c[_0xbb11de(0x20f)](_0xa9fb45=>{const _0x2007ab=_0xbb11de;_0x596eb8[_0x2007ab(0x1ec)][_0xa9fb45['quality']+'p']=_0xa9fb45[_0x2007ab(0x1f7)];}),_0x596eb8;}async[a0_0x31751d(0x215)](_0x1b9ae6,_0x16371d=a0_0x31751d(0x20a)){const _0x4b7406=a0_0x31751d,_0x29fddb=await this[_0x4b7406(0x216)](_0x1b9ae6),_0x308fcf=_0x29fddb[_0x4b7406(0x1ec)][_0x16371d+'p']||Object[_0x4b7406(0x212)](_0x29fddb[_0x4b7406(0x1ec)])[0x0],_0x230871=await mkdtemp(join(tmpdir(),_0x4b7406(0x1eb))),_0x22ab13=join(_0x230871,'video.mp4');try{await execAsync(_0x4b7406(0x1f9)+UA+'\x22\x20-headers\x20\x22Referer:\x20https://www.pornhub.com/\x0d\x0a\x22\x20-i\x20\x22'+_0x308fcf+_0x4b7406(0x21a)+_0x22ab13+'\x22',{'timeout':0x1d4c0});const _0x3b797f=await readFile(_0x22ab13);return{'title':_0x29fddb[_0x4b7406(0x207)],'buffer':_0x3b797f};}finally{await rm(_0x230871,{'recursive':!![],'force':!![]});}}}module[a0_0x31751d(0x21b)]=new PornHub();
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ph-scraper-api",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A lightweight Node.js scraper for searching and extracting HLS download links from PornHub.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node index.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"ph-scraper",
|
|
11
|
+
"downloader",
|
|
12
|
+
"video-search",
|
|
13
|
+
"hls-extractor"
|
|
14
|
+
],
|
|
15
|
+
"author": "Keshara Liyanaarachchi",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"axios": "^1.6.0",
|
|
19
|
+
"cheerio": "^1.0.0-rc.12"
|
|
20
|
+
}
|
|
21
|
+
}
|