googlenewsdecoder 0.1.0__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.
- googlenewsdecoder-0.1.0/LICENSE +21 -0
- googlenewsdecoder-0.1.0/PKG-INFO +53 -0
- googlenewsdecoder-0.1.0/README.md +37 -0
- googlenewsdecoder-0.1.0/googlenewsdecoder/__init__.py +2 -0
- googlenewsdecoder-0.1.0/googlenewsdecoder/decoderv1.py +40 -0
- googlenewsdecoder-0.1.0/googlenewsdecoder/decoderv2.py +77 -0
- googlenewsdecoder-0.1.0/googlenewsdecoder.egg-info/PKG-INFO +53 -0
- googlenewsdecoder-0.1.0/googlenewsdecoder.egg-info/SOURCES.txt +11 -0
- googlenewsdecoder-0.1.0/googlenewsdecoder.egg-info/dependency_links.txt +1 -0
- googlenewsdecoder-0.1.0/googlenewsdecoder.egg-info/requires.txt +1 -0
- googlenewsdecoder-0.1.0/googlenewsdecoder.egg-info/top_level.txt +1 -0
- googlenewsdecoder-0.1.0/setup.cfg +4 -0
- googlenewsdecoder-0.1.0/setup.py +23 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Sujit Biswas
|
|
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.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: googlenewsdecoder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A package to decode Google News URLs.
|
|
5
|
+
Home-page: https://github.com/SSujitX/google-news-url-decoder
|
|
6
|
+
Author: Sujit Biswas
|
|
7
|
+
Author-email: ssujitxx@example.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
|
|
17
|
+
# Google News Decoder
|
|
18
|
+
|
|
19
|
+
A Python package to decode Google News URLs.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
You can install this package using pip:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
pip install googlenewsdecoder
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Credits
|
|
30
|
+
|
|
31
|
+
Original script by [huksley](https://gist.github.com/huksley/bc3cb046157a99cd9d1)
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Here is an example of how to use this package:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
|
|
39
|
+
from googlenewsdecoder import decoderv1, decoderv2
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
# source_url = "https://news.google.com/rss/articles/CBMiLmh0dHBzOi8vd3d3LmJiYy5jb20vbmV3cy9hcnRpY2xlcy9jampqbnhkdjE4OG_SATJodHRwczovL3d3dy5iYmMuY29tL25ld3MvYXJ0aWNsZXMvY2pqam54ZHYxODhvLmFtcA?oc=5"
|
|
43
|
+
# source_url = "https://news.google.com/rss/articles/CBMiVkFVX3lxTE4zaGU2bTY2ZGkzdTRkSkJ0cFpsTGlDUjkxU2FBRURaTWU0c3QzVWZ1MHZZNkZ5Vzk1ZVBnTDFHY2R6ZmdCUkpUTUJsS1pqQTlCRzlzbHV3?oc=5"
|
|
44
|
+
source_url = "https://news.google.com/rss/articles/CBMiqwFBVV95cUxNMTRqdUZpNl9hQldXbGo2YVVLOGFQdkFLYldlMUxUVlNEaElsYjRRODVUMkF3R1RYdWxvT1NoVzdUYS0xSHg3eVdpTjdVODQ5cVJJLWt4dk9vZFBScVp2ZmpzQXZZRy1ncDM5c2tRbXBVVHVrQnpmMGVrQXNkQVItV3h4dVQ1V1BTbjhnM3k2ZUdPdnhVOFk1NmllNTZkdGJTbW9NX0k5U3E2Tkk?oc=5"
|
|
45
|
+
# Decode the URL using decoderv1
|
|
46
|
+
decoded_url_v1 = decoderv1(source_url)
|
|
47
|
+
print(decoded_url_v1)
|
|
48
|
+
|
|
49
|
+
# Decode the URL using decoderv2
|
|
50
|
+
decoded_url_v2 = decoderv2(source_url)
|
|
51
|
+
print(decoded_url_v2)
|
|
52
|
+
print(decoded_url)
|
|
53
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Google News Decoder
|
|
2
|
+
|
|
3
|
+
A Python package to decode Google News URLs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install this package using pip:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pip install googlenewsdecoder
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Credits
|
|
14
|
+
|
|
15
|
+
Original script by [huksley](https://gist.github.com/huksley/bc3cb046157a99cd9d1)
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Here is an example of how to use this package:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
|
|
23
|
+
from googlenewsdecoder import decoderv1, decoderv2
|
|
24
|
+
|
|
25
|
+
if __name__ == "__main__":
|
|
26
|
+
# source_url = "https://news.google.com/rss/articles/CBMiLmh0dHBzOi8vd3d3LmJiYy5jb20vbmV3cy9hcnRpY2xlcy9jampqbnhkdjE4OG_SATJodHRwczovL3d3dy5iYmMuY29tL25ld3MvYXJ0aWNsZXMvY2pqam54ZHYxODhvLmFtcA?oc=5"
|
|
27
|
+
# source_url = "https://news.google.com/rss/articles/CBMiVkFVX3lxTE4zaGU2bTY2ZGkzdTRkSkJ0cFpsTGlDUjkxU2FBRURaTWU0c3QzVWZ1MHZZNkZ5Vzk1ZVBnTDFHY2R6ZmdCUkpUTUJsS1pqQTlCRzlzbHV3?oc=5"
|
|
28
|
+
source_url = "https://news.google.com/rss/articles/CBMiqwFBVV95cUxNMTRqdUZpNl9hQldXbGo2YVVLOGFQdkFLYldlMUxUVlNEaElsYjRRODVUMkF3R1RYdWxvT1NoVzdUYS0xSHg3eVdpTjdVODQ5cVJJLWt4dk9vZFBScVp2ZmpzQXZZRy1ncDM5c2tRbXBVVHVrQnpmMGVrQXNkQVItV3h4dVQ1V1BTbjhnM3k2ZUdPdnhVOFk1NmllNTZkdGJTbW9NX0k5U3E2Tkk?oc=5"
|
|
29
|
+
# Decode the URL using decoderv1
|
|
30
|
+
decoded_url_v1 = decoderv1(source_url)
|
|
31
|
+
print(decoded_url_v1)
|
|
32
|
+
|
|
33
|
+
# Decode the URL using decoderv2
|
|
34
|
+
decoded_url_v2 = decoderv2(source_url)
|
|
35
|
+
print(decoded_url_v2)
|
|
36
|
+
print(decoded_url)
|
|
37
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
from urllib.parse import urlparse
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def decode_google_news_url(source_url):
|
|
6
|
+
url = urlparse(source_url)
|
|
7
|
+
path = url.path.split("/")
|
|
8
|
+
if (
|
|
9
|
+
url.hostname == "news.google.com"
|
|
10
|
+
and len(path) > 1
|
|
11
|
+
and path[len(path) - 2] == "articles"
|
|
12
|
+
):
|
|
13
|
+
base64_str = path[len(path) - 1]
|
|
14
|
+
decoded_bytes = base64.urlsafe_b64decode(base64_str + "==")
|
|
15
|
+
decoded_str = decoded_bytes.decode("latin1")
|
|
16
|
+
|
|
17
|
+
prefix = bytes([0x08, 0x13, 0x22]).decode("latin1")
|
|
18
|
+
if decoded_str.startswith(prefix):
|
|
19
|
+
decoded_str = decoded_str[len(prefix) :]
|
|
20
|
+
|
|
21
|
+
suffix = bytes([0xD2, 0x01, 0x00]).decode("latin1")
|
|
22
|
+
if decoded_str.endswith(suffix):
|
|
23
|
+
decoded_str = decoded_str[: -len(suffix)]
|
|
24
|
+
|
|
25
|
+
bytes_array = bytearray(decoded_str, "latin1")
|
|
26
|
+
length = bytes_array[0]
|
|
27
|
+
if length >= 0x80:
|
|
28
|
+
decoded_str = decoded_str[2 : length + 1]
|
|
29
|
+
else:
|
|
30
|
+
decoded_str = decoded_str[1 : length + 1]
|
|
31
|
+
|
|
32
|
+
return decoded_str
|
|
33
|
+
else:
|
|
34
|
+
return source_url
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# # Example usage:
|
|
38
|
+
# if __name__ == "__main__":
|
|
39
|
+
# source_url = "https://news.google.com/rss/articles/CBMiLmh0dHBzOi8vd3d3LmJiYy5jb20vbmV3cy9hcnRpY2xlcy9jampqbnhkdjE4OG_SATJodHRwczovL3d3dy5iYmMuY29tL25ld3MvYXJ0aWNsZXMvY2pqam54ZHYxODhvLmFtcA?oc=5"
|
|
40
|
+
# print(decode_google_news_url(source_url))
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import base64
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def fetch_decoded_batch_execute(id):
|
|
6
|
+
s = (
|
|
7
|
+
'[[["Fbv4je","[\\"garturlreq\\",[[\\"en-US\\",\\"US\\",[\\"FINANCE_TOP_INDICES\\",\\"WEB_TEST_1_0_0\\"],'
|
|
8
|
+
'null,null,1,1,\\"US:en\\",null,180,null,null,null,null,null,0,null,null,[1608992183,723341000]],'
|
|
9
|
+
'\\"en-US\\",\\"US\\",1,[2,3,4,8],1,0,\\"655000234\\",0,0,null,0],\\"'
|
|
10
|
+
+ id
|
|
11
|
+
+ '\\"]",null,"generic"]]]'
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
headers = {
|
|
15
|
+
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
|
|
16
|
+
"Referer": "https://news.google.com/",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
response = requests.post(
|
|
20
|
+
"https://news.google.com/_/DotsSplashUi/data/batchexecute?rpcids=Fbv4je",
|
|
21
|
+
headers=headers,
|
|
22
|
+
data={"f.req": s},
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
if response.status_code != 200:
|
|
26
|
+
raise Exception("Failed to fetch data from Google.")
|
|
27
|
+
|
|
28
|
+
text = response.text
|
|
29
|
+
header = '[\\"garturlres\\",\\"'
|
|
30
|
+
footer = '\\",'
|
|
31
|
+
if header not in text:
|
|
32
|
+
raise Exception(f"Header not found in response: {text}")
|
|
33
|
+
start = text.split(header, 1)[1]
|
|
34
|
+
if footer not in start:
|
|
35
|
+
raise Exception("Footer not found in response.")
|
|
36
|
+
url = start.split(footer, 1)[0]
|
|
37
|
+
return url
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def decode_google_news_url(source_url):
|
|
41
|
+
url = requests.utils.urlparse(source_url)
|
|
42
|
+
path = url.path.split("/")
|
|
43
|
+
if url.hostname == "news.google.com" and len(path) > 1 and path[-2] == "articles":
|
|
44
|
+
base64_str = path[-1]
|
|
45
|
+
decoded_bytes = base64.urlsafe_b64decode(base64_str + "==")
|
|
46
|
+
decoded_str = decoded_bytes.decode("latin1")
|
|
47
|
+
|
|
48
|
+
prefix = b"\x08\x13\x22".decode("latin1")
|
|
49
|
+
if decoded_str.startswith(prefix):
|
|
50
|
+
decoded_str = decoded_str[len(prefix) :]
|
|
51
|
+
|
|
52
|
+
suffix = b"\xd2\x01\x00".decode("latin1")
|
|
53
|
+
if decoded_str.endswith(suffix):
|
|
54
|
+
decoded_str = decoded_str[: -len(suffix)]
|
|
55
|
+
|
|
56
|
+
bytes_array = bytearray(decoded_str, "latin1")
|
|
57
|
+
length = bytes_array[0]
|
|
58
|
+
if length >= 0x80:
|
|
59
|
+
decoded_str = decoded_str[2 : length + 1]
|
|
60
|
+
else:
|
|
61
|
+
decoded_str = decoded_str[1 : length + 1]
|
|
62
|
+
|
|
63
|
+
if decoded_str.startswith("AU_yqL"):
|
|
64
|
+
return fetch_decoded_batch_execute(base64_str)
|
|
65
|
+
|
|
66
|
+
return decoded_str
|
|
67
|
+
else:
|
|
68
|
+
return source_url
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# # Example usage
|
|
72
|
+
# if __name__ == "__main__":
|
|
73
|
+
# # source_url = "https://news.google.com/rss/articles/CBMiLmh0dHBzOi8vd3d3LmJiYy5jb20vbmV3cy9hcnRpY2xlcy9jampqbnhkdjE4OG_SATJodHRwczovL3d3dy5iYmMuY29tL25ld3MvYXJ0aWNsZXMvY2pqam54ZHYxODhvLmFtcA?oc=5"
|
|
74
|
+
# # source_url = "https://news.google.com/rss/articles/CBMiVkFVX3lxTE4zaGU2bTY2ZGkzdTRkSkJ0cFpsTGlDUjkxU2FBRURaTWU0c3QzVWZ1MHZZNkZ5Vzk1ZVBnTDFHY2R6ZmdCUkpUTUJsS1pqQTlCRzlzbHV3?oc=5"
|
|
75
|
+
# source_url = "https://news.google.com/rss/articles/CBMiqwFBVV95cUxNMTRqdUZpNl9hQldXbGo2YVVLOGFQdkFLYldlMUxUVlNEaElsYjRRODVUMkF3R1RYdWxvT1NoVzdUYS0xSHg3eVdpTjdVODQ5cVJJLWt4dk9vZFBScVp2ZmpzQXZZRy1ncDM5c2tRbXBVVHVrQnpmMGVrQXNkQVItV3h4dVQ1V1BTbjhnM3k2ZUdPdnhVOFk1NmllNTZkdGJTbW9NX0k5U3E2Tkk?oc=5"
|
|
76
|
+
# decoded_url = decode_google_news_url(source_url)
|
|
77
|
+
# print(decoded_url)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: googlenewsdecoder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A package to decode Google News URLs.
|
|
5
|
+
Home-page: https://github.com/SSujitX/google-news-url-decoder
|
|
6
|
+
Author: Sujit Biswas
|
|
7
|
+
Author-email: ssujitxx@example.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
|
|
17
|
+
# Google News Decoder
|
|
18
|
+
|
|
19
|
+
A Python package to decode Google News URLs.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
You can install this package using pip:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
pip install googlenewsdecoder
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Credits
|
|
30
|
+
|
|
31
|
+
Original script by [huksley](https://gist.github.com/huksley/bc3cb046157a99cd9d1)
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Here is an example of how to use this package:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
|
|
39
|
+
from googlenewsdecoder import decoderv1, decoderv2
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
# source_url = "https://news.google.com/rss/articles/CBMiLmh0dHBzOi8vd3d3LmJiYy5jb20vbmV3cy9hcnRpY2xlcy9jampqbnhkdjE4OG_SATJodHRwczovL3d3dy5iYmMuY29tL25ld3MvYXJ0aWNsZXMvY2pqam54ZHYxODhvLmFtcA?oc=5"
|
|
43
|
+
# source_url = "https://news.google.com/rss/articles/CBMiVkFVX3lxTE4zaGU2bTY2ZGkzdTRkSkJ0cFpsTGlDUjkxU2FBRURaTWU0c3QzVWZ1MHZZNkZ5Vzk1ZVBnTDFHY2R6ZmdCUkpUTUJsS1pqQTlCRzlzbHV3?oc=5"
|
|
44
|
+
source_url = "https://news.google.com/rss/articles/CBMiqwFBVV95cUxNMTRqdUZpNl9hQldXbGo2YVVLOGFQdkFLYldlMUxUVlNEaElsYjRRODVUMkF3R1RYdWxvT1NoVzdUYS0xSHg3eVdpTjdVODQ5cVJJLWt4dk9vZFBScVp2ZmpzQXZZRy1ncDM5c2tRbXBVVHVrQnpmMGVrQXNkQVItV3h4dVQ1V1BTbjhnM3k2ZUdPdnhVOFk1NmllNTZkdGJTbW9NX0k5U3E2Tkk?oc=5"
|
|
45
|
+
# Decode the URL using decoderv1
|
|
46
|
+
decoded_url_v1 = decoderv1(source_url)
|
|
47
|
+
print(decoded_url_v1)
|
|
48
|
+
|
|
49
|
+
# Decode the URL using decoderv2
|
|
50
|
+
decoded_url_v2 = decoderv2(source_url)
|
|
51
|
+
print(decoded_url_v2)
|
|
52
|
+
print(decoded_url)
|
|
53
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
googlenewsdecoder/__init__.py
|
|
5
|
+
googlenewsdecoder/decoderv1.py
|
|
6
|
+
googlenewsdecoder/decoderv2.py
|
|
7
|
+
googlenewsdecoder.egg-info/PKG-INFO
|
|
8
|
+
googlenewsdecoder.egg-info/SOURCES.txt
|
|
9
|
+
googlenewsdecoder.egg-info/dependency_links.txt
|
|
10
|
+
googlenewsdecoder.egg-info/requires.txt
|
|
11
|
+
googlenewsdecoder.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
googlenewsdecoder
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="googlenewsdecoder",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
description="A package to decode Google News URLs.",
|
|
7
|
+
long_description=open("README.md").read(),
|
|
8
|
+
long_description_content_type="text/markdown",
|
|
9
|
+
url="https://github.com/SSujitX/google-news-url-decoder",
|
|
10
|
+
author="Sujit Biswas",
|
|
11
|
+
author_email="ssujitxx@example.com",
|
|
12
|
+
license="MIT",
|
|
13
|
+
packages=find_packages(),
|
|
14
|
+
install_requires=[
|
|
15
|
+
"requests", # Add any dependencies here
|
|
16
|
+
],
|
|
17
|
+
classifiers=[
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
],
|
|
22
|
+
python_requires=">=3.9",
|
|
23
|
+
)
|