Skip to content

Commit

Permalink
Rev 481: Allow sort tags (sort:X / order=X) if they don't conflic…
Browse files Browse the repository at this point in the history
…t with date filter
  • Loading branch information
trickerer01 committed Dec 4, 2023
1 parent e172792 commit 3957688
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
8 changes: 7 additions & 1 deletion src/app_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,15 @@ def _parse_tags(self, tags_base_arr: Iterable[str]) -> None:
tags_list, self.neg_and_groups = extract_neg_and_groups(' '.join(tags_base_arr))
for t in tags_list:
if len(t) > 2 and f'{t[0]}{t[-1]}' == '()' and f'{t[:2]}{t[-2:]}' != f'({cc}{cc})':
thread_exit(f'Invalid tag \'{t}\'! Looks like \'or\' group but not fully contatenated with \'{cc}\'.')
thread_exit(f'Error: invalid tag \'{t}\'! Looks like \'or\' group but not fully contatenated with \'{cc}\'')
self.tags_str_arr = split_tags_into_tasks(tags_list, cc, sc, split_always)
self.orig_tasks_count = self._tasks_count()
# conflict: sort tag + date filter
sort_checker = (lambda s: (s.startswith('order=') and s != 'order=id_desc') if ProcModule.is_rn() else
(s.startswith('sort:') and s != 'sort:id'))
sort_tags = list(filter(sort_checker, tags_list))
if sort_tags and (self.date_min != DATE_MIN_DEFAULT or self.date_max != datetime.today().strftime(FMT_DATE)):
thread_exit('Error: cannot use both sort tag and date filter at the same time!')

def _process_all_tags(self) -> None:
if self.warn_nonempty:
Expand Down
16 changes: 6 additions & 10 deletions src/app_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def normalize_tag(ntag: str) -> str:
if len(tags_line) > 0 and (tags_line.find(' ') != -1 or tags_line.find('\n') != -1):
tags_line = re_space_mult.sub(r' ', tags_line.replace('\n', ' '))
setrootconf(Options.OPT_TAGS, tags_line)
parse_suc, tags_list = parse_tags(tags_line)
_, tags_list = parse_tags(tags_line)
tags_str = ' '.join(normalize_tag(tag) for tag in tags_list)
newstr.append(tags_str)
# + module
Expand Down Expand Up @@ -506,16 +506,12 @@ def check_tags_direct() -> None:
Thread(target=check_tags_direct_do).start()


def parse_tags_field(tags: str) -> bool:
result, _ = parse_tags(tags)
return result


def recheck_args() -> Tuple[bool, str]:
# tags
if len(str(getrootconf(Options.OPT_TAGS))) <= 0:
return False, 'No tags specified'
if not parse_tags_field(str(getrootconf(Options.OPT_TAGS))):
parse_result, _ = parse_tags(str(getrootconf(Options.OPT_TAGS)))
if not parse_result:
return False, 'Invalid tags'
# path
pathstr = normalize_path(path.expanduser(str(getrootconf(Options.OPT_PATH))))
Expand All @@ -542,9 +538,9 @@ def recheck_args() -> Tuple[bool, str]:
if datetime.strptime(datebefore_str, FMT_DATE) < datetime.strptime(dateafter_str, FMT_DATE):
return False, 'Maximum date cannot be lower than minimum date'
# Not downloading anything
if str(getrootconf(Options.OPT_IMGSETTING)) == OPTION_VALUES_IMAGES[0] and \
str(getrootconf(Options.OPT_VIDSETTING)) == OPTION_VALUES_VIDEOS[0] and \
(not __RUXX_DEBUG__ or len(OPTION_CMD_DOWNMODE[int(getrootconf(Options.OPT_DOWNLOAD_MODE))]) == 0):
if (str(getrootconf(Options.OPT_IMGSETTING)) == OPTION_VALUES_IMAGES[0] and
str(getrootconf(Options.OPT_VIDSETTING)) == OPTION_VALUES_VIDEOS[0] and
(not __RUXX_DEBUG__ or len(OPTION_CMD_DOWNMODE[int(getrootconf(Options.OPT_DOWNLOAD_MODE))]) == 0)):
return False, 'Not downloading anything'

return True, ''
Expand Down
4 changes: 2 additions & 2 deletions src/app_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
APP_NAME = 'Ruxx'
APP_VER_MAJOR = '1'
APP_VER_SUB = '3'
APP_REVISION = '480'
APP_REVISION = '481'
APP_IS_BETA = False
APP_IS_BETA_TEXT = 'b' * APP_IS_BETA
APP_REV_DATE = '02 Dec 2023'
APP_REV_DATE = '04 Dec 2023'
APP_VERSION = f'{APP_VER_MAJOR}.{APP_VER_SUB}.{APP_REVISION}{APP_IS_BETA_TEXT}'

#
Expand Down
4 changes: 0 additions & 4 deletions src/app_tags_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ def parse_tags(tags: str) -> Tuple[bool, Tuple[str, ...]]:

fulltags = list()
for tag in unique_everseen(tags.split(' ')): # type: str
if (ProcModule.is_rx() or ProcModule.is_rs()) and tag.startswith('sort:'):
return fail()
if ProcModule.is_rn() and tag.startswith('order='):
return fail()
if tag.startswith('(') and re_orgr_full().fullmatch(tag):
try:
tag = split_or_group(tag)
Expand Down
19 changes: 15 additions & 4 deletions src/app_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# internal
from app_cmdargs import prepare_arglist
from app_defines import DEFAULT_HEADERS, DownloadModes
from app_defines import DEFAULT_HEADERS, DownloadModes, ThreadInterruptException
from app_download_rx import DownloaderRx
from app_logger import Logger
from app_utils import normalize_path
Expand All @@ -26,14 +26,15 @@

args_argparse_str1 = (
'sfw asd ned -nds -proxr '
'-timeout 13 -retries 56 -dmode 0 -skip_img -skip_vid -webm -lowres -noproxy -proxynodown -prefix -dump_tags -dump_sources -append_info'
'-timeout 13 -retries 56 -dmode 0 -skip_img -skip_vid -lowres -noproxy -proxynodown -prefix -dump_tags -dump_sources -append_info'
)
args_argparse_str2 = (
'sfw asd ned -nds -proxt '
'-mindate 31-12-1950 -maxdate 01-01-2038 -threads 8 -proxy http://8.8.8.8:65333 '
'-headers {"name1":"value1"} -cookies {"name2":"value2"} '
'-path ' + CUR_PATH
)
args_argparse_str3 = args_argparse_str2 + ' sort:score'


class ArgParseTests(TestCase):
Expand All @@ -42,7 +43,7 @@ def test_argparse1(self) -> None:
args = args_argparse_str1
arglist = prepare_arglist(args.split())
self.assertIsNotNone(arglist.tags)
print(str(arglist.tags))
# print(str(arglist.tags))
self.assertEqual(5, len(arglist.tags))
print('test_argparse1 passed')

Expand All @@ -64,6 +65,7 @@ def test_argparse2(self) -> None:

class DownloaderBaseTests(TestCase):
def test_cmdline1(self) -> None:
Logger.init(True, True)
args = args_argparse_str1
arglist = prepare_arglist(args.split())
with DownloaderRx() as dwn:
Expand All @@ -74,7 +76,7 @@ def test_cmdline1(self) -> None:
self.assertEqual(DownloadModes.DOWNLOAD_FULL, dwn.download_mode)
self.assertTrue(dwn.skip_images)
self.assertTrue(dwn.skip_videos)
self.assertTrue(dwn.prefer_webm)
self.assertFalse(dwn.prefer_webm)
self.assertTrue(dwn.low_res)
self.assertTrue(dwn.ignore_proxy)
self.assertTrue(dwn.ignore_proxy_dwn)
Expand All @@ -85,6 +87,7 @@ def test_cmdline1(self) -> None:
print('test_cmdline1 passed')

def test_cmdline2(self) -> None:
Logger.init(True, True)
args = args_argparse_str2
arglist = prepare_arglist(args.split())
with DownloaderRx() as dwn:
Expand All @@ -100,6 +103,14 @@ def test_cmdline2(self) -> None:
self.assertEqual('value2', dwn.add_cookies.get('name2'))
print('test_cmdline2 passed')

def test_cmdline3(self) -> None:
Logger.init(True, True)
args = args_argparse_str3
arglist = prepare_arglist(args.split())
with DownloaderRx() as dwn:
self.assertRaises(ThreadInterruptException, dwn.parse_args, arglist)
print('test_cmdline3 passed')


# Tests below require actual connection

Expand Down

0 comments on commit 3957688

Please sign in to comment.