Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SiCKRAGE
sickrage
Commits
4323d844
Commit
4323d844
authored
Dec 10, 2017
by
echel0n
Browse files
Refactored database calls, resolves memory usage issues
parent
0d8b4d1e
Changes
32
Hide whitespace changes
Inline
Side-by-side
changelog.md
View file @
4323d844
# Changelog
-
*
3ceb533 - 2017-12-10: Small memory footprint improvement
-
*
84cd66d - 2017-12-10: Refactored database calls, resolves memory usage issues
-
*
0d8b4d1 - 2017-12-10: Small memory footprint improvement
-
*
f2d7dc6 - 2017-12-10: Release v9.2.61
-
*
656a038 - 2017-12-10: Overall stats now only displayed for main shows page, helps reduce overhead
-
*
75fa296 - 2017-12-10: Release v9.2.57
...
...
sickrage/core/__init__.py
View file @
4323d844
...
...
@@ -532,7 +532,7 @@ class Core(object):
Populates the showlist with shows from the database
"""
for
dbData
in
[
x
[
'doc'
]
for
x
in
self
.
main_db
.
db
.
all
(
'tv_shows'
,
with_doc
=
True
)]
:
for
dbData
in
self
.
main_db
.
all
(
'tv_shows'
)
:
try
:
self
.
log
.
debug
(
"Loading data for show: [{}]"
.
format
(
dbData
[
'show_name'
]))
self
.
showlist
+=
[
TVShow
(
int
(
dbData
[
'indexer'
]),
int
(
dbData
[
'indexer_id'
]))]
...
...
sickrage/core/blackandwhitelist.py
View file @
4323d844
...
...
@@ -20,9 +20,9 @@
from
__future__
import
unicode_literals
from
CodernityDB.database
import
RecordNotFound
from
adba.aniDBerrors
import
AniDBCommandTimeoutError
import
sickrage
from
adba.aniDBerrors
import
AniDBCommandTimeoutError
class
BlackAndWhiteList
(
object
):
...
...
@@ -98,9 +98,7 @@ class BlackAndWhiteList(object):
:return: keywords in list
"""
groups
=
[]
for
result
in
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
table
,
self
.
show_id
,
with_doc
=
True
)]:
groups
.
append
(
result
[
'keyword'
])
groups
=
[
x
[
'keyword'
]
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
table
,
self
.
show_id
)]
sickrage
.
app
.
log
.
debug
(
'BWL: '
+
str
(
self
.
show_id
)
+
' loaded keywords from '
+
table
+
': '
+
str
(
groups
))
...
...
sickrage/core/caches/name_cache.py
View file @
4323d844
...
...
@@ -55,8 +55,8 @@ class NameCache(object):
self
.
cache
[
name
]
=
int
(
indexer_id
)
try
:
if
not
len
([
x
[
'doc'
]
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'scene_names'
,
name
,
with_doc
=
True
)
if
x
[
'doc'
]
[
'indexer_id'
]
==
indexer_id
]):
if
not
len
([
x
for
x
in
sickrage
.
app
.
cache_db
.
get_many
(
'scene_names'
,
name
)
if
x
[
'indexer_id'
]
==
indexer_id
]):
# insert name into cache
sickrage
.
app
.
cache_db
.
db
.
insert
({
'_t'
:
'scene_names'
,
...
...
@@ -86,23 +86,22 @@ class NameCache(object):
"""
Deletes all "unknown" entries from the cache (names with indexer_id of 0).
"""
[
sickrage
.
app
.
cache_db
.
db
.
delete
(
x
[
'doc'
]
)
for
x
in
sickrage
.
app
.
cache_db
.
db
.
all
(
'scene_names'
,
with_doc
=
True
)
if
x
[
'
doc'
][
'
indexer_id'
]
in
[
indexerid
,
0
]]
[
sickrage
.
app
.
cache_db
.
db
.
delete
(
x
)
for
x
in
sickrage
.
app
.
cache_db
.
all
(
'scene_names'
)
if
x
[
'indexer_id'
]
in
[
indexerid
,
0
]]
for
item
in
[
self
.
cache
[
key
]
for
key
,
value
in
self
.
cache
.
items
()
if
value
==
0
or
value
==
indexerid
]:
del
item
def
load
(
self
):
self
.
cache
=
dict
([(
x
[
'doc'
][
'name'
],
x
[
'doc'
][
'indexer_id'
])
for
x
in
sickrage
.
app
.
cache_db
.
db
.
all
(
'scene_names'
,
with_doc
=
True
)])
self
.
cache
=
dict
([(
x
[
'name'
],
x
[
'indexer_id'
])
for
x
in
sickrage
.
app
.
cache_db
.
all
(
'scene_names'
)])
def
save
(
self
):
"""Commit cache to database file"""
for
name
,
indexer_id
in
self
.
cache
.
items
():
try
:
if
len
([
x
[
'doc'
]
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'scene_names'
,
name
,
with_doc
=
True
)
if
x
[
'doc'
]
[
'indexer_id'
]
==
indexer_id
]):
if
len
([
x
for
x
in
sickrage
.
app
.
cache_db
.
get_many
(
'scene_names'
,
name
)
if
x
[
'indexer_id'
]
==
indexer_id
]):
continue
except
RecordNotFound
:
pass
...
...
sickrage/core/caches/tv_cache.py
View file @
4323d844
...
...
@@ -41,8 +41,8 @@ class TVCache(object):
def
clear
(
self
):
if
self
.
shouldClearCache
():
[
sickrage
.
app
.
cache_db
.
db
.
delete
(
x
[
'doc'
]
)
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'providers'
,
self
.
providerID
,
with_doc
=
True
)]
[
sickrage
.
app
.
cache_db
.
db
.
delete
(
x
)
for
x
in
sickrage
.
app
.
cache_db
.
get_many
(
'providers'
,
self
.
providerID
)]
def
_get_title_and_url
(
self
,
item
):
return
self
.
provider
.
_get_title_and_url
(
item
)
...
...
@@ -181,8 +181,8 @@ class TVCache(object):
def
addCacheEntry
(
self
,
name
,
url
,
seeders
,
leechers
,
size
):
# check for existing entry in cache
if
len
([
x
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'providers'
,
self
.
providerID
,
with_doc
=
True
)
if
x
[
'doc'
]
[
'url'
]
==
url
]):
return
if
len
([
x
for
x
in
sickrage
.
app
.
cache_db
.
get_many
(
'providers'
,
self
.
providerID
)
if
x
[
'url'
]
==
url
]):
return
try
:
# parse release name
...
...
@@ -247,8 +247,9 @@ class TVCache(object):
pass
# get data from internal database
dbData
+=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'providers'
,
self
.
providerID
,
with_doc
=
True
)]
dbData
+=
[
x
for
x
in
sickrage
.
app
.
cache_db
.
get_many
(
'providers'
,
self
.
providerID
)]
# sort data by criteria
dbData
=
[
x
for
x
in
dbData
if
x
[
'indexerid'
]
==
ep_obj
.
show
.
indexerid
and
x
[
'season'
]
==
ep_obj
.
season
and
"|"
+
str
(
ep_obj
.
episode
)
+
"|"
in
x
[
'episodes'
]]
if
ep_obj
else
dbData
...
...
sickrage/core/databases/__init__.py
View file @
4323d844
...
...
@@ -293,6 +293,11 @@ class srDatabase(object):
if
os
.
path
.
isfile
(
self
.
old_db_path
+
'-shm'
):
os
.
rename
(
self
.
old_db_path
+
'-shm'
,
'{}-shm.{}_old'
.
format
(
self
.
old_db_path
,
random
))
def
all
(
self
,
*
args
):
return
(
x
[
'doc'
]
for
x
in
self
.
db
.
all
(
*
args
,
with_doc
=
True
))
def
get_many
(
self
,
*
args
):
return
(
x
[
'doc'
]
for
x
in
self
.
db
.
get_many
(
*
args
,
with_doc
=
True
))
# Monkey-Patch storage to suppress logging messages
IU_Storage
.
get
=
Custom_IU_Storage_get
sickrage/core/databases/cache/__init__.py
View file @
4323d844
...
...
@@ -53,6 +53,6 @@ class CacheDB(srDatabase):
def
check_versions
(
self
,
index_name
,
current_version
,
previous_version
):
# Wipe table if versions are different
if
previous_version
<
current_version
:
for
x
in
self
.
db
.
all
(
index_name
,
with_doc
=
True
):
self
.
db
.
delete
(
x
[
'doc'
]
)
for
x
in
self
.
all
(
index_name
):
self
.
db
.
delete
(
x
)
super
(
CacheDB
,
self
).
check_versions
(
index_name
,
current_version
,
previous_version
)
sickrage/core/databases/failed/__init__.py
View file @
4323d844
...
...
@@ -43,6 +43,6 @@ class FailedDB(srDatabase):
def
check_versions
(
self
,
index_name
,
current_version
,
previous_version
):
# Wipe table if versions are different
if
previous_version
<
current_version
:
for
x
in
self
.
db
.
all
(
index_name
,
with_doc
=
True
):
self
.
db
.
delete
(
x
[
'doc'
]
)
for
x
in
self
.
all
(
index_name
):
self
.
db
.
delete
(
x
)
super
(
FailedDB
,
self
).
check_versions
(
index_name
,
current_version
,
previous_version
)
\ No newline at end of file
sickrage/core/databases/main/__init__.py
View file @
4323d844
...
...
@@ -77,7 +77,7 @@ class MainDB(srDatabase):
def
fix_show_none_types
(
self
):
checked
=
[]
for
show
in
[
x
[
'doc'
]
for
x
in
self
.
db
.
all
(
'tv_shows'
,
with_doc
=
True
)]
:
for
show
in
self
.
all
(
'tv_shows'
)
:
if
show
[
'indexer_id'
]
in
checked
:
continue
...
...
@@ -95,10 +95,12 @@ class MainDB(srDatabase):
checked
+=
[
show
[
'indexer_id'
]]
del
checked
def
fix_episode_none_types
(
self
):
checked
=
[]
for
ep
in
[
x
[
'doc'
]
for
x
in
self
.
db
.
all
(
'tv_episodes'
,
with_doc
=
True
)]
:
for
ep
in
self
.
all
(
'tv_episodes'
)
:
if
ep
[
'showid'
]
in
checked
:
continue
...
...
@@ -116,35 +118,41 @@ class MainDB(srDatabase):
checked
+=
[
ep
[
'showid'
]]
del
checked
def
fix_dupe_shows
(
self
):
checked
=
[]
for
show
in
[
x
[
'doc'
]
for
x
in
self
.
db
.
all
(
'tv_shows'
,
with_doc
=
True
)]
:
for
show
in
self
.
all
(
'tv_shows'
)
:
if
show
[
'indexer_id'
]
in
checked
:
continue
for
dupe
in
[
x
[
'doc'
]
for
x
in
self
.
db
.
get_many
(
'tv_shows'
,
show
[
'indexer_id'
]
,
with_doc
=
True
)]
[
1
::]:
for
dupe
in
list
(
self
.
get_many
(
'tv_shows'
,
show
[
'indexer_id'
]
))
[
1
::]:
sickrage
.
app
.
log
.
info
(
"Deleting duplicate show with id: {}"
.
format
(
dupe
[
"indexer_id"
]))
self
.
db
.
delete
(
dupe
)
checked
+=
[
show
[
'indexer_id'
]]
del
checked
def
fix_dupe_episodes
(
self
):
checked
=
[]
for
ep
in
[
x
[
'doc'
]
for
x
in
self
.
db
.
all
(
'tv_episodes'
,
with_doc
=
True
)]
:
for
ep
in
self
.
all
(
'tv_episodes'
)
:
if
ep
[
'showid'
]
in
checked
:
continue
for
dupe
in
[
x
[
'doc'
]
for
x
in
self
.
db
.
get_many
(
'tv_episodes'
,
ep
[
'showid'
]
,
with_doc
=
True
)
if
x
[
'doc'
]
[
'indexerid'
]
==
ep
[
'indexerid'
]
][
1
::]
:
sickrage
.
app
.
log
.
info
(
"Deleting duplicate episode with id: {}"
.
format
(
dupe
[
"indexerid"
]))
self
.
db
.
delete
(
dupe
)
for
dupe
in
list
(
self
.
get_many
(
'tv_episodes'
,
ep
[
'showid'
]
))[
1
::]:
if
dupe
[
'indexerid'
]
==
ep
[
'indexerid'
]:
sickrage
.
app
.
log
.
info
(
"Deleting duplicate episode with id: {}"
.
format
(
dupe
[
"indexerid"
]))
self
.
db
.
delete
(
dupe
)
checked
+=
[
ep
[
'showid'
]]
del
checked
def
fix_orphaned_episodes
(
self
):
for
ep
in
[
x
[
'doc'
]
for
x
in
self
.
db
.
all
(
'tv_episodes'
,
with_doc
=
True
)]
:
for
ep
in
self
.
all
(
'tv_episodes'
)
:
if
not
self
.
db
.
get
(
'tv_shows'
,
ep
[
'showid'
],
with_doc
=
True
)[
'doc'
]:
sickrage
.
app
.
log
.
info
(
"Deleting orphan episode with id: {}"
.
format
(
ep
[
"indexerid"
]))
self
.
db
.
delete
(
ep
)
sickrage/core/helpers/__init__.py
View file @
4323d844
...
...
@@ -1549,7 +1549,7 @@ def overall_stats():
'total_size'
:
0
}
for
result
in
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
all
(
'tv_episodes'
,
with_doc
=
True
)]
:
for
result
in
sickrage
.
app
.
main_db
.
all
(
'tv_episodes'
)
:
if
not
(
result
[
'season'
]
>
0
and
result
[
'episode'
]
>
0
and
result
[
'airdate'
]
>
1
):
continue
...
...
sickrage/core/helpers/show_names.py
View file @
4323d844
...
...
@@ -196,9 +196,8 @@ def makeSceneSeasonSearchString(show, ep_obj, extraSearchType=None):
seasonStrings
.
append
(
"%02d"
%
ab_number
)
else
:
numseasons
=
len
({
x
[
'doc'
][
'season'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
,
with_doc
=
True
)
if
x
[
'doc'
][
'season'
]
!=
0
})
numseasons
=
len
({
x
[
'season'
]
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
)
if
x
[
'season'
]
!=
0
})
seasonStrings
=
[
"S%02d"
%
int
(
ep_obj
.
scene_season
)]
...
...
@@ -230,9 +229,8 @@ def makeSceneSeasonSearchString(show, ep_obj, extraSearchType=None):
def
makeSceneSearchString
(
show
,
ep_obj
):
toReturn
=
[]
numseasons
=
len
(
{
x
[
'doc'
][
'season'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
,
with_doc
=
True
)
if
x
[
'doc'
][
'season'
]
!=
0
})
numseasons
=
len
({
x
[
'season'
]
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
)
if
x
[
'season'
]
!=
0
})
# see if we should use dates instead of episodes
if
(
show
.
air_by_date
or
show
.
sports
)
and
ep_obj
.
airdate
!=
date
.
fromordinal
(
1
):
...
...
sickrage/core/nameparser/__init__.py
View file @
4323d844
...
...
@@ -268,9 +268,8 @@ class NameParser(object):
if
bestResult
.
is_air_by_date
:
airdate
=
bestResult
.
air_date
.
toordinal
()
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'tv_episodes'
,
bestResult
.
show
.
indexerid
,
with_doc
=
True
)
if
x
[
'doc'
][
'indexer'
]
==
bestResult
.
show
.
indexer
and
x
[
'doc'
][
'airdate'
]
==
airdate
]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'tv_episodes'
,
bestResult
.
show
.
indexerid
)
if
x
[
'indexer'
]
==
bestResult
.
show
.
indexer
and
x
[
'airdate'
]
==
airdate
]
season_number
=
None
episode_numbers
=
[]
...
...
sickrage/core/process_tv.py
View file @
4323d844
...
...
@@ -50,6 +50,7 @@ class ProcessResult(object):
def
__str__
(
self
):
return
self
.
__unicode__
().
encode
(
'utf-8'
,
errors
=
'replace'
)
def
delete_folder
(
folder
,
check_empty
=
True
):
"""
Removes a folder from the filesystem
...
...
@@ -307,7 +308,7 @@ def validateDir(process_path, release_name, failed, result):
# make sure the dir isn't inside a show dir
for
show
in
sickrage
.
app
.
showlist
:
if
process_path
.
lower
().
startswith
(
os
.
path
.
realpath
(
show
.
location
).
lower
()
+
os
.
sep
)
or
\
process_path
.
lower
()
==
os
.
path
.
realpath
(
show
.
location
).
lower
():
process_path
.
lower
()
==
os
.
path
.
realpath
(
show
.
location
).
lower
():
result
.
output
+=
logHelper
(
"Cannot process an episode that's already been moved to its show dir, skipping "
+
process_path
,
sickrage
.
app
.
log
.
WARNING
)
...
...
@@ -447,12 +448,11 @@ def already_postprocessed(dirName, videofile, force, result):
return
False
# Avoid processing the same dir again if we use a process method <> move
if
[
x
for
x
in
sickrage
.
app
.
main_db
.
db
.
all
(
'tv_episodes'
,
with_doc
=
True
)
if
x
[
'doc'
][
'release_name'
]
==
dirName
]:
if
[
x
for
x
in
sickrage
.
app
.
main_db
.
all
(
'tv_episodes'
)
if
x
[
'release_name'
]
==
dirName
]:
return
True
else
:
if
[
x
for
x
in
sickrage
.
app
.
main_db
.
db
.
all
(
'tv_episodes'
,
with_doc
=
True
)
if
x
[
'doc'
][
'release_name'
]
==
[
videofile
.
rpartition
(
'.'
)[
0
]]]:
return
True
if
[
x
for
x
in
sickrage
.
app
.
main_db
.
all
(
'tv_episodes'
)
if
x
[
'release_name'
]
==
[
videofile
.
rpartition
(
'.'
)[
0
]]]:
return
True
# Needed if we have downloaded the same episode @ different quality
# But we need to make sure we check the history of the episode we're going to PP, and not others
...
...
@@ -462,19 +462,18 @@ def already_postprocessed(dirName, videofile, force, result):
except
:
parse_result
=
False
for
h
in
[
h
[
'doc'
]
for
h
in
sickrage
.
app
.
main_db
.
db
.
all
(
'history'
,
with_doc
=
True
)
if
h
[
'doc'
][
'resource'
].
endswith
(
videofile
)]:
for
e
in
[
e
[
'doc'
]
for
e
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'tv_episodes'
,
h
[
'showid'
],
with_doc
=
True
)
if
h
[
'season'
]
==
e
[
'doc'
][
'season'
]
and
h
[
'episode'
]
==
e
[
'doc'
][
'episode'
]
and
e
[
'doc'
][
'status'
]
in
Quality
.
DOWNLOADED
]:
for
h
in
(
h
for
h
in
sickrage
.
app
.
main_db
.
all
(
'history'
)
if
h
[
'resource'
].
endswith
(
videofile
)):
for
e
in
(
e
for
e
in
sickrage
.
app
.
main_db
.
get_many
(
'tv_episodes'
,
h
[
'showid'
])
if
h
[
'season'
]
==
e
[
'season'
]
and
h
[
'episode'
]
==
e
[
'episode'
]
and
e
[
'status'
]
in
Quality
.
DOWNLOADED
):
# If we find a showid, a season number, and one or more episode numbers then we need to use those in the query
if
parse_result
and
(
parse_result
.
indexerid
and
parse_result
.
episode_numbers
and
parse_result
.
season_number
):
if
e
[
'showid'
]
==
int
(
parse_result
.
indexerid
)
and
e
[
'season'
]
==
int
(
parse_result
.
season_number
and
e
[
'episode'
])
==
int
(
parse_result
.
episode_numbers
[
0
]):
if
parse_result
and
(
parse_result
.
indexerid
and
parse_result
.
episode_numbers
and
parse_result
.
season_number
):
if
e
[
'showid'
]
==
int
(
parse_result
.
indexerid
)
and
\
e
[
'season'
]
==
int
(
parse_result
.
season_number
and
e
[
'episode'
])
==
int
(
parse_result
.
episode_numbers
[
0
]):
return
True
else
:
return
True
...
...
sickrage/core/processors/post_processor.py
View file @
4323d844
...
...
@@ -523,9 +523,7 @@ class PostProcessor(object):
# search the database for a possible match and return immediately if we find one
for
curName
in
names
:
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
all
(
'history'
,
with_doc
=
True
)
if
curName
in
x
[
'doc'
][
'resource'
]]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
all
(
'history'
)
if
curName
in
x
[
'resource'
]]
if
len
(
dbData
)
==
0
:
continue
...
...
@@ -568,7 +566,7 @@ class PostProcessor(object):
# if the result is complete then remember that for later
# if the result is complete then set release name
if
parse_result
.
series_name
and
(
not
(
not
(
parse_result
.
season_number
is
not
None
and
parse_result
.
episode_numbers
)
and
not
parse_result
.
air_date
))
and
parse_result
.
release_group
:
parse_result
.
season_number
is
not
None
and
parse_result
.
episode_numbers
)
and
not
parse_result
.
air_date
))
and
parse_result
.
release_group
:
if
not
self
.
release_name
:
self
.
release_name
=
remove_non_release_groups
(
...
...
@@ -716,20 +714,16 @@ class PostProcessor(object):
airdate
=
episodes
[
0
].
toordinal
()
# Ignore season 0 when searching for episode(Conflict between special and regular episode, same air date)
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
,
with_doc
=
True
)
if
x
[
'doc'
][
'indexer'
]
==
show
.
indexer
and
x
[
'doc'
][
'airdate'
]
==
airdate
and
x
[
'doc'
][
'season'
]
!=
0
]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
)
if
x
[
'indexer'
]
==
show
.
indexer
and
x
[
'airdate'
]
==
airdate
and
x
[
'season'
]
!=
0
]
if
dbData
:
season
=
int
(
dbData
[
0
][
'season'
])
episodes
=
[
int
(
dbData
[
0
][
'episode'
])]
else
:
# Found no result, try with season 0
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
,
with_doc
=
True
)
if
x
[
'doc'
][
'indexer'
]
==
show
.
indexer
and
x
[
'doc'
][
'airdate'
]
==
airdate
]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
)
if
x
[
'indexer'
]
==
show
.
indexer
and
x
[
'airdate'
]
==
airdate
]
if
dbData
:
season
=
int
(
dbData
[
0
][
'season'
])
...
...
@@ -747,13 +741,11 @@ class PostProcessor(object):
# if there's no season then we can hopefully just use 1 automatically
elif
season
is
None
and
show
:
if
len
({
x
[
'doc'
][
'season'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
,
with_doc
=
True
)
if
x
[
'doc'
][
'season'
]
!=
0
and
x
[
'doc'
][
'indexer'
]
==
show
.
indexer
})
==
1
and
season
is
None
:
if
len
({
x
[
'season'
]
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'tv_episodes'
,
show
.
indexerid
)
if
x
[
'season'
]
!=
0
and
x
[
'indexer'
]
==
show
.
indexer
})
==
1
:
self
.
_log
(
"Don't have a season number, but this show appears to only have 1 season, setting "
"season number to 1..."
,
sickrage
.
app
.
log
.
DEBUG
)
season
=
1
self
.
_log
(
"Don't have a season number, but this show appears to only have 1 season, setting season number to 1..."
,
sickrage
.
app
.
log
.
DEBUG
)
if
show
and
season
and
episodes
:
return
show
,
season
,
episodes
,
quality
,
version
...
...
sickrage/core/scene_exceptions.py
View file @
4323d844
...
...
@@ -125,9 +125,8 @@ def retrieve_exceptions(get_xem=True, get_anidb=True):
if
not
len
(
cur_exception_dict
):
continue
try
:
existing_exceptions
=
[
x
[
'doc'
][
"show_name"
]
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'scene_exceptions'
,
cur_indexer_id
,
with_doc
=
True
)]
existing_exceptions
=
[
x
[
"show_name"
]
for
x
in
sickrage
.
app
.
cache_db
.
get_many
(
'scene_exceptions'
,
cur_indexer_id
)]
except
RecordNotFound
:
continue
...
...
@@ -161,10 +160,8 @@ def get_scene_exceptions(indexer_id, season=-1):
if
indexer_id
not
in
exceptionsCache
or
season
not
in
exceptionsCache
[
indexer_id
]:
try
:
exceptionsList
=
list
(
set
([
cur_exception
[
'show_name'
]
for
cur_exception
in
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'scene_exceptions'
,
indexer_id
,
with_doc
=
True
)]
exceptionsList
=
list
(
set
([
cur_exception
[
'show_name'
]
for
cur_exception
in
sickrage
.
app
.
cache_db
.
get_many
(
'scene_exceptions'
,
indexer_id
)
if
cur_exception
[
'season'
]
==
season
]))
if
not
indexer_id
in
exceptionsCache
:
...
...
@@ -191,8 +188,7 @@ def get_all_scene_exceptions(indexer_id):
"""
exceptionsDict
=
{}
for
cur_exception
in
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'scene_exceptions'
,
indexer_id
,
with_doc
=
True
)]:
for
cur_exception
in
sickrage
.
app
.
cache_db
.
get_many
(
'scene_exceptions'
,
indexer_id
):
if
not
cur_exception
[
'season'
]
in
exceptionsDict
:
exceptionsDict
[
cur_exception
[
'season'
]]
=
[]
exceptionsDict
[
cur_exception
[
'season'
]].
append
(
cur_exception
[
'show_name'
])
...
...
@@ -207,9 +203,8 @@ def get_scene_seasons(indexer_id):
exceptionsSeasonList
=
[]
if
indexer_id
not
in
exceptionsSeasonCache
:
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'scene_exceptions'
,
indexer_id
,
with_doc
=
True
)]
exceptionsSeasonList
=
list
(
set
([
int
(
x
[
'season'
])
for
x
in
dbData
]))
exceptionsSeasonList
=
list
(
set
([
int
(
x
[
'season'
])
for
x
in
sickrage
.
app
.
cache_db
.
get_many
(
'scene_exceptions'
,
indexer_id
)]))
if
not
indexer_id
in
exceptionsSeasonCache
:
exceptionsSeasonCache
[
indexer_id
]
=
{}
...
...
@@ -232,15 +227,13 @@ def get_scene_exception_by_name_multiple(show_name):
out
=
[]
dbData
=
sorted
([
x
[
'doc'
]
for
x
in
sickrage
.
app
.
cache_db
.
db
.
all
(
'scene_exceptions'
,
with_doc
=
True
)],
key
=
lambda
d
:
d
[
'season'
])
# try the obvious case first
exception_result
=
[
x
for
x
in
dbData
if
x
[
'show_name'
].
lower
()
==
show_name
.
lower
()]
exception_result
=
[
x
for
x
in
sorted
(
sickrage
.
app
.
cache_db
.
all
(
'scene_exceptions'
),
key
=
lambda
d
:
d
[
'season'
])
if
x
[
'show_name'
].
lower
()
==
show_name
.
lower
()]
if
exception_result
:
return
[(
int
(
x
[
'indexer_id'
]),
int
(
x
[
'season'
]))
for
x
in
exception_result
]
for
cur_exception
in
dbData
:
for
cur_exception
in
sorted
(
sickrage
.
app
.
cache_db
.
all
(
'scene_exceptions'
),
key
=
lambda
d
:
d
[
'season'
])
:
cur_exception_name
=
cur_exception
[
'show_name'
]
cur_indexer_id
=
int
(
cur_exception
[
'indexer_id'
])
cur_season
=
int
(
cur_exception
[
'season'
])
...
...
@@ -261,9 +254,8 @@ def update_scene_exceptions(indexer_id, scene_exceptions, season=-1):
"""
Given a indexer_id, and a list of all show scene exceptions, update the db.
"""
[
sickrage
.
app
.
cache_db
.
db
.
delete
(
x
[
'doc'
])
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'scene_exceptions'
,
indexer_id
,
with_doc
=
True
)
if
x
[
'doc'
][
'season'
]
==
season
]
[
sickrage
.
app
.
cache_db
.
db
.
delete
(
x
)
for
x
in
sickrage
.
app
.
cache_db
.
get_many
(
'scene_exceptions'
,
indexer_id
)
if
x
[
'season'
]
==
season
]
sickrage
.
app
.
log
.
info
(
"Updating scene exceptions"
)
...
...
@@ -345,8 +337,7 @@ def _xem_exceptions_fetcher():
def
getSceneSeasons
(
indexer_id
):
"""get a list of season numbers that have scene exceptions"""
return
[
x
[
'doc'
][
'season'
]
for
x
in
sickrage
.
app
.
cache_db
.
db
.
get_many
(
'scene_exceptions'
,
indexer_id
,
with_doc
=
True
)]
return
(
x
[
'season'
]
for
x
in
sickrage
.
app
.
cache_db
.
get_many
(
'scene_exceptions'
,
indexer_id
))
def
check_against_names
(
nameInQuestion
,
show
,
season
=-
1
):
...
...
sickrage/core/scene_numbering.py
View file @
4323d844
...
...
@@ -72,12 +72,12 @@ def find_scene_numbering(indexer_id, indexer, season, episode):
indexer_id
=
int
(
indexer_id
)
indexer
=
int
(
indexer
)
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'scene_numbering'
,
indexer_id
,
with_doc
=
True
)
if
x
[
'
doc'
][
'
indexer'
]
==
indexer
and
x
[
'
doc'
][
'
season'
]
==
season
and
x
[
'
doc'
][
'
episode'
]
==
episode
and
x
[
'
doc'
][
'
scene_season'
]
!=
0
and
x
[
'
doc'
][
'
scene_episode'
]
!=
0
]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'scene_numbering'
,
indexer_id
)
if
x
[
'indexer'
]
==
indexer
and
x
[
'season'
]
==
season
and
x
[
'episode'
]
==
episode
and
x
[
'scene_season'
]
!=
0
and
x
[
'scene_episode'
]
!=
0
]
if
dbData
:
return
try_int
(
dbData
[
0
].
get
(
"scene_season"
)),
try_int
(
dbData
[
0
].
get
(
"scene_episode"
))
...
...
@@ -126,10 +126,10 @@ def find_scene_absolute_numbering(indexer_id, indexer, absolute_number):
indexer_id
=
int
(
indexer_id
)
indexer
=
int
(
indexer
)
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'scene_numbering'
,
indexer_id
,
with_doc
=
True
)
if
x
[
'
doc'
][
'
indexer'
]
==
indexer
and
x
[
'
doc'
][
'
absolute_number'
]
==
absolute_number
and
x
[
'
doc'
][
'
scene_absolute_number'
]
!=
0
]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'scene_numbering'
,
indexer_id
)
if
x
[
'indexer'
]
==
indexer
and
x
[
'absolute_number'
]
==
absolute_number
and
x
[
'scene_absolute_number'
]
!=
0
]
if
dbData
:
return
try_int
(
dbData
[
0
].
get
(
'scene_absolute_number'
))
...
...
@@ -146,10 +146,10 @@ def get_indexer_numbering(indexer_id, indexer, sceneSeason, sceneEpisode, fallba
indexer_id
=
int
(
indexer_id
)
indexer
=
int
(
indexer
)
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'scene_numbering'
,
indexer_id
,
with_doc
=
True
)
if
x
[
'
doc'
][
'
indexer'
]
==
indexer
and
x
[
'
doc'
][
'
scene_season'
]
==
sceneSeason
and
x
[
'
doc'
][
'
scene_episode'
]
==
sceneEpisode
]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'scene_numbering'
,
indexer_id
)
if
x
[
'indexer'
]
==
indexer
and
x
[
'scene_season'
]
==
sceneSeason
and
x
[
'scene_episode'
]
==
sceneEpisode
]
if
dbData
:
return
try_int
(
dbData
[
0
].
get
(
"season"
)),
try_int
(
dbData
[
0
].
get
(
"episode"
))
...
...
@@ -171,14 +171,14 @@ def get_indexer_absolute_numbering(indexer_id, indexer, sceneAbsoluteNumber, fal
indexer
=
int
(
indexer
)
if
scene_season
is
None
:
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'scene_numbering'
,
indexer_id
,
with_doc
=
True
)
if
x
[
'
doc'
][
'
indexer'
]
==
indexer
and
x
[
'
doc'
][
'
scene_absolute_number'
]
==
sceneAbsoluteNumber
]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'scene_numbering'
,
indexer_id
)
if
x
[
'indexer'
]
==
indexer
and
x
[
'scene_absolute_number'
]
==
sceneAbsoluteNumber
]
else
:
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'scene_numbering'
,
indexer_id
,
with_doc
=
True
)
if
x
[
'
doc'
][
'
indexer'
]
==
indexer
and
x
[
'
doc'
][
'
scene_absolute_number'
]
==
sceneAbsoluteNumber
and
x
[
'
doc'
][
'
scene_season'
]
==
scene_season
]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'scene_numbering'
,
indexer_id
)
if
x
[
'indexer'
]
==
indexer
and
x
[
'scene_absolute_number'
]
==
sceneAbsoluteNumber
and
x
[
'scene_season'
]
==
scene_season
]
if
dbData
:
return
try_int
(
dbData
[
0
].
get
(
"absolute_number"
))
...
...
@@ -201,10 +201,10 @@ def set_scene_numbering(indexer_id, indexer, season=0, episode=0, absolute_numbe
indexer
=
int
(
indexer
)
if
season
and
episode
:
dbData
=
[
x
[
'doc'
]
for
x
in
sickrage
.
app
.
main_db
.
db
.
get_many
(
'scene_numbering'
,
indexer_id
,
with_doc
=
True
)
if
x
[
'
doc'
][
'
index'
]
==
indexer
and
x
[
'
doc'
][
'
season'
]
==
season
and
x
[
'
doc'
][
'
episode'
]
==
episode
]
dbData
=
[
x
for
x
in
sickrage
.
app
.
main_db
.
get_many
(
'scene_numbering'
,
indexer_id
)
if
x
[
'index'
]
==
indexer
and
x
[
'season'
]
==
season
and
x
[
'episode'
]
==
episode
]
if
len
(
dbData
):
dbData
[
0
][
'scene_season'
]
=
sceneSeason
...
...
@@ -224,9 +224,9 @@ def set_scene_numbering(indexer_id, indexer, season=0, episode=0, absolute_numbe
})
elif
absolute_number
: