Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added chardet to detect the encoding of the content #6

Merged
merged 7 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Changelog

- v1.1

- Changed

- Add support to automatically identify file encoding.

- v1.0

- Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<center><img src="https://github.com/xnl-h4ck3r/urless/blob/main/urless/images/title.png"></center>

## About - v1.0
## About - v1.1

This is a tool used to de-clutter a list of URLs.
As a starting point, I took the amazing tool [uro](https://github.com/s0md3v/uro/) by Somdev Sangwan. But I wanted to change a few things, make some improvements (like deal with GUIDs) and make it more customizable.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
author="@xnl-h4ck3r",
url="https://github.com/xnl-h4ck3r/urless",
zip_safe=False,
install_requires=["argparse", "pyyaml", "termcolor", "urlparse3"],
install_requires=["argparse", "pyyaml", "termcolor", "urlparse3", "chardet"],
entry_points={
'console_scripts': [
'urless = urless.urless:main',
Expand Down
2 changes: 1 addition & 1 deletion urless/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="1.0"
__version__="1.1"
17 changes: 10 additions & 7 deletions urless/urless.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import Pattern
import yaml
import argparse
import chardet
from signal import SIGINT, signal
from urllib.parse import urlparse
from termcolor import colored
Expand Down Expand Up @@ -438,30 +439,32 @@ def processLine(line):
if args.ignore_querystring:
line = line.split('?')[0].split('#')[0]
return line

def processInput():

global linesOrigCount
try:
if not sys.stdin.isatty():
for line in sys.stdin:
processUrl(processLine(line))
else:
with open(os.path.expanduser(args.input), 'rb') as f:
result = chardet.detect(f.read()) # or readline if the file is large

try:
inFile = open(os.path.expanduser(args.input), 'r')
inFile = open(os.path.expanduser(args.input), 'r', encoding=result['encoding'])
lines = inFile.readlines()
linesOrigCount = len(lines)
for line in lines:
processUrl(processLine(line))
except Exception as e:
writerr(colored('ERROR processInput 2 ' + str(e), 'red'))

try:
inFile.close()
except:
pass
pass
except Exception as e:
writerr(colored('ERROR processInput 1: ' + str(e), 'red'))
writerr(colored('ERROR processInput 1: ' + str(e), 'red'))

def processOutput():
global linesFinalCount, linesOrigCount, patternsGUID, patternsInt, patternsCustomID, patternsLang
Expand Down Expand Up @@ -717,4 +720,4 @@ def main():

if __name__ == '__main__':
main()