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

Add ability to manually change episode quality. Fixes #4474 #4658

Merged
merged 17 commits into from
Jul 15, 2018
Merged
Show file tree
Hide file tree
Changes from 15 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Removed the old `/ui` route ([#4565](https://github.com/pymedusa/Medusa/pull/4565))
- Added a simple "Loading..." message while the page is loading ([#4629](https://github.com/pymedusa/Medusa/pull/4629))
- Expanded episode status management capabilities, added support for Downloaded, Archived ([#4647](https://github.com/pymedusa/Medusa/pull/4647))
- Added ability to manually change episode quality ([#4658](https://github.com/pymedusa/Medusa/pull/4658))
- _Simple message describing the improvement, and a link to the pull request._

**Fixes**
Expand Down
23 changes: 11 additions & 12 deletions medusa/server/web/home/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def displayShow(self, indexername=None, seriesid=None, ):
for cur_result in sql_results:
cur_ep_cat = series_obj.get_overview(cur_result[b'status'], cur_result[b'quality'], manually_searched=cur_result[b'manually_searched'])
if cur_ep_cat:
ep_cats['{season}x{episode}'.format(season=cur_result[b'season'], episode=cur_result[b'episode'])] = cur_ep_cat
ep_cats['s{season}e{episode}'.format(season=cur_result[b'season'], episode=cur_result[b'episode'])] = cur_ep_cat
ep_counts[cur_ep_cat] += 1

bwl = None
Expand Down Expand Up @@ -1349,8 +1349,8 @@ def snatchSelection(self, indexername, seriesid, season=None, episode=None, manu
cur_ep_cat = series_obj.get_overview(cur_result[b'status'], cur_result[b'quality'],
manually_searched=cur_result[b'manually_searched'])
if cur_ep_cat:
ep_cats['{season}x{episode}'.format(season=cur_result[b'season'],
episode=cur_result[b'episode'])] = cur_ep_cat
ep_cats['s{season}e{episode}'.format(season=cur_result[b'season'],
episode=cur_result[b'episode'])] = cur_ep_cat
ep_counts[cur_ep_cat] += 1

return t.render(
Expand Down Expand Up @@ -1923,13 +1923,13 @@ def setStatus(self, indexername=None, seriesid=None, eps=None, status=None, dire
logger.log('Attempting to set status for episode {series} {episode} to {status}'.format(
series=series_obj.name, episode=cur_ep, status=status), logger.DEBUG)

ep_info = cur_ep.split('x')
if not all(ep_info):
season_no, episode_no = cur_ep.lstrip('s').split('e')
if not all([season_no, episode_no]):
logger.log('Something went wrong when trying to set status, season: {season}, episode: {episode}'.format
(season=ep_info[0], episode=ep_info[1]), logger.DEBUG)
(season=season_no, episode=episode_no), logger.DEBUG)
continue

ep_obj = series_obj.get_episode(ep_info[0], ep_info[1])
ep_obj = series_obj.get_episode(season_no, episode_no)
if not ep_obj:
return self._genericMessage('Error', 'Episode couldn\'t be retrieved')

Expand Down Expand Up @@ -2110,16 +2110,15 @@ def doRename(self, indexername=None, seriesid=None, eps=None):

main_db_con = db.DBConnection()
for cur_ep in eps.split('|'):

ep_info = cur_ep.split('x')
season_no, episode_no = cur_ep.lstrip('s').split('e')

# this is probably the worst possible way to deal with double eps
# but I've kinda painted myself into a corner here with this stupid database
ep_result = main_db_con.select(
b'SELECT location '
b'FROM tv_episodes '
b'WHERE indexer = ? AND showid = ? AND season = ? AND episode = ? AND 5=5',
[indexer_name_to_id(indexername), seriesid, ep_info[0], ep_info[1]])
[indexer_name_to_id(indexername), seriesid, season_no, episode_no])
if not ep_result:
logger.log(u'Unable to find an episode for {episode}, skipping'.format
(episode=cur_ep), logger.WARNING)
Expand All @@ -2128,10 +2127,10 @@ def doRename(self, indexername=None, seriesid=None, eps=None):
b'SELECT season, episode '
b'FROM tv_episodes '
b'WHERE location = ? AND episode != ?',
[ep_result[0][b'location'], ep_info[1]]
[ep_result[0][b'location'], episode_no]
)

root_ep_obj = series_obj.get_episode(ep_info[0], ep_info[1])
root_ep_obj = series_obj.get_episode(season_no, episode_no)
root_ep_obj.related_episodes = []

for cur_related_ep in related_eps_result:
Expand Down
5 changes: 3 additions & 2 deletions medusa/server/web/manage/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ def downloadSubtitleMissed(self, *args, **kwargs):
b"AND location != ''",
[DOWNLOADED, cur_indexer_id, cur_series_id]
)
to_download[(cur_indexer_id, cur_series_id)] = [str(x[b'season']) + 'x' + str(x[b'episode']) for x in all_eps_results]
to_download[(cur_indexer_id, cur_series_id)] = ['s' + str(x[b'season']) + 'e' + str(x[b'episode'])
for x in all_eps_results]

for epResult in to_download[(cur_indexer_id, cur_series_id)]:
season, episode = epResult.split('x')
season, episode = epResult.lstrip('s').split('e')
Copy link
Contributor

Choose a reason for hiding this comment

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

I see a problem here, look at line 297, it's still using the SNxEP format


series_obj = Show.find_by_id(app.showList, cur_indexer_id, cur_series_id)
series_obj.get_episode(season, episode).download_subtitles()
Expand Down
4 changes: 2 additions & 2 deletions themes-default/slim/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
],
"rules": {
"indent": ["error", 4],
"object-curly-spacing": ["error", "always"]
"space-before-function-paren": ["error", "never"]
"object-curly-spacing": ["error", "always"],
"space-before-function-paren": ["error", "never"],
"unicorn/catch-error-name": ["error", { "name": "error" }]
},
"env": {
Expand Down
39 changes: 32 additions & 7 deletions themes-default/slim/static/js/home/display-show.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ MEDUSA.home.displayShow = function() { // eslint-disable-line max-lines

$('#changeStatus').on('click', () => {
const epArr = [];
const status = $('#statusSelect').val();
const quality = $('#qualitySelect').val();
const seriesSlug = $('#series-slug').val();

$('.epCheck').each(function() {
if (this.checked === true) {
Expand All @@ -69,21 +72,28 @@ MEDUSA.home.displayShow = function() { // eslint-disable-line max-lines
return false;
}

window.location.href = $('base').attr('href') + 'home/setStatus?' +
'indexername=' + $('#indexer-name').attr('value') +
'&seriesid=' + $('#series-id').attr('value') +
'&eps=' + epArr.join('|') +
'&status=' + $('#statusSelect').val();
if (quality !== '') {
setQuality(quality, seriesSlug, epArr);
}

if (status !== '') {
window.location.href = $('base').attr('href') + 'home/setStatus?' +
'indexername=' + $('#indexer-name').attr('value') +
'&seriesid=' + $('#series-id').attr('value') +
'&eps=' + epArr.join('|') +
'&status=' + status;
}
});

$('.seasonCheck').on('click', function() {
const seasCheck = this;
const seasNo = $(seasCheck).attr('id');

$('#collapseSeason-' + seasNo).collapse('show');
const seasonIdentifier = 's' + seasNo;
$('.epCheck:visible').each(function() {
const epParts = $(this).attr('id').split('x');
if (epParts[0] === seasNo) {
const epParts = $(this).attr('id').split('e');
if (epParts[0] === seasonIdentifier) {
this.checked = seasCheck.checked;
}
});
Expand Down Expand Up @@ -414,4 +424,19 @@ MEDUSA.home.displayShow = function() { // eslint-disable-line max-lines
log.error(error.data);
});
});

function setQuality(quality, seriesSlug, episodes) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use const setQuality = (quality, seriesSlug, episodes) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure? That's a really ugly syntax IMO 😕

Copy link
Collaborator

Choose a reason for hiding this comment

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

How so? That's an arrow function.

The reason I wanted this change was the fact that functions get hoisted and you should avoid that if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like that at first. But it gets better when your getting used to it

const patchData = {};
episodes.forEach(episode => {
patchData[episode] = { quality: parseInt(quality, 10) };
});

api.patch('series/' + seriesSlug + '/episodes', patchData)
.then(response => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

.then should be on the same line as the api.patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I change it the XO lint won't pass.

Copy link
Contributor

Choose a reason for hiding this comment

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

Try

api.patch('series/' + seriesSlug + '/episodes', patchData).then(response => {
    log.info(response.data);
    window.location.reload();
}).catch(error => {
    log.error(error.data);
});

log.info(response.data);
window.location.reload();
}).catch(error => {
log.error(error.data);
});
}
};
Loading