py-youtube-search 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
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/__init__.py +32 -13
- {py_youtube_search-0.1.0.dist-info → py_youtube_search-0.2.0.dist-info}/METADATA +4 -4
- py_youtube_search-0.2.0.dist-info/RECORD +5 -0
- py_youtube_search-0.1.0.dist-info/RECORD +0 -5
- {py_youtube_search-0.1.0.dist-info → py_youtube_search-0.2.0.dist-info}/WHEEL +0 -0
- {py_youtube_search-0.1.0.dist-info → py_youtube_search-0.2.0.dist-info}/top_level.txt +0 -0
py_youtube_search/__init__.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import re
|
|
2
|
-
import
|
|
2
|
+
import aiohttp
|
|
3
|
+
import asyncio
|
|
3
4
|
|
|
4
5
|
# Filter constants accessible to the user
|
|
5
6
|
class Filters:
|
|
@@ -17,27 +18,37 @@ class Filters:
|
|
|
17
18
|
|
|
18
19
|
class YouTubeSearch:
|
|
19
20
|
def __init__(self, keywords: str, sp: str = None, limit: int = 15):
|
|
21
|
+
"""
|
|
22
|
+
Initialize the search parameters.
|
|
23
|
+
Note: No network request happens here. Call .search() to fetch data.
|
|
24
|
+
"""
|
|
20
25
|
self.keywords = keywords.replace(" ", "+")
|
|
21
26
|
self.sp = sp
|
|
22
27
|
self.limit = limit
|
|
23
|
-
self.source =
|
|
28
|
+
self.source = None
|
|
29
|
+
self.base_url = "https://www.youtube.com/results"
|
|
24
30
|
|
|
25
|
-
def _fetch_source(self):
|
|
26
|
-
|
|
31
|
+
async def _fetch_source(self):
|
|
32
|
+
params = {"search_query": self.keywords}
|
|
27
33
|
if self.sp:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
url = base_url
|
|
31
|
-
|
|
34
|
+
params["sp"] = self.sp
|
|
35
|
+
|
|
32
36
|
headers = {
|
|
33
37
|
"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"
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
req = urllib.request.Request(url, headers=headers)
|
|
37
|
-
with urllib.request.urlopen(req) as response:
|
|
38
|
-
return response.read().decode("utf-8")
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
async with aiohttp.ClientSession() as session:
|
|
41
|
+
async with session.get(self.base_url, params=params, headers=headers) as response:
|
|
42
|
+
return await response.text()
|
|
43
|
+
|
|
44
|
+
async def search(self):
|
|
45
|
+
"""
|
|
46
|
+
Asynchronously fetches and parses the search results.
|
|
47
|
+
Returns a list of videos.
|
|
48
|
+
"""
|
|
49
|
+
if not self.source:
|
|
50
|
+
self.source = await self._fetch_source()
|
|
51
|
+
|
|
41
52
|
# Regex to capture distinct JSON fields for ID, Title, Duration, and Views.
|
|
42
53
|
pattern = (
|
|
43
54
|
r'\"videoRenderer\":\{'
|
|
@@ -64,3 +75,11 @@ class YouTubeSearch:
|
|
|
64
75
|
})
|
|
65
76
|
|
|
66
77
|
return results
|
|
78
|
+
|
|
79
|
+
# --- Usage Example (Async) ---
|
|
80
|
+
# import asyncio
|
|
81
|
+
# async def main():
|
|
82
|
+
# yt = YouTubeSearch("LangGraph", sp=Filters.long_this_week)
|
|
83
|
+
# videos = await yt.search()
|
|
84
|
+
# print(videos)
|
|
85
|
+
# asyncio.run(main())
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: py-youtube-search
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: A lightweight, regex-based YouTube search library without API keys.
|
|
5
|
-
Home-page: https://github.com/
|
|
6
|
-
Author:
|
|
7
|
-
Author-email:
|
|
5
|
+
Home-page: https://github.com/VishvaRam/py-youtube-search
|
|
6
|
+
Author: VishvaRam
|
|
7
|
+
Author-email: murthyvishva@gmail.com
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
py_youtube_search/__init__.py,sha256=hWJcqytPfRODGIFynNmDrCQm_9P5zWwg4DOcWIyrVog,2769
|
|
2
|
+
py_youtube_search-0.2.0.dist-info/METADATA,sha256=-Z0VAXP6C5HNG4TriRWmPy9ZSrUPKqu9_1SX1dpPOkM,4833
|
|
3
|
+
py_youtube_search-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
4
|
+
py_youtube_search-0.2.0.dist-info/top_level.txt,sha256=4EMqIznKjzwgAcB_78SKaMIzZXpIxWQ4SRLeakY3fzQ,18
|
|
5
|
+
py_youtube_search-0.2.0.dist-info/RECORD,,
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
py_youtube_search/__init__.py,sha256=9y3zJefUcvRnKxuyo6441PvliVQ75HygT5bsyzICpfA,2226
|
|
2
|
-
py_youtube_search-0.1.0.dist-info/METADATA,sha256=4tIXGEZyr5oPm7AyC8k2jA6SLRaojoBd__AIL6nAyis,4836
|
|
3
|
-
py_youtube_search-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
4
|
-
py_youtube_search-0.1.0.dist-info/top_level.txt,sha256=4EMqIznKjzwgAcB_78SKaMIzZXpIxWQ4SRLeakY3fzQ,18
|
|
5
|
-
py_youtube_search-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|