-
Notifications
You must be signed in to change notification settings - Fork 9
Better scene detection #76
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
eb290fc
ed363a1
3d9e304
bf96470
e23d29f
76bd6fb
a27d706
50c523b
d169540
6f6c0de
6d0542a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
|
@@ -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 | ||
|
|
||
|
|
||
| class BbSubmission(Submission): | ||
| default_fields = ("form_title", "tags", "cover") | ||
|
|
@@ -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) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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.
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): | ||
|
|
||
There was a problem hiding this comment.
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