refactored Movie model to Media
This commit is contained in:
@@ -5,7 +5,7 @@ from couchpotato.core.helpers.encoding import simplifyString, toUnicode
|
||||
from couchpotato.core.helpers.variable import md5, getTitle
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.media._base.searcher.base import SearcherBase
|
||||
from couchpotato.core.settings.model import Movie, Release, ReleaseInfo
|
||||
from couchpotato.core.settings.model import Media, Release, ReleaseInfo
|
||||
from couchpotato.environment import Env
|
||||
from inspect import ismethod, isfunction
|
||||
import datetime
|
||||
@@ -110,7 +110,7 @@ class Searcher(SearcherBase):
|
||||
db.commit()
|
||||
|
||||
# Mark movie done
|
||||
mvie = db.query(Movie).filter_by(id = movie['id']).first()
|
||||
mvie = db.query(Media).filter_by(id = movie['id']).first()
|
||||
mvie.status_id = done_status.get('id')
|
||||
mvie.last_edit = int(time.time())
|
||||
db.commit()
|
||||
|
||||
@@ -5,7 +5,7 @@ from couchpotato.core.helpers.encoding import toUnicode, simplifyString
|
||||
from couchpotato.core.helpers.variable import getImdb, splitString, tryInt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.media.movie import MovieTypeBase
|
||||
from couchpotato.core.settings.model import Library, LibraryTitle, Movie, \
|
||||
from couchpotato.core.settings.model import Library, LibraryTitle, Media, \
|
||||
Release
|
||||
from couchpotato.environment import Env
|
||||
from sqlalchemy.orm import joinedload_all
|
||||
@@ -118,8 +118,8 @@ class MovieBase(MovieTypeBase):
|
||||
db = get_session()
|
||||
|
||||
# get movies last_edit more than a week ago
|
||||
movies = db.query(Movie) \
|
||||
.filter(Movie.status_id == done_status.get('id'), Movie.last_edit < (now - week)) \
|
||||
movies = db.query(Media) \
|
||||
.filter(Media.status_id == done_status.get('id'), Media.last_edit < (now - week)) \
|
||||
.all()
|
||||
|
||||
for movie in movies:
|
||||
@@ -145,9 +145,9 @@ class MovieBase(MovieTypeBase):
|
||||
imdb_id = getImdb(str(movie_id))
|
||||
|
||||
if(imdb_id):
|
||||
m = db.query(Movie).filter(Movie.library.has(identifier = imdb_id)).first()
|
||||
m = db.query(Media).filter(Media.library.has(identifier = imdb_id)).first()
|
||||
else:
|
||||
m = db.query(Movie).filter_by(id = movie_id).first()
|
||||
m = db.query(Media).filter_by(id = movie_id).first()
|
||||
|
||||
results = None
|
||||
if m:
|
||||
@@ -166,14 +166,14 @@ class MovieBase(MovieTypeBase):
|
||||
if release_status and not isinstance(release_status, (list, tuple)):
|
||||
release_status = [release_status]
|
||||
|
||||
q = db.query(Movie) \
|
||||
.outerjoin(Movie.releases, Movie.library, Library.titles) \
|
||||
q = db.query(Media) \
|
||||
.outerjoin(Media.releases, Media.library, Library.titles) \
|
||||
.filter(LibraryTitle.default == True) \
|
||||
.group_by(Movie.id)
|
||||
.group_by(Media.id)
|
||||
|
||||
# Filter on movie status
|
||||
if status and len(status) > 0:
|
||||
q = q.filter(or_(*[Movie.status.has(identifier = s) for s in status]))
|
||||
q = q.filter(or_(*[Media.status.has(identifier = s) for s in status]))
|
||||
|
||||
# Filter on release status
|
||||
if release_status and len(release_status) > 0:
|
||||
@@ -204,7 +204,7 @@ class MovieBase(MovieTypeBase):
|
||||
q = q.order_by(asc(LibraryTitle.simple_title))
|
||||
|
||||
q = q.subquery()
|
||||
q2 = db.query(Movie).join((q, q.c.id == Movie.id)) \
|
||||
q2 = db.query(Media).join((q, q.c.id == Media.id)) \
|
||||
.options(joinedload_all('releases.files')) \
|
||||
.options(joinedload_all('releases.info')) \
|
||||
.options(joinedload_all('profile.types')) \
|
||||
@@ -244,13 +244,13 @@ class MovieBase(MovieTypeBase):
|
||||
if release_status and not isinstance(release_status, (list, tuple)):
|
||||
release_status = [release_status]
|
||||
|
||||
q = db.query(Movie) \
|
||||
.outerjoin(Movie.releases, Movie.library, Library.titles, Movie.status) \
|
||||
q = db.query(Media) \
|
||||
.outerjoin(Media.releases, Media.library, Library.titles, Media.status) \
|
||||
.options(joinedload_all('library.titles'))
|
||||
|
||||
# Filter on movie status
|
||||
if status and len(status) > 0:
|
||||
q = q.filter(or_(*[Movie.status.has(identifier = s) for s in status]))
|
||||
q = q.filter(or_(*[Media.status.has(identifier = s) for s in status]))
|
||||
|
||||
# Filter on release status
|
||||
if release_status and len(release_status) > 0:
|
||||
@@ -310,7 +310,7 @@ class MovieBase(MovieTypeBase):
|
||||
db = get_session()
|
||||
|
||||
for x in splitString(id):
|
||||
movie = db.query(Movie).filter_by(id = x).first()
|
||||
movie = db.query(Media).filter_by(id = x).first()
|
||||
|
||||
if movie:
|
||||
|
||||
@@ -374,11 +374,11 @@ class MovieBase(MovieTypeBase):
|
||||
cat_id = params.get('category_id', None)
|
||||
|
||||
db = get_session()
|
||||
m = db.query(Movie).filter_by(library_id = library.get('id')).first()
|
||||
m = db.query(Media).filter_by(library_id = library.get('id')).first()
|
||||
added = True
|
||||
do_search = False
|
||||
if not m:
|
||||
m = Movie(
|
||||
m = Media(
|
||||
library_id = library.get('id'),
|
||||
profile_id = params.get('profile_id', default_profile.get('id')),
|
||||
status_id = status_id if status_id else status_active.get('id'),
|
||||
@@ -455,7 +455,7 @@ class MovieBase(MovieTypeBase):
|
||||
ids = splitString(id)
|
||||
for movie_id in ids:
|
||||
|
||||
m = db.query(Movie).filter_by(id = movie_id).first()
|
||||
m = db.query(Media).filter_by(id = movie_id).first()
|
||||
if not m:
|
||||
continue
|
||||
|
||||
@@ -502,7 +502,7 @@ class MovieBase(MovieTypeBase):
|
||||
|
||||
db = get_session()
|
||||
|
||||
movie = db.query(Movie).filter_by(id = movie_id).first()
|
||||
movie = db.query(Media).filter_by(id = movie_id).first()
|
||||
if movie:
|
||||
deleted = False
|
||||
if delete_from == 'all':
|
||||
@@ -552,7 +552,7 @@ class MovieBase(MovieTypeBase):
|
||||
|
||||
db = get_session()
|
||||
|
||||
m = db.query(Movie).filter_by(id = movie_id).first()
|
||||
m = db.query(Media).filter_by(id = movie_id).first()
|
||||
if not m or len(m.library.titles) == 0:
|
||||
log.debug('Can\'t restatus movie, doesn\'t seem to exist.')
|
||||
return False
|
||||
@@ -578,7 +578,7 @@ class MovieBase(MovieTypeBase):
|
||||
|
||||
def onComplete():
|
||||
db = get_session()
|
||||
movie = db.query(Movie).filter_by(id = movie_id).first()
|
||||
movie = db.query(Media).filter_by(id = movie_id).first()
|
||||
fireEventAsync('movie.searcher.single', movie.to_dict(self.default_dict), on_complete = self.createNotifyFront(movie_id))
|
||||
db.expire_all()
|
||||
|
||||
@@ -589,7 +589,7 @@ class MovieBase(MovieTypeBase):
|
||||
|
||||
def notifyFront():
|
||||
db = get_session()
|
||||
movie = db.query(Movie).filter_by(id = movie_id).first()
|
||||
movie = db.query(Media).filter_by(id = movie_id).first()
|
||||
fireEvent('notify.frontend', type = 'movie.update.%s' % movie.id, data = movie.to_dict(self.default_dict))
|
||||
db.expire_all()
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from couchpotato.core.helpers.variable import md5, getTitle, splitString, \
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.media._base.searcher.base import SearcherBase
|
||||
from couchpotato.core.media.movie import MovieTypeBase
|
||||
from couchpotato.core.settings.model import Movie, Release, ReleaseInfo
|
||||
from couchpotato.core.settings.model import Media, Release, ReleaseInfo
|
||||
from couchpotato.environment import Env
|
||||
from datetime import date
|
||||
from sqlalchemy.exc import InterfaceError
|
||||
@@ -74,8 +74,8 @@ class MovieSearcher(SearcherBase, MovieTypeBase):
|
||||
|
||||
db = get_session()
|
||||
|
||||
movies = db.query(Movie).filter(
|
||||
Movie.status.has(identifier = 'active')
|
||||
movies = db.query(Media).filter(
|
||||
Media.status.has(identifier = 'active')
|
||||
).all()
|
||||
random.shuffle(movies)
|
||||
|
||||
@@ -182,7 +182,7 @@ class MovieSearcher(SearcherBase, MovieTypeBase):
|
||||
sorted_results = sorted(sorted_results, key = lambda k: k['type'][:3], reverse = (download_preference == 'torrent'))
|
||||
|
||||
# Check if movie isn't deleted while searching
|
||||
if not db.query(Movie).filter_by(id = movie.get('id')).first():
|
||||
if not db.query(Media).filter_by(id = movie.get('id')).first():
|
||||
break
|
||||
|
||||
# Add them to this movie releases list
|
||||
|
||||
@@ -5,7 +5,7 @@ from couchpotato.core.helpers.encoding import toUnicode, simplifyString
|
||||
from couchpotato.core.helpers.variable import getImdb, splitString, tryInt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.media import MediaBase
|
||||
from couchpotato.core.settings.model import Library, LibraryTitle, Movie, \
|
||||
from couchpotato.core.settings.model import Library, LibraryTitle, Media, \
|
||||
Release
|
||||
from couchpotato.environment import Env
|
||||
from sqlalchemy.orm import joinedload_all
|
||||
@@ -190,11 +190,11 @@ class ShowBase(MediaBase):
|
||||
cat_id = params.get('category_id', None)
|
||||
|
||||
db = get_session()
|
||||
m = db.query(Movie).filter_by(library_id = library.get('id')).first()
|
||||
m = db.query(Media).filter_by(library_id = library.get('id')).first()
|
||||
added = True
|
||||
do_search = False
|
||||
if not m:
|
||||
m = Movie(
|
||||
m = Media(
|
||||
type = type,
|
||||
library_id = library.get('id'),
|
||||
profile_id = params.get('profile_id', default_profile.get('id')),
|
||||
@@ -256,7 +256,7 @@ class ShowBase(MediaBase):
|
||||
|
||||
def onComplete():
|
||||
db = get_session()
|
||||
show = db.query(Movie).filter_by(id = show_id).first()
|
||||
show = db.query(Media).filter_by(id = show_id).first()
|
||||
fireEventAsync('show.searcher.single', show.to_dict(self.default_dict), on_complete = self.createNotifyFront(show_id))
|
||||
db.expire_all()
|
||||
|
||||
@@ -266,7 +266,7 @@ class ShowBase(MediaBase):
|
||||
|
||||
def notifyFront():
|
||||
db = get_session()
|
||||
show = db.query(Movie).filter_by(id = show_id).first()
|
||||
show = db.query(Media).filter_by(id = show_id).first()
|
||||
fireEvent('notify.frontend', type = 'show.update.%s' % show.id, data = show.to_dict(self.default_dict))
|
||||
db.expire_all()
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Movie, Category
|
||||
from couchpotato.core.settings.model import Media, Category
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -114,7 +114,7 @@ class CategoryPlugin(Plugin):
|
||||
def removeFromMovie(self, category_id):
|
||||
|
||||
db = get_session()
|
||||
movies = db.query(Movie).filter(Movie.category_id == category_id).all()
|
||||
movies = db.query(Media).filter(Media.category_id == category_id).all()
|
||||
|
||||
if len(movies) > 0:
|
||||
for movie in movies:
|
||||
|
||||
@@ -4,7 +4,7 @@ from couchpotato.core.event import fireEvent
|
||||
from couchpotato.core.helpers.variable import splitString, tryInt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Movie
|
||||
from couchpotato.core.settings.model import Media
|
||||
from sqlalchemy.orm import joinedload_all
|
||||
import random as rndm
|
||||
import time
|
||||
@@ -42,9 +42,9 @@ class Dashboard(Plugin):
|
||||
|
||||
# Get all active movies
|
||||
active_status, snatched_status, downloaded_status, available_status = fireEvent('status.get', ['active', 'snatched', 'downloaded', 'available'], single = True)
|
||||
subq = db.query(Movie).filter(Movie.status_id == active_status.get('id')).subquery()
|
||||
subq = db.query(Media).filter(Media.status_id == active_status.get('id')).subquery()
|
||||
|
||||
q = db.query(Movie).join((subq, subq.c.id == Movie.id)) \
|
||||
q = db.query(Media).join((subq, subq.c.id == Media.id)) \
|
||||
.options(joinedload_all('releases')) \
|
||||
.options(joinedload_all('profile')) \
|
||||
.options(joinedload_all('library.titles')) \
|
||||
|
||||
@@ -4,7 +4,7 @@ from couchpotato.core.event import addEvent, fireEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Profile, ProfileType, Movie
|
||||
from couchpotato.core.settings.model import Profile, ProfileType, Media
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -37,7 +37,7 @@ class ProfilePlugin(Plugin):
|
||||
active_status = fireEvent('status.get', 'active', single = True)
|
||||
|
||||
db = get_session()
|
||||
movies = db.query(Movie).filter(Movie.status_id == active_status.get('id'), Movie.profile == None).all()
|
||||
movies = db.query(Media).filter(Media.status_id == active_status.get('id'), Media.profile == None).all()
|
||||
|
||||
if len(movies) > 0:
|
||||
default_profile = self.default()
|
||||
|
||||
@@ -5,7 +5,7 @@ from couchpotato.core.helpers.encoding import ss
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.plugins.scanner.main import Scanner
|
||||
from couchpotato.core.settings.model import File, Release as Relea, Movie
|
||||
from couchpotato.core.settings.model import File, Release as Relea, Media
|
||||
from sqlalchemy.sql.expression import and_, or_
|
||||
import os
|
||||
|
||||
@@ -49,9 +49,9 @@ class Release(Plugin):
|
||||
done_status, snatched_status = fireEvent('status.get', ['done', 'snatched'], single = True)
|
||||
|
||||
# Add movie
|
||||
movie = db.query(Movie).filter_by(library_id = group['library'].get('id')).first()
|
||||
movie = db.query(Media).filter_by(library_id = group['library'].get('id')).first()
|
||||
if not movie:
|
||||
movie = Movie(
|
||||
movie = Media(
|
||||
library_id = group['library'].get('id'),
|
||||
profile_id = 0,
|
||||
status_id = done_status.get('id')
|
||||
|
||||
@@ -166,7 +166,7 @@ class Renamer(Plugin):
|
||||
|
||||
# Overwrite destination when set in category
|
||||
destination = self.conf('to')
|
||||
for movie in library_ent.movies:
|
||||
for movie in library_ent.media:
|
||||
if movie.category and movie.category.destination and len(movie.category.destination) > 0:
|
||||
destination = movie.category.destination
|
||||
log.debug('Setting category destination for "%s": %s' % (movie_title, destination))
|
||||
@@ -330,13 +330,13 @@ class Renamer(Plugin):
|
||||
remove_leftovers = True
|
||||
|
||||
# Add it to the wanted list before we continue
|
||||
if len(library_ent.movies) == 0:
|
||||
if len(library_ent.media) == 0:
|
||||
profile = db.query(Profile).filter_by(core = True, label = group['meta_data']['quality']['label']).first()
|
||||
fireEvent('movie.add', params = {'identifier': group['library']['identifier'], 'profile_id': profile.id}, search_after = False)
|
||||
db.expire_all()
|
||||
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||
|
||||
for movie in library_ent.movies:
|
||||
for movie in library_ent.media:
|
||||
|
||||
# Mark movie "done" once it's found the quality with the finish check
|
||||
try:
|
||||
|
||||
@@ -4,7 +4,7 @@ from couchpotato.core.helpers.encoding import toUnicode, simplifyString, ss
|
||||
from couchpotato.core.helpers.variable import getExt, getImdb, tryInt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import File, Movie
|
||||
from couchpotato.core.settings.model import File, Media
|
||||
from enzyme.exceptions import NoParserError, ParseError
|
||||
from guessit import guess_movie_info
|
||||
from subliminal.videos import Video
|
||||
@@ -404,7 +404,7 @@ class Scanner(Plugin):
|
||||
if not group['library']:
|
||||
log.error('Unable to determine movie: %s', group['identifiers'])
|
||||
else:
|
||||
movie = db.query(Movie).filter_by(library_id = group['library']['id']).first()
|
||||
movie = db.query(Media).filter_by(library_id = group['library']['id']).first()
|
||||
group['movie_id'] = None if not movie else movie.id
|
||||
|
||||
processed_movies[identifier] = group
|
||||
|
||||
@@ -27,7 +27,7 @@ class Subtitle(Plugin):
|
||||
library = db.query(Library).all()
|
||||
done_status = fireEvent('status.get', 'done', single = True)
|
||||
|
||||
for movie in library.movies:
|
||||
for movie in library.media:
|
||||
|
||||
for release in movie.releases:
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from couchpotato.core.event import fireEvent
|
||||
from couchpotato.core.helpers.encoding import ss
|
||||
from couchpotato.core.helpers.variable import splitString, md5
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Movie
|
||||
from couchpotato.core.settings.model import Media
|
||||
from couchpotato.environment import Env
|
||||
from sqlalchemy.sql.expression import or_
|
||||
|
||||
@@ -23,8 +23,8 @@ class Suggestion(Plugin):
|
||||
|
||||
if not movies or len(movies) == 0:
|
||||
db = get_session()
|
||||
active_movies = db.query(Movie) \
|
||||
.filter(or_(*[Movie.status.has(identifier = s) for s in ['active', 'done']])).all()
|
||||
active_movies = db.query(Media) \
|
||||
.filter(or_(*[Media.status.has(identifier = s) for s in ['active', 'done']])).all()
|
||||
movies = [x.library.identifier for x in active_movies]
|
||||
|
||||
if not ignored or len(ignored) == 0:
|
||||
@@ -76,8 +76,8 @@ class Suggestion(Plugin):
|
||||
if len(new_suggestions) - 1 < limit:
|
||||
|
||||
db = get_session()
|
||||
active_movies = db.query(Movie) \
|
||||
.filter(or_(*[Movie.status.has(identifier = s) for s in ['active', 'done']])).all()
|
||||
active_movies = db.query(Media) \
|
||||
.filter(or_(*[Media.status.has(identifier = s) for s in ['active', 'done']])).all()
|
||||
movies = [x.library.identifier for x in active_movies]
|
||||
|
||||
ignored.extend([x.get('imdb') for x in cached_suggestion])
|
||||
|
||||
@@ -73,7 +73,7 @@ class MovieResultModifier(Plugin):
|
||||
# Statuses
|
||||
active_status, done_status = fireEvent('status.get', ['active', 'done'], single = True)
|
||||
|
||||
for movie in l.movies:
|
||||
for movie in l.media:
|
||||
if movie.status_id == active_status['id']:
|
||||
temp['in_wanted'] = fireEvent('movie.get', movie.id, single = True)
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class ShowResultModifier(Plugin):
|
||||
# Statuses
|
||||
active_status, done_status = fireEvent('status.get', ['active', 'done'], single = True)
|
||||
|
||||
for movie in l.movies:
|
||||
for movie in l.media:
|
||||
if movie.status_id == active_status['id']:
|
||||
temp['in_wanted'] = fireEvent('movie.get', movie.id, single = True)
|
||||
|
||||
|
||||
@@ -74,9 +74,9 @@ class MutableDict(Mutable, dict):
|
||||
MutableDict.associate_with(JsonType)
|
||||
|
||||
|
||||
class Movie(Entity):
|
||||
"""Movie Resource a movie could have multiple releases
|
||||
The files belonging to the movie object are global for the whole movie
|
||||
class Media(Entity):
|
||||
"""Media Resource could have multiple releases
|
||||
The files belonging to the media object are global for the whole media
|
||||
such as trailers, nfo, thumbnails"""
|
||||
|
||||
type = Field(String(10), default = "movie", index = True)
|
||||
@@ -105,7 +105,7 @@ class Library(Entity):
|
||||
info = Field(JsonType)
|
||||
|
||||
status = ManyToOne('Status')
|
||||
movies = OneToMany('Movie', cascade = 'all, delete-orphan')
|
||||
media = OneToMany('Media', cascade = 'all, delete-orphan')
|
||||
titles = OneToMany('LibraryTitle', cascade = 'all, delete-orphan')
|
||||
files = ManyToMany('File', cascade = 'all, delete-orphan', single_parent = True)
|
||||
|
||||
@@ -220,7 +220,7 @@ class Release(Entity):
|
||||
last_edit = Field(Integer, default = lambda: int(time.time()), index = True)
|
||||
identifier = Field(String(100), index = True)
|
||||
|
||||
movie = ManyToOne('Movie')
|
||||
media = ManyToOne('Media')
|
||||
status = ManyToOne('Status')
|
||||
quality = ManyToOne('Quality')
|
||||
files = ManyToMany('File')
|
||||
@@ -285,7 +285,7 @@ class Profile(Entity):
|
||||
core = Field(Boolean, default = False)
|
||||
hide = Field(Boolean, default = False)
|
||||
|
||||
movie = OneToMany('Movie')
|
||||
media = OneToMany('Media')
|
||||
types = OneToMany('ProfileType', cascade = 'all, delete-orphan')
|
||||
|
||||
def to_dict(self, deep = {}, exclude = []):
|
||||
@@ -306,7 +306,7 @@ class Category(Entity):
|
||||
ignored = Field(Unicode(255))
|
||||
destination = Field(Unicode(255))
|
||||
|
||||
movie = OneToMany('Movie')
|
||||
media = OneToMany('Media')
|
||||
destination = Field(Unicode(255))
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ class File(Entity):
|
||||
properties = OneToMany('FileProperty')
|
||||
|
||||
history = OneToMany('RenameHistory')
|
||||
movie = ManyToMany('Movie')
|
||||
media = ManyToMany('Media')
|
||||
release = ManyToMany('Release')
|
||||
library = ManyToMany('Library')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user