py-youtube-search 0.2.1__tar.gz → 0.2.2__tar.gz
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.
- {py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/PKG-INFO +24 -12
- {py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/README.md +19 -11
- {py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/py_youtube_search/__init__.py +36 -25
- {py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/py_youtube_search.egg-info/PKG-INFO +24 -12
- {py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/py_youtube_search.egg-info/SOURCES.txt +1 -0
- py_youtube_search-0.2.2/py_youtube_search.egg-info/requires.txt +1 -0
- {py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/setup.py +8 -4
- {py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/py_youtube_search.egg-info/dependency_links.txt +0 -0
- {py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/py_youtube_search.egg-info/top_level.txt +0 -0
- {py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/setup.cfg +0 -0
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: py-youtube-search
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A lightweight, regex-based YouTube search library without API keys.
|
|
5
5
|
Home-page: https://github.com/VishvaRam/py-youtube-search
|
|
6
6
|
Author: VishvaRam
|
|
7
7
|
Author-email: murthyvishva@gmail.com
|
|
8
|
+
License: MIT
|
|
8
9
|
Classifier: Programming Language :: Python :: 3
|
|
9
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
11
|
Classifier: Operating System :: OS Independent
|
|
11
12
|
Requires-Python: >=3.6
|
|
12
13
|
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
13
15
|
Dynamic: author
|
|
14
16
|
Dynamic: author-email
|
|
15
17
|
Dynamic: classifier
|
|
16
18
|
Dynamic: description
|
|
17
19
|
Dynamic: description-content-type
|
|
18
20
|
Dynamic: home-page
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: requires-dist
|
|
19
23
|
Dynamic: requires-python
|
|
20
24
|
Dynamic: summary
|
|
21
25
|
|
|
22
|
-
|
|
23
26
|
# py-youtube-search
|
|
24
27
|
|
|
25
28
|
A lightweight, asynchronous Python library to search YouTube videos programmatically without an API key.
|
|
@@ -28,6 +31,7 @@ It scrapes search results using `aiohttp` and `re`, making it fast, robust, and
|
|
|
28
31
|
## Features
|
|
29
32
|
|
|
30
33
|
- **Async Support**: Fully asynchronous using `aiohttp` for non-blocking execution.
|
|
34
|
+
- **Reusable Client**: Create a single instance and run multiple searches with different configurations.
|
|
31
35
|
- **No API Key Required**: Search YouTube directly without setting up Google Cloud projects.
|
|
32
36
|
- **Advanced Filtering**: Built-in support for duration (Medium 3-20m, Long >20m) and upload date filters.
|
|
33
37
|
- **Rich Data Extraction**: Extracts Video ID, Title, Duration, and View Count using optimized regex.
|
|
@@ -41,18 +45,18 @@ pip install py-youtube-search
|
|
|
41
45
|
## Quick Start
|
|
42
46
|
|
|
43
47
|
### 1. Basic Async Search
|
|
44
|
-
|
|
48
|
+
Initialize the client once and run multiple searches.
|
|
45
49
|
|
|
46
50
|
```python
|
|
47
51
|
import asyncio
|
|
48
52
|
from py_youtube_search import YouTubeSearch
|
|
49
53
|
|
|
50
54
|
async def main():
|
|
51
|
-
# 1. Initialize the
|
|
52
|
-
yt = YouTubeSearch(
|
|
55
|
+
# 1. Initialize the client (reusable)
|
|
56
|
+
yt = YouTubeSearch()
|
|
53
57
|
|
|
54
|
-
# 2.
|
|
55
|
-
videos = await yt.search()
|
|
58
|
+
# 2. Run a search
|
|
59
|
+
videos = await yt.search("Python async tutorials", limit=5)
|
|
56
60
|
|
|
57
61
|
for v in videos:
|
|
58
62
|
print(f"Title: {v['title']}")
|
|
@@ -72,21 +76,29 @@ import asyncio
|
|
|
72
76
|
from py_youtube_search import YouTubeSearch, Filters
|
|
73
77
|
|
|
74
78
|
async def main():
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
yt = YouTubeSearch()
|
|
80
|
+
|
|
81
|
+
# Search 1: Long videos about LangGraph
|
|
82
|
+
print("Searching for LangGraph...")
|
|
83
|
+
videos = await yt.search("LangGraph", sp=Filters.long_this_week, limit=3)
|
|
79
84
|
|
|
80
85
|
for v in videos:
|
|
81
86
|
print(f"🎥 {v['title']} | ⏱ {v['duration']} | 👁 {v['views']}")
|
|
82
87
|
|
|
88
|
+
# Search 2: Reusing the same client for a different query
|
|
89
|
+
print("\nSearching for Python...")
|
|
90
|
+
videos_py = await yt.search("Python 3.12", sp=Filters.medium_today, limit=3)
|
|
91
|
+
|
|
92
|
+
for v in videos_py:
|
|
93
|
+
print(f"🐍 {v['title']}")
|
|
94
|
+
|
|
83
95
|
if __name__ == "__main__":
|
|
84
96
|
asyncio.run(main())
|
|
85
97
|
```
|
|
86
98
|
|
|
87
99
|
## Available Filters
|
|
88
100
|
|
|
89
|
-
Pass these constants into the `sp` parameter of `
|
|
101
|
+
Pass these constants into the `sp` parameter of the `search()` method.
|
|
90
102
|
|
|
91
103
|
### Duration: Medium (3 - 20 Minutes)
|
|
92
104
|
| Filter Attribute | Description |
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
# py-youtube-search
|
|
3
2
|
|
|
4
3
|
A lightweight, asynchronous Python library to search YouTube videos programmatically without an API key.
|
|
@@ -7,6 +6,7 @@ It scrapes search results using `aiohttp` and `re`, making it fast, robust, and
|
|
|
7
6
|
## Features
|
|
8
7
|
|
|
9
8
|
- **Async Support**: Fully asynchronous using `aiohttp` for non-blocking execution.
|
|
9
|
+
- **Reusable Client**: Create a single instance and run multiple searches with different configurations.
|
|
10
10
|
- **No API Key Required**: Search YouTube directly without setting up Google Cloud projects.
|
|
11
11
|
- **Advanced Filtering**: Built-in support for duration (Medium 3-20m, Long >20m) and upload date filters.
|
|
12
12
|
- **Rich Data Extraction**: Extracts Video ID, Title, Duration, and View Count using optimized regex.
|
|
@@ -20,18 +20,18 @@ pip install py-youtube-search
|
|
|
20
20
|
## Quick Start
|
|
21
21
|
|
|
22
22
|
### 1. Basic Async Search
|
|
23
|
-
|
|
23
|
+
Initialize the client once and run multiple searches.
|
|
24
24
|
|
|
25
25
|
```python
|
|
26
26
|
import asyncio
|
|
27
27
|
from py_youtube_search import YouTubeSearch
|
|
28
28
|
|
|
29
29
|
async def main():
|
|
30
|
-
# 1. Initialize the
|
|
31
|
-
yt = YouTubeSearch(
|
|
30
|
+
# 1. Initialize the client (reusable)
|
|
31
|
+
yt = YouTubeSearch()
|
|
32
32
|
|
|
33
|
-
# 2.
|
|
34
|
-
videos = await yt.search()
|
|
33
|
+
# 2. Run a search
|
|
34
|
+
videos = await yt.search("Python async tutorials", limit=5)
|
|
35
35
|
|
|
36
36
|
for v in videos:
|
|
37
37
|
print(f"Title: {v['title']}")
|
|
@@ -51,21 +51,29 @@ import asyncio
|
|
|
51
51
|
from py_youtube_search import YouTubeSearch, Filters
|
|
52
52
|
|
|
53
53
|
async def main():
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
yt = YouTubeSearch()
|
|
55
|
+
|
|
56
|
+
# Search 1: Long videos about LangGraph
|
|
57
|
+
print("Searching for LangGraph...")
|
|
58
|
+
videos = await yt.search("LangGraph", sp=Filters.long_this_week, limit=3)
|
|
58
59
|
|
|
59
60
|
for v in videos:
|
|
60
61
|
print(f"🎥 {v['title']} | ⏱ {v['duration']} | 👁 {v['views']}")
|
|
61
62
|
|
|
63
|
+
# Search 2: Reusing the same client for a different query
|
|
64
|
+
print("\nSearching for Python...")
|
|
65
|
+
videos_py = await yt.search("Python 3.12", sp=Filters.medium_today, limit=3)
|
|
66
|
+
|
|
67
|
+
for v in videos_py:
|
|
68
|
+
print(f"🐍 {v['title']}")
|
|
69
|
+
|
|
62
70
|
if __name__ == "__main__":
|
|
63
71
|
asyncio.run(main())
|
|
64
72
|
```
|
|
65
73
|
|
|
66
74
|
## Available Filters
|
|
67
75
|
|
|
68
|
-
Pass these constants into the `sp` parameter of `
|
|
76
|
+
Pass these constants into the `sp` parameter of the `search()` method.
|
|
69
77
|
|
|
70
78
|
### Duration: Medium (3 - 20 Minutes)
|
|
71
79
|
| Filter Attribute | Description |
|
|
@@ -16,38 +16,40 @@ class Filters:
|
|
|
16
16
|
long_this_month = "EgYIBBABGAI="
|
|
17
17
|
long_this_year = "EgYIBRABGAI="
|
|
18
18
|
|
|
19
|
+
|
|
19
20
|
class YouTubeSearch:
|
|
20
|
-
def __init__(self
|
|
21
|
+
def __init__(self):
|
|
21
22
|
"""
|
|
22
|
-
Initialize the
|
|
23
|
-
|
|
23
|
+
Initialize the YouTubeSearch client.
|
|
24
|
+
The client is stateless; parameters are passed to the search method.
|
|
24
25
|
"""
|
|
25
|
-
self.keywords = keywords.replace(" ", "+")
|
|
26
|
-
self.sp = sp
|
|
27
|
-
self.limit = limit
|
|
28
|
-
self.source = None
|
|
29
26
|
self.base_url = "https://www.youtube.com/results"
|
|
30
|
-
|
|
31
|
-
async def _fetch_source(self):
|
|
32
|
-
params = {"search_query": self.keywords}
|
|
33
|
-
if self.sp:
|
|
34
|
-
params["sp"] = self.sp
|
|
35
|
-
|
|
36
|
-
headers = {
|
|
27
|
+
self.headers = {
|
|
37
28
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
38
29
|
}
|
|
39
30
|
|
|
31
|
+
async def _fetch_source(self, keywords: str, sp: str = None):
|
|
32
|
+
params = {"search_query": keywords.replace(" ", "+")}
|
|
33
|
+
if sp:
|
|
34
|
+
params["sp"] = sp
|
|
35
|
+
|
|
40
36
|
async with aiohttp.ClientSession() as session:
|
|
41
|
-
async with session.get(self.base_url, params=params, headers=headers) as response:
|
|
37
|
+
async with session.get(self.base_url, params=params, headers=self.headers) as response:
|
|
42
38
|
return await response.text()
|
|
43
39
|
|
|
44
|
-
async def search(self):
|
|
40
|
+
async def search(self, keywords: str, sp: str = None, limit: int = 15):
|
|
45
41
|
"""
|
|
46
|
-
Asynchronously fetches and parses the
|
|
47
|
-
|
|
42
|
+
Asynchronously fetches and parses search results for the given keywords.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
keywords (str): The search query.
|
|
46
|
+
sp (str, optional): The filter string (use Filters class). Defaults to None.
|
|
47
|
+
limit (int, optional): Max number of results. Defaults to 15.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
list: A list of dictionaries containing video details.
|
|
48
51
|
"""
|
|
49
|
-
|
|
50
|
-
self.source = await self._fetch_source()
|
|
52
|
+
source = await self._fetch_source(keywords, sp)
|
|
51
53
|
|
|
52
54
|
# Regex to capture distinct JSON fields for ID, Title, Duration, and Views.
|
|
53
55
|
pattern = (
|
|
@@ -58,11 +60,11 @@ class YouTubeSearch:
|
|
|
58
60
|
r'.+?\"viewCountText\":\{\"simpleText\":\"(?P<views>.+?)\"\}'
|
|
59
61
|
)
|
|
60
62
|
|
|
61
|
-
matches = re.finditer(pattern,
|
|
63
|
+
matches = re.finditer(pattern, source)
|
|
62
64
|
|
|
63
65
|
results = []
|
|
64
66
|
for match in matches:
|
|
65
|
-
if len(results) >=
|
|
67
|
+
if len(results) >= limit:
|
|
66
68
|
break
|
|
67
69
|
|
|
68
70
|
data = match.groupdict()
|
|
@@ -79,7 +81,16 @@ class YouTubeSearch:
|
|
|
79
81
|
# --- Usage Example (Async) ---
|
|
80
82
|
# import asyncio
|
|
81
83
|
# async def main():
|
|
82
|
-
# yt = YouTubeSearch(
|
|
83
|
-
#
|
|
84
|
-
#
|
|
84
|
+
# yt = YouTubeSearch()
|
|
85
|
+
#
|
|
86
|
+
# # Search 1: Long videos about LangGraph
|
|
87
|
+
# print("Searching LangGraph...")
|
|
88
|
+
# videos1 = await yt.search("LangGraph", sp=Filters.long_this_week, limit=5)
|
|
89
|
+
# print(f"Found {len(videos1)} videos")
|
|
90
|
+
#
|
|
91
|
+
# # Search 2: Short Python tutorials (reusing the same instance)
|
|
92
|
+
# print("Searching Python...")
|
|
93
|
+
# videos2 = await yt.search("Python", sp=Filters.medium_today, limit=3)
|
|
94
|
+
# print(f"Found {len(videos2)} videos")
|
|
95
|
+
#
|
|
85
96
|
# asyncio.run(main())
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: py-youtube-search
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A lightweight, regex-based YouTube search library without API keys.
|
|
5
5
|
Home-page: https://github.com/VishvaRam/py-youtube-search
|
|
6
6
|
Author: VishvaRam
|
|
7
7
|
Author-email: murthyvishva@gmail.com
|
|
8
|
+
License: MIT
|
|
8
9
|
Classifier: Programming Language :: Python :: 3
|
|
9
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
11
|
Classifier: Operating System :: OS Independent
|
|
11
12
|
Requires-Python: >=3.6
|
|
12
13
|
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
13
15
|
Dynamic: author
|
|
14
16
|
Dynamic: author-email
|
|
15
17
|
Dynamic: classifier
|
|
16
18
|
Dynamic: description
|
|
17
19
|
Dynamic: description-content-type
|
|
18
20
|
Dynamic: home-page
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: requires-dist
|
|
19
23
|
Dynamic: requires-python
|
|
20
24
|
Dynamic: summary
|
|
21
25
|
|
|
22
|
-
|
|
23
26
|
# py-youtube-search
|
|
24
27
|
|
|
25
28
|
A lightweight, asynchronous Python library to search YouTube videos programmatically without an API key.
|
|
@@ -28,6 +31,7 @@ It scrapes search results using `aiohttp` and `re`, making it fast, robust, and
|
|
|
28
31
|
## Features
|
|
29
32
|
|
|
30
33
|
- **Async Support**: Fully asynchronous using `aiohttp` for non-blocking execution.
|
|
34
|
+
- **Reusable Client**: Create a single instance and run multiple searches with different configurations.
|
|
31
35
|
- **No API Key Required**: Search YouTube directly without setting up Google Cloud projects.
|
|
32
36
|
- **Advanced Filtering**: Built-in support for duration (Medium 3-20m, Long >20m) and upload date filters.
|
|
33
37
|
- **Rich Data Extraction**: Extracts Video ID, Title, Duration, and View Count using optimized regex.
|
|
@@ -41,18 +45,18 @@ pip install py-youtube-search
|
|
|
41
45
|
## Quick Start
|
|
42
46
|
|
|
43
47
|
### 1. Basic Async Search
|
|
44
|
-
|
|
48
|
+
Initialize the client once and run multiple searches.
|
|
45
49
|
|
|
46
50
|
```python
|
|
47
51
|
import asyncio
|
|
48
52
|
from py_youtube_search import YouTubeSearch
|
|
49
53
|
|
|
50
54
|
async def main():
|
|
51
|
-
# 1. Initialize the
|
|
52
|
-
yt = YouTubeSearch(
|
|
55
|
+
# 1. Initialize the client (reusable)
|
|
56
|
+
yt = YouTubeSearch()
|
|
53
57
|
|
|
54
|
-
# 2.
|
|
55
|
-
videos = await yt.search()
|
|
58
|
+
# 2. Run a search
|
|
59
|
+
videos = await yt.search("Python async tutorials", limit=5)
|
|
56
60
|
|
|
57
61
|
for v in videos:
|
|
58
62
|
print(f"Title: {v['title']}")
|
|
@@ -72,21 +76,29 @@ import asyncio
|
|
|
72
76
|
from py_youtube_search import YouTubeSearch, Filters
|
|
73
77
|
|
|
74
78
|
async def main():
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
yt = YouTubeSearch()
|
|
80
|
+
|
|
81
|
+
# Search 1: Long videos about LangGraph
|
|
82
|
+
print("Searching for LangGraph...")
|
|
83
|
+
videos = await yt.search("LangGraph", sp=Filters.long_this_week, limit=3)
|
|
79
84
|
|
|
80
85
|
for v in videos:
|
|
81
86
|
print(f"🎥 {v['title']} | ⏱ {v['duration']} | 👁 {v['views']}")
|
|
82
87
|
|
|
88
|
+
# Search 2: Reusing the same client for a different query
|
|
89
|
+
print("\nSearching for Python...")
|
|
90
|
+
videos_py = await yt.search("Python 3.12", sp=Filters.medium_today, limit=3)
|
|
91
|
+
|
|
92
|
+
for v in videos_py:
|
|
93
|
+
print(f"🐍 {v['title']}")
|
|
94
|
+
|
|
83
95
|
if __name__ == "__main__":
|
|
84
96
|
asyncio.run(main())
|
|
85
97
|
```
|
|
86
98
|
|
|
87
99
|
## Available Filters
|
|
88
100
|
|
|
89
|
-
Pass these constants into the `sp` parameter of `
|
|
101
|
+
Pass these constants into the `sp` parameter of the `search()` method.
|
|
90
102
|
|
|
91
103
|
### Duration: Medium (3 - 20 Minutes)
|
|
92
104
|
| Filter Attribute | Description |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aiohttp>=3.8.0
|
|
@@ -5,13 +5,16 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name="py-youtube-search",
|
|
8
|
-
version="0.2.
|
|
9
|
-
author="VishvaRam",
|
|
10
|
-
|
|
8
|
+
version="0.2.2",
|
|
9
|
+
author="VishvaRam",
|
|
10
|
+
install_requires=[
|
|
11
|
+
"aiohttp>=3.8.0",
|
|
12
|
+
],
|
|
13
|
+
author_email="murthyvishva@gmail.com",
|
|
11
14
|
description="A lightweight, regex-based YouTube search library without API keys.",
|
|
12
15
|
long_description=long_description,
|
|
13
16
|
long_description_content_type="text/markdown",
|
|
14
|
-
url="https://github.com/VishvaRam/py-youtube-search",
|
|
17
|
+
url="https://github.com/VishvaRam/py-youtube-search",
|
|
15
18
|
packages=find_packages(),
|
|
16
19
|
classifiers=[
|
|
17
20
|
"Programming Language :: Python :: 3",
|
|
@@ -19,4 +22,5 @@ setup(
|
|
|
19
22
|
"Operating System :: OS Independent",
|
|
20
23
|
],
|
|
21
24
|
python_requires='>=3.6',
|
|
25
|
+
license="MIT",
|
|
22
26
|
)
|
{py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/py_youtube_search.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{py_youtube_search-0.2.1 → py_youtube_search-0.2.2}/py_youtube_search.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|