mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 13:53:15 -07:00
Move common libs to libs/common
This commit is contained in:
parent
8dbb1a2451
commit
1f4bd41bcc
1612 changed files with 962 additions and 10 deletions
5
libs/common/guessit/rules/markers/__init__.py
Normal file
5
libs/common/guessit/rules/markers/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Markers
|
||||
"""
|
52
libs/common/guessit/rules/markers/groups.py
Normal file
52
libs/common/guessit/rules/markers/groups.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Groups markers (...), [...] and {...}
|
||||
"""
|
||||
from rebulk import Rebulk
|
||||
|
||||
|
||||
def groups(config):
|
||||
"""
|
||||
Builder for rebulk object.
|
||||
|
||||
:param config: rule configuration
|
||||
:type config: dict
|
||||
:return: Created Rebulk object
|
||||
:rtype: Rebulk
|
||||
"""
|
||||
rebulk = Rebulk()
|
||||
rebulk.defaults(name="group", marker=True)
|
||||
|
||||
starting = config['starting']
|
||||
ending = config['ending']
|
||||
|
||||
def mark_groups(input_string):
|
||||
"""
|
||||
Functional pattern to mark groups (...), [...] and {...}.
|
||||
|
||||
:param input_string:
|
||||
:return:
|
||||
"""
|
||||
openings = ([], [], [])
|
||||
i = 0
|
||||
|
||||
ret = []
|
||||
for char in input_string:
|
||||
start_type = starting.find(char)
|
||||
if start_type > -1:
|
||||
openings[start_type].append(i)
|
||||
|
||||
i += 1
|
||||
|
||||
end_type = ending.find(char)
|
||||
if end_type > -1:
|
||||
try:
|
||||
start_index = openings[end_type].pop()
|
||||
ret.append((start_index, i))
|
||||
except IndexError:
|
||||
pass
|
||||
return ret
|
||||
|
||||
rebulk.functional(mark_groups)
|
||||
return rebulk
|
47
libs/common/guessit/rules/markers/path.py
Normal file
47
libs/common/guessit/rules/markers/path.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Path markers
|
||||
"""
|
||||
from rebulk import Rebulk
|
||||
|
||||
from rebulk.utils import find_all
|
||||
|
||||
|
||||
def path(config): # pylint:disable=unused-argument
|
||||
"""
|
||||
Builder for rebulk object.
|
||||
|
||||
:param config: rule configuration
|
||||
:type config: dict
|
||||
:return: Created Rebulk object
|
||||
:rtype: Rebulk
|
||||
"""
|
||||
rebulk = Rebulk()
|
||||
rebulk.defaults(name="path", marker=True)
|
||||
|
||||
def mark_path(input_string, context):
|
||||
"""
|
||||
Functional pattern to mark path elements.
|
||||
|
||||
:param input_string:
|
||||
:param context:
|
||||
:return:
|
||||
"""
|
||||
ret = []
|
||||
if context.get('name_only', False):
|
||||
ret.append((0, len(input_string)))
|
||||
else:
|
||||
indices = list(find_all(input_string, '/'))
|
||||
indices += list(find_all(input_string, '\\'))
|
||||
indices += [-1, len(input_string)]
|
||||
|
||||
indices.sort()
|
||||
|
||||
for i in range(0, len(indices) - 1):
|
||||
ret.append((indices[i] + 1, indices[i + 1]))
|
||||
|
||||
return ret
|
||||
|
||||
rebulk.functional(mark_path)
|
||||
return rebulk
|
Loading…
Add table
Add a link
Reference in a new issue