Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.
Open
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
22 changes: 19 additions & 3 deletions CrossSeedAutoDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

parser = argparse.ArgumentParser(description='Searches for cross-seedable torrents')
parser.add_argument('-p', '--parse-dir', dest='parse_dir', action='store_true', help='Optional. Indicates whether to search for all the items inside the input directory as individual releases')
parser.add_argument('-g', '--match-release-group', dest='match_release_group', action='store_true', help='Optional. Indicates whether to attempt to extract a release group name and include it in the search query.')
parser.add_argument('-d', '--delay', metavar='delay', dest='delay', type=int, default=10, help='Pause duration (in seconds) between searches (default: 10)')
parser.add_argument('-i', '--input-path', metavar='input_path', dest='input_path', type=str, required=True, help='File or Folder for which to find a matching torrent')
parser.add_argument('-s', '--save-path', metavar='save_path', dest='save_path', type=str, required=True, help='Directory in which to store downloaded torrents')
Expand Down Expand Up @@ -48,7 +49,8 @@ def get_release_data(path):
'main_path': path,
'basename': os.path.basename(path),
'size': ReleaseData._get_total_size(path),
'guessed_data': guessit( os.path.basename(path) )
'guessed_data': guessit( os.path.basename(path) ),
'release_group': ReleaseData._get_release_group(path)
}

@staticmethod
Expand Down Expand Up @@ -86,6 +88,16 @@ def _is_link(file_path):
else:
return os.path.islink(file_path)

@staticmethod
def _get_release_group(path):
basename = os.path.basename(path)
if len(basename.split('-')) <= 1:
return None
release_group = os.path.splitext(basename.split('-')[-1])[0].strip()
if any(bad_char in release_group for bad_char in [' ', '.']):
return None
return release_group


class Searcher:
# 1 MibiByte == 1024^2 bytes
Expand All @@ -112,6 +124,9 @@ def search(self, local_release_data, search_history):
if local_release_data['guessed_data'].get('year') is not None:
search_query += ' ' + str( local_release_data['guessed_data']['year'] )

if ARGS.match_release_group and local_release_data['release_group'] is not None:
search_query += ' ' + local_release_data['release_group']

search_url = self._get_full_search_url(search_query, local_release_data)
logger.info(search_url)

Expand Down Expand Up @@ -386,11 +401,12 @@ def main():
logger.info( 'Skipping file. Could not get title from filename: {}'.format(local_release_data['basename']) )
continue

info = 'Searching for {num} of {size}: {title} {year}'.format(
info = 'Searching for {num} of {size}: {title} {year} {release_group}'.format(
num=i + 1,
size=len(paths),
title=local_release_data['guessed_data']['title'],
year=local_release_data['guessed_data'].get('year', '')
year=local_release_data['guessed_data'].get('year', ''),
release_group=f"""{'' if not ARGS.match_release_group else f"(release group: {local_release_data['release_group']})"}"""
)
print(info)
logger.info(info + f'/ {os.path.basename(path)}')
Expand Down