-
Notifications
You must be signed in to change notification settings - Fork 279
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
Feature/show sub original release #7955
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a199e80
Add history api route. (python apiv2 changes)
p0psicles c9a8c8b
Add the last release name from the history table, to the subtitle-sea…
p0psicles 6311ec0
Fix a small front end (racing condition) bug.
p0psicles bb84c45
Only show release names when status in Snatched or Downloaded
p0psicles 26d1ad1
Fix lint errors
p0psicles 507e90b
Update api-description
p0psicles 1754d87
Added "provider" to api-description.yml
p0psicles 07f78c3
Updated changelog
p0psicles 98c82f4
Merge remote-tracking branch 'remotes/origin/develop' into feature/sh…
p0psicles 17ea616
Review comments.
p0psicles 2a53728
Re-arange subtitle-search.vue to make it more test friendly
p0psicles 6ae5e57
Fix getting proper_tags & manually_searched
medariox 7e9f32e
Merge branch 'develop' into feature/show-sub-original-release
medariox d6ce12c
make sure the pagination response is valid.
p0psicles 75366df
Merge remote-tracking branch 'remotes/origin/feature/show-sub-origina…
p0psicles 8f32868
Disabling the history tests.
p0psicles 7586bec
Use the provider field, as a generic string field.
p0psicles 5dc8cdf
Fix flake warnings
p0psicles 3f1d499
flake
p0psicles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# coding=utf-8 | ||
"""Request handler for series and episodes.""" | ||
from __future__ import unicode_literals | ||
|
||
import logging | ||
from os.path import basename | ||
|
||
from medusa import db | ||
from medusa.common import statusStrings | ||
from medusa.logger.adapters.style import BraceAdapter | ||
from medusa.server.api.v2.base import BaseRequestHandler | ||
from medusa.server.api.v2.history import HistoryHandler | ||
from medusa.tv.episode import Episode, EpisodeNumber | ||
from medusa.tv.series import Series, SeriesIdentifier | ||
|
||
|
||
log = BraceAdapter(logging.getLogger(__name__)) | ||
log.logger.addHandler(logging.NullHandler()) | ||
|
||
|
||
class EpisodeHistoryHandler(BaseRequestHandler): | ||
"""Episode history request handler.""" | ||
|
||
#: parent resource handler | ||
parent_handler = HistoryHandler | ||
#: resource name | ||
name = 'episode' | ||
#: identifier | ||
identifier = ('episode_slug', r'[\w-]+') | ||
#: path param | ||
path_param = ('path_param', r'\w+') | ||
#: allowed HTTP methods | ||
allowed_methods = ('GET',) | ||
|
||
def get(self, series_slug, episode_slug, path_param): | ||
"""Query episode's history information. | ||
|
||
:param series_slug: series slug. E.g.: tvdb1234 | ||
:param episode_slug: episode slug. E.g.: s01e01 | ||
:param path_param: | ||
""" | ||
series_identifier = SeriesIdentifier.from_slug(series_slug) | ||
if not series_identifier: | ||
return self._bad_request('Invalid series slug') | ||
|
||
series = Series.find_by_identifier(series_identifier) | ||
if not series: | ||
return self._not_found('Series not found') | ||
|
||
if not episode_slug: | ||
return self._bad_request('Invalid episode slug') | ||
|
||
episode_number = EpisodeNumber.from_slug(episode_slug) | ||
if not episode_number: | ||
return self._not_found('Invalid episode number') | ||
|
||
episode = Episode.find_by_series_and_episode(series, episode_number) | ||
if not episode: | ||
return self._not_found('Episode not found') | ||
|
||
sql_base = """ | ||
SELECT rowid, date, action, quality, | ||
provider, version, resource, size, proper_tags, | ||
indexer_id, showid, season, episode, manually_searched | ||
FROM history | ||
WHERE showid = ? AND indexer_id = ? AND season = ? AND episode = ? | ||
""" | ||
|
||
params = [series.series_id, series.indexer, episode.season, episode.episode] | ||
|
||
sql_base += ' ORDER BY date DESC' | ||
results = db.DBConnection().select(sql_base, params) | ||
|
||
def data_generator(): | ||
"""Read history data and normalize key/value pairs.""" | ||
for item in results: | ||
d = {} | ||
d['id'] = item['rowid'] | ||
d['series'] = SeriesIdentifier.from_id(item['indexer_id'], item['showid']).slug | ||
d['status'] = item['action'] | ||
d['actionDate'] = item['date'] | ||
|
||
d['resource'] = basename(item['resource']) | ||
d['size'] = item['size'] | ||
d['properTags'] = item['proper_tags'] | ||
d['statusName'] = statusStrings.get(item['action']) | ||
d['season'] = item['season'] | ||
d['episode'] = item['episode'] | ||
d['manuallySearched'] = bool(item['manually_searched']) | ||
d['provider'] = item['provider'] | ||
|
||
yield d | ||
|
||
if not results: | ||
return self._not_found('History data not found for show {show} and episode {episode}'.format( | ||
show=series.identifier.slug, episode=episode.slug | ||
)) | ||
|
||
return self._ok(data=list(data_generator())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# coding=utf-8 | ||
"""Request handler for alias (scene exceptions).""" | ||
from __future__ import unicode_literals | ||
|
||
from os.path import basename | ||
|
||
from medusa import db | ||
from medusa.common import statusStrings | ||
from medusa.server.api.v2.base import BaseRequestHandler | ||
from medusa.tv.series import SeriesIdentifier | ||
|
||
|
||
class HistoryHandler(BaseRequestHandler): | ||
"""History request handler.""" | ||
|
||
#: resource name | ||
name = 'history' | ||
#: identifier | ||
identifier = ('series_slug', r'\w+') | ||
#: path param | ||
path_param = ('path_param', r'\w+') | ||
#: allowed HTTP methods | ||
allowed_methods = ('GET', 'POST', 'PUT', 'DELETE') | ||
|
||
def get(self, series_slug, path_param): | ||
""" | ||
Get history records. | ||
|
||
History records can be specified using a show slug. | ||
""" | ||
sql_base = """ | ||
SELECT rowid, date, action, quality, | ||
provider, version, proper_tags, manually_searched, | ||
resource, size, indexer_id, showid, season, episode | ||
FROM history | ||
""" | ||
params = [] | ||
|
||
arg_page = self._get_page() | ||
arg_limit = self._get_limit(default=50) | ||
|
||
if series_slug is not None: | ||
series_identifier = SeriesIdentifier.from_slug(series_slug) | ||
if not series_identifier: | ||
return self._bad_request('Invalid series') | ||
|
||
sql_base += ' WHERE indexer_id = ? AND showid = ?' | ||
params += [series_identifier.indexer.id, series_identifier.id] | ||
|
||
sql_base += ' ORDER BY date DESC' | ||
results = db.DBConnection().select(sql_base, params) | ||
|
||
def data_generator(): | ||
"""Read and paginate history records.""" | ||
start = arg_limit * (arg_page - 1) | ||
|
||
for item in results[start:start + arg_limit]: | ||
d = {} | ||
d['id'] = item['rowid'] | ||
d['series'] = SeriesIdentifier.from_id(item['indexer_id'], item['showid']).slug | ||
d['status'] = item['action'] | ||
d['actionDate'] = item['date'] | ||
|
||
d['resource'] = basename(item['resource']) | ||
d['size'] = item['size'] | ||
d['properTags'] = item['proper_tags'] | ||
d['statusName'] = statusStrings.get(item['action']) | ||
d['season'] = item['season'] | ||
d['episode'] = item['episode'] | ||
d['manuallySearched'] = bool(item['manually_searched']) | ||
d['provider'] = item['provider'] | ||
|
||
yield d | ||
|
||
if not results: | ||
return self._not_found('History data not found') | ||
|
||
return self._paginate(data_generator=data_generator) | ||
|
||
def delete(self, identifier, **kwargs): | ||
"""Delete a history record.""" | ||
identifier = self._parse(identifier) | ||
if not identifier: | ||
return self._bad_request('Invalid history id') | ||
|
||
main_db_con = db.DBConnection() | ||
last_changes = main_db_con.connection.total_changes | ||
main_db_con.action('DELETE FROM history WHERE row_id = ?', [identifier]) | ||
if main_db_con.connection.total_changes - last_changes <= 0: | ||
return self._not_found('History row not found') | ||
|
||
return self._no_content() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@medariox @sharkykh yes i'm disabling these.
I'm not getting it to work. If some of you want to spend time on this, feel free.