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

Better scene detection #76

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
63 changes: 42 additions & 21 deletions pythonbits/bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from .submission import (Submission, form_field, finalize,
SubmissionAttributeError)
from .tracker import Tracker
from .scene import is_scene_crc, query_scene_fname
from . import scene
from . import prompt


def format_tag(tag):
Expand Down Expand Up @@ -76,28 +77,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')

query_scene_fname(path)
except HTTPError as e:
log.notice(e)
# TODO: These should be detected as scene releases and produce an error message
# because they must be in a directory named after the release:

while True:
choice = input('Is this a scene release? [y/N] ')
# 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

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
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
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
13 changes: 13 additions & 0 deletions pythonbits/prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-


def 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
Loading