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

Added DELETE method for deleting an episode to the apiv2. #5685

Merged
merged 9 commits into from
Nov 12, 2018
Merged
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
- Added Join notifier ([#5241](https://github.com/pymedusa/Medusa/pull/5241))

#### Improvements
- Vueified "config - notifications" page. Improved components: config-textbox, select-list, show-selector, config-textbox-number. Improved responsiveness of the notification page on smaller screens ([#4913](https://github.com/pymedusa/Medusa/pull/4913))
- Allow the use of priorities in the Pushover notifier ([#5567](https://github.com/pymedusa/Medusa/pull/5567))
- Allow Nyaa and Anidex to search for non-anime shows ([#5680](https://github.com/pymedusa/Medusa/pull/5680) & [#5680](https://github.com/pymedusa/Medusa/pull/5681))
- Vueified "config - notifications" page:
- Improved components: config-textbox, select-list, show-selector, config-textbox-number
- Improved responsiveness of the notification page on smaller screens ([#4913](https://github.com/pymedusa/Medusa/pull/4913))
- Allowed the use of priorities in the Pushover notifier ([#5567](https://github.com/pymedusa/Medusa/pull/5567))
- Added delete method to EpisodeHandler (apiv2), for deleting a single episode ([#5685](https://github.com/pymedusa/Medusa/pull/5685))
- Allowed Nyaa and Anidex to search for non-anime shows ([#5680](https://github.com/pymedusa/Medusa/pull/5680) & [#5681](https://github.com/pymedusa/Medusa/pull/5681))

#### Fixes
- Fixed test not working for Download Station ([#5561](https://github.com/pymedusa/Medusa/pull/5561))
Expand Down
36 changes: 36 additions & 0 deletions dredd/api-description.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,35 @@ paths:
{"status": 2, "quality": 4}
path-params:
id: e999
delete:
summary: Delete a specific episode from a given series
description: Delete a specific episode from a given series
parameters:
- $ref: '#/parameters/series-id'
name: seriesid
- $ref: '#/parameters/episode-id-delete'
name: id
responses:
204:
description: Episode is deleted successfully
400:
$ref: '#/responses/error'
description: Invalid id
x-request:
path-params:
seriesid: tvdb301824
id: 123456
404:
$ref: '#/responses/error'
description: Episode not found
x-request:
path-params:
seriesid: tvdb301824
id: s9999e9999
409:
$ref: '#/responses/error'
description: Unable to delete episode
x-disabled: true
/series/{seriesid}/episodes/{id}/{field}:
get:
summary: Return a specific field from a given episode
Expand Down Expand Up @@ -2342,6 +2371,13 @@ parameters:
description: The episode id to retrieve. E.g. s02e03, e34 or 2016-12-31
x-example: s01e01
type: string
episode-id-delete:
name: episode-id-delete
in: path
required: true
description: The episode id to retrieve. E.g. s02e03, e34 or 2016-12-31
x-example: s01e02
type: string
alias-id:
name: alias-id
in: path
Expand Down
31 changes: 30 additions & 1 deletion medusa/server/api/v2/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging

from medusa.helper.exceptions import EpisodeDeletedException
from medusa.logger.adapters.style import BraceAdapter
from medusa.server.api.v2.base import (
BaseRequestHandler,
Expand Down Expand Up @@ -36,7 +37,7 @@ class EpisodeHandler(BaseRequestHandler):
#: path param
path_param = ('path_param', r'\w+')
#: allowed HTTP methods
allowed_methods = ('GET', 'PATCH', )
allowed_methods = ('GET', 'PATCH', 'DELETE',)

def http_get(self, series_slug, episode_slug, path_param):
"""Query episode information.
Expand Down Expand Up @@ -156,3 +157,31 @@ def _patch_episode(episode, data):
)

return accepted

def http_delete(self, series_slug, episode_slug, **kwargs):
"""Delete the episode."""
if not series_slug:
return self._method_not_allowed('Deleting multiple series are not allowed')

identifier = SeriesIdentifier.from_slug(series_slug)
if not identifier:
return self._bad_request('Invalid series identifier')

series = Series.find_by_identifier(identifier)
if not series:
return self._not_found('Series not found')

episode_number = EpisodeNumber.from_slug(episode_slug)
if not episode_number:
return self._bad_request('Invalid episode number')

episode = Episode.find_by_series_and_episode(series, episode_number)
if not episode:
return self._not_found('Episode not found')

try:
episode.delete_episode()
except EpisodeDeletedException:
return self._no_content()
else:
return self._conflict('Unable to delete episode')
4 changes: 2 additions & 2 deletions medusa/tv/episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class EpisodeNumber(Identifier):

date_fmt = '%Y-%m-%d'
regex = re.compile(r'\b(?:(?P<air_date>\d{4}-\d{2}-\d{2})|'
r'(?:s(?P<season>\d{1,4}))(?:e(?P<episode>\d{1,2}))|'
r'(?:e(?P<abs_episode>\d{1,3})))\b', re.IGNORECASE)
r'(?:s(?P<season>\d{1,4}))(?:e(?P<episode>\d{1,4}))|'
r'(?:e(?P<abs_episode>\d{1,4})))\b', re.IGNORECASE)

@classmethod
def from_slug(cls, slug):
Expand Down
18 changes: 11 additions & 7 deletions tests/test_tv_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_series_identifier(p):
},
{ # p11: e1234
'slug': 'e1234',
'expected': None,
'expected': AbsoluteNumber(1234),
},
{ # p12: E15
'slug': 'E15',
Expand All @@ -144,27 +144,31 @@ def test_series_identifier(p):
'slug': 's2017e02',
'expected': RelativeNumber(2017, 2),
},
{ # p15: 2017-07-16
{ # p15: s01e9999
'slug': 's01e9999',
'expected': RelativeNumber(1, 9999),
},
{ # p16: 2017-07-16
'slug': '2017-07-16',
'expected': AirByDateNumber(datetime(year=2017, month=7, day=16)),
},
{ # p16: 2017-17-16 (invalid date)
{ # p17: 2017-17-16 (invalid date)
'slug': '2017-17-16',
'expected': None,
},
{ # p17: Invalid
{ # p18: Invalid
'slug': 's01e022017-07-16',
'expected': None,
},
{ # p18: Invalid
{ # p19: Invalid
'slug': '22017-07-16',
'expected': None,
},
{ # p19: Invalid
{ # p20: Invalid
'slug': 'ss01',
'expected': None,
},
{ # p20: Invalid
{ # p21: Invalid
'slug': 'ee01',
'expected': None,
},
Expand Down