Commit 9f0903de authored by echel0n's avatar echel0n
Browse files

Refactored video files to be mime typed by built-in module mimetypes, no...

Refactored video files to be mime typed by built-in module mimetypes, no longer requires end-user to specify allowed video file extensions
Fixed issues with custom Newznab providers and saving settings
parent 790c4251
...@@ -842,9 +842,25 @@ class Config(object): ...@@ -842,9 +842,25 @@ class Config(object):
default=self.general.calendar_unprotected, field_type=bool) default=self.general.calendar_unprotected, field_type=bool)
self.general.calendar_icons = self._get_config_file_value(config_object, 'General', 'calendar_icons', default=self.general.calendar_icons, self.general.calendar_icons = self._get_config_file_value(config_object, 'General', 'calendar_icons', default=self.general.calendar_icons,
field_type=bool) field_type=bool)
self.general.no_restart = self._get_config_file_value(config_object, 'General', 'no_restart', default=self.general.no_restart, field_type=bool)
self.general.no_restart = self._get_config_file_value(
config_object,
'General',
'no_restart',
default=self.general.no_restart,
field_type=bool
)
self.general.allowed_video_file_exts = ','.join( self.general.allowed_video_file_exts = ','.join(
self._get_config_file_value(config_object, 'General', 'allowed_video_file_exts', default=self.general.allowed_video_file_exts, field_type=list)) self._get_config_file_value(
config_object,
'General',
'allowed_video_file_exts',
default=self.general.allowed_video_file_exts.split(','),
field_type=list
)
)
self.general.extra_scripts = self._get_config_file_value(config_object, 'General', 'extra_scripts', default=self.general.extra_scripts, field_type=str) self.general.extra_scripts = self._get_config_file_value(config_object, 'General', 'extra_scripts', default=self.general.extra_scripts, field_type=str)
self.general.display_all_seasons = self._get_config_file_value(config_object, 'General', 'display_all_seasons', self.general.display_all_seasons = self._get_config_file_value(config_object, 'General', 'display_all_seasons',
default=self.general.display_all_seasons, field_type=bool) default=self.general.display_all_seasons, field_type=bool)
......
...@@ -26,6 +26,7 @@ import datetime ...@@ -26,6 +26,7 @@ import datetime
import glob import glob
import hashlib import hashlib
import ipaddress import ipaddress
import mimetypes
import os import os
import platform import platform
import random import random
...@@ -60,6 +61,17 @@ from sickrage.core.enums import TorrentMethod ...@@ -60,6 +61,17 @@ from sickrage.core.enums import TorrentMethod
from sickrage.core.helpers import encryption from sickrage.core.helpers import encryption
from sickrage.core.websession import WebSession from sickrage.core.websession import WebSession
mimetypes.add_type('video/divx', '.divx')
mimetypes.add_type("video/x-flv", ".flv")
mimetypes.add_type("video/x-f4v", ".f4v")
mimetypes.add_type("video/x-dvd-iso", ".iso")
mimetypes.add_type("video/x-dvd-iso", ".img")
mimetypes.add_type("video/x-dvd-iso", ".nrg")
mimetypes.add_type("video/dvd", ".vob")
mimetypes.add_type("video/mpeg", ".wtv")
mimetypes.add_type("application/x-bittorrent", ".torrent")
mimetypes.add_type("application/x-nzb", ".nzb")
def safe_getattr(object, name, default=None): def safe_getattr(object, name, default=None):
try: try:
...@@ -154,7 +166,10 @@ def remove_extension(name): ...@@ -154,7 +166,10 @@ def remove_extension(name):
if name and "." in name: if name and "." in name:
base_name, sep, extension = name.rpartition('.') base_name, sep, extension = name.rpartition('.')
if base_name and extension.lower() in ['nzb', 'torrent'] + sickrage.app.config.general.allowed_video_file_exts.split(','): mime_type = mimetypes.guess_type(name)[0]
is_video = True if mime_type is not None and mime_type.startswith('video') else False
if base_name and extension.lower() in ['nzb', 'torrent'] or is_video:
name = base_name name = base_name
return name return name
...@@ -319,7 +334,8 @@ def is_media_file(filename): ...@@ -319,7 +334,8 @@ def is_media_file(filename):
if re.search('extras?$', sepFile[0], re.I): if re.search('extras?$', sepFile[0], re.I):
return False return False
return sepFile[-1].lower() in sickrage.app.config.general.allowed_video_file_exts.split(',') mime_type = mimetypes.guess_type(filename)[0]
return True if mime_type is not None and mime_type.startswith('video') else False
def is_rar_file(filename): def is_rar_file(filename):
......
...@@ -159,27 +159,7 @@ ...@@ -159,27 +159,7 @@
<!-- start div for editing providers //--> <!-- start div for editing providers //-->
% for providerID, providerObj in sickrage.app.search_providers.newznab().items(): % for providerID, providerObj in sickrage.app.search_providers.newznab().items():
<div class="providerDiv" id="${providerID}Div"> <div class="providerDiv" id="${providerID}Div">
% if not providerObj.default: % if providerObj.private and providerObj.default:
<div class="form-row form-group">
<div class="col-lg-3 col-md-4 col-sm-5">
<label class="component-title">${_('URL:')}</label>
</div>
<div class="col-lg-9 col-md-8 col-sm-7 component-desc">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><span class="fas fa-globe"></span></span>
</div>
<input id="${providerID}_url"
value="${providerObj.urls['base_url']}"
title="Provider URL"
class="form-control"
autocapitalize="off" disabled/>
</div>
</div>
</div>
% endif
% if providerObj.private:
<div class="form-row form-group"> <div class="form-row form-group">
<div class="col-lg-3 col-md-4 col-sm-5"> <div class="col-lg-3 col-md-4 col-sm-5">
<label class="component-title">${_('API key:')}</label> <label class="component-title">${_('API key:')}</label>
...@@ -192,7 +172,7 @@ ...@@ -192,7 +172,7 @@
<input id="${providerID}_api_key" <input id="${providerID}_api_key"
name="${providerID}_api_key" name="${providerID}_api_key"
value="${providerObj.api_key}" value="${providerObj.api_key}"
newznab_name="${providerID}_api_key" newznab_name="${providerID}"
class="newznab_key form-control" class="newznab_key form-control"
title="Provider API key" title="Provider API key"
autocapitalize="off"/> autocapitalize="off"/>
...@@ -218,7 +198,7 @@ ...@@ -218,7 +198,7 @@
% endif % endif
% if hasattr(providerObj, 'enable_backlog'): % if hasattr(providerObj, 'enable_backlog'):
<div class="row field-pair${(' d-none', '')[providerObj.supports_backlog]}"> <div class="form-row form-group ${('d-none', '')[providerObj.supports_backlog]}">
<div class="col-lg-3 col-md-4 col-sm-5"> <div class="col-lg-3 col-md-4 col-sm-5">
<label class="component-title">${_('Enable backlog searches')}</label> <label class="component-title">${_('Enable backlog searches')}</label>
</div> </div>
...@@ -892,27 +872,27 @@ ...@@ -892,27 +872,27 @@
</div> </div>
% endif % endif
## % if hasattr(providerObj, 'cat') and providerID == 'tntvillage': ## % if hasattr(providerObj, 'cat') and providerID == 'tntvillage':
## <div class="form-row form-group"> ## <div class="form-row form-group">
## <div class="col-lg-3 col-md-4 col-sm-5"> ## <div class="col-lg-3 col-md-4 col-sm-5">
## <label class="component-title">${_('Category:')}</label> ## <label class="component-title">${_('Category:')}</label>
## </div> ## </div>
## <div class="col-lg-9 col-md-8 col-sm-7 component-desc"> ## <div class="col-lg-9 col-md-8 col-sm-7 component-desc">
## <div class="input-group"> ## <div class="input-group">
## <div class="input-group-prepend"> ## <div class="input-group-prepend">
## <span class="input-group-text"><span class="fas fa-list"></span></span> ## <span class="input-group-text"><span class="fas fa-list"></span></span>
## </div> ## </div>
## <select name="${providerID}_cat" id="${providerID}_cat" ## <select name="${providerID}_cat" id="${providerID}_cat"
## title="Provider category" ## title="Provider category"
## class="form-control"> ## class="form-control">
## % for i in providerObj.category_dict.keys(): ## % for i in providerObj.category_dict.keys():
## <option value="${providerObj.category_dict[i]}" ${('', 'selected')[providerObj.category_dict[i] == providerObj.cat]}>${i}</option> ## <option value="${providerObj.category_dict[i]}" ${('', 'selected')[providerObj.category_dict[i] == providerObj.cat]}>${i}</option>
## % endfor ## % endfor
## </select> ## </select>
## </div> ## </div>
## </div> ## </div>
## </div> ## </div>
## % endif ## % endif
% if 'subtitle' in providerObj.custom_settings and providerID == 'tntvillage': % if 'subtitle' in providerObj.custom_settings and providerID == 'tntvillage':
<div class="form-row form-group"> <div class="form-row form-group">
...@@ -1029,7 +1009,9 @@ ...@@ -1029,7 +1009,9 @@
style="min-width:10em;"></select> style="min-width:10em;"></select>
<p> <p>
${_('(select your Newznab categories on the left, and click the "update ' ${_('(select your Newznab categories on the left, and click the "update '
'categories" button to use them for searching.)')}<br/> 'categories" button to add them)')}<br/>
${_('(select your Newznab categories on the right, and click the "update '
'categories" button to remove them)')}<br/>
<b>${_('Don\'t forget to save changes!')}</b> <b>${_('Don\'t forget to save changes!')}</b>
</p> </p>
</div> </div>
......
...@@ -5141,6 +5141,7 @@ $(document).ready(function ($) { ...@@ -5141,6 +5141,7 @@ $(document).ready(function ($) {
if (isDefault !== 'true') { if (isDefault !== 'true') {
$('#editANewznabProvider').append($("<option></option>").attr("value", id).text(name)); $('#editANewznabProvider').append($("<option></option>").attr("value", id).text(name));
$('#editANewznabProvider').val(id);
SICKRAGE.config.providers.populateNewznabSection(); SICKRAGE.config.providers.populateNewznabSection();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment