Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
73 changes: 52 additions & 21 deletions pythonbits/bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .submission import (Submission, form_field, finalize,
SubmissionAttributeError)
from .tracker import Tracker
from .scene import is_scene_crc, query_scene_fname
from . import scene


def format_tag(tag):
Expand All @@ -43,6 +43,17 @@ def format_choices(choices):
for num, value in enumerate(choices)
])

def prompt_yesno(question, default):
while True:
choices = '[Y/n]' if default else '[y/N]'
choice = input('%s %s ' % (question, choices))
if not choice:
return default
elif choice.casefold() == 'y':
return True
elif choice.casefold() == 'n':
return False
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go into a separate module



class BbSubmission(Submission):
default_fields = ("form_title", "tags", "cover")
Expand Down Expand Up @@ -76,28 +87,48 @@ def submit(payload):
t = Tracker()
return t.upload(**payload)

@form_field('scene', 'checkbox')
def _render_scene(self):
# todo: if path is directory, choose file for crc
path = os.path.normpath(self['path']) # removes trailing slash
try:
try:
if os.path.exists(path) and not os.path.isdir(path):
return is_scene_crc(path)
except KeyboardInterrupt:
sys.stdout.write('...skipped\n')
# TODO: These should be detected as scene releases and produce an error message
# because they must be in a directory named after the release:

query_scene_fname(path)
except HTTPError as e:
log.notice(e)
# voa-the_omega_man_x264_bluray.mkv -> The.Omega.Man.1971.1080p.BluRay.x264-VOA/voa-the_omega_man_x264_bluray.mkv
# hd1080-wtl.mkv -> Walk.the.Line.Extended.Cut.2005.1080p.BluRay.x264-HD1080/hd1080-wtl.mkv

while True:
choice = input('Is this a scene release? [y/N] ')

if not choice or choice.lower() == 'n':
return False
elif choice.lower() == 'y':
return True
@form_field('scene', 'checkbox')
def _render_scene(self):
def ask_user():
return prompt_yesno('Is this a scene release?', default=False)

def handle_error(filepath, error):
log.error(str(error))

path = self['path']
modified = scene.check_integrity(path, on_error=handle_error)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if it thinks it's not a scene release, it queries the user every time?

The CRC check should stay as an option IMO, since it's the "safest". And it had the advantage of not querying the user if it wasn't found. My usecase for it is headless submissions.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if it thinks it's not a scene release, it queries the user every time?

No. If it finds nothing, it's not a scene release. This should work all the time unless the release group or title were changed. This is an improvement over the old algorithm that always asked the user unless it found the exact title.

The CRC check should stay as an option IMO

I don't object as long as I can disable it.

# modified is True, False or None (unknown)
if modified is False:
return True
elif modified is True:
if prompt_yesno('Abort?', default=True):
# The return statement is there because sys.exit() is mocked in tests.
log.debug('Aborting')
return sys.exit(1)
else:
log.debug('Asking user')
return ask_user()

# Check if release was renamed
release_names = scene.release_names(path)
if not release_names:
return False
elif release_names:
print('Existing releases:')
for release_name in release_names:
print(' * {}'.format(release_name))
log.error('This release was very likely modified and should not be uploaded like this.')
if prompt_yesno('Abort?', default=True):
# The return statement is there because sys.exit() is mocked in tests.
return sys.exit(1)
else:
return ask_user()

def data_method(self, source, target):
def copy(source, target):
Expand Down
Loading