aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <gueux@gueux.org>2013-01-07 19:38:51 +0100
committerFélix Sipma <gueux@gueux.org>2013-01-08 11:22:45 +0100
commit821314521018e9497ed068ea79e48df13c325f28 (patch)
tree5f9a98a13b63c05763a97fc8cf04f9cbc486f0eb
parent4f0d7fbcc175ad5ae12f6a8e7dc0865e32c3b516 (diff)
- requirements.txt: use the upstream version of pymediainfo (BeautifulSoup patch applied)
- add copy_movie management command - add_movie management command: remove --copy and --delete options - add_movie_to_user_seen_movies, delete_movie, update_moviefile_of_movie management command: use exact instead of iexact, fix bug in filename query - change mode of helpers/check_for_updates.py to 755
-rwxr-xr-x[-rw-r--r--]helpers/check_for_updates.py0
-rw-r--r--requirements.txt2
-rw-r--r--videodb/management/commands/add_movie.py36
-rw-r--r--videodb/management/commands/add_movie_to_user_seen_movies.py6
-rw-r--r--videodb/management/commands/copy_movie.py100
-rw-r--r--videodb/management/commands/delete_movie.py6
-rw-r--r--videodb/management/commands/update_moviefile_of_movie.py6
7 files changed, 110 insertions, 46 deletions
diff --git a/helpers/check_for_updates.py b/helpers/check_for_updates.py
index 051469d..051469d 100644..100755
--- a/helpers/check_for_updates.py
+++ b/helpers/check_for_updates.py
diff --git a/requirements.txt b/requirements.txt
index f87d27b..6805595 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,4 +9,4 @@ Whoosh
-e hg+https://bitbucket.org/alberanid/imdbpy#egg=imdbpy
pytz
python-magic
--e git+https://github.com/legrostdg/pymediainfo.git#egg=pymediainfo
+-e git+https://github.com/paltman/pymediainfo#egg=pymediainfo
diff --git a/videodb/management/commands/add_movie.py b/videodb/management/commands/add_movie.py
index d4cb536..bbabcf0 100644
--- a/videodb/management/commands/add_movie.py
+++ b/videodb/management/commands/add_movie.py
@@ -46,16 +46,6 @@ class Command(BaseCommand):
dest='no',
default=False,
help='Tells Django to NOT prompt the user for input of any kind, answers no to all questions'),
- make_option('-c', '--copy',
- action='store_true',
- dest='copy',
- default=False,
- help='Copy file to DIRECTORS_DIR/movie_director and symlink it in MOVIES_DIR. DIRECTORS_DIR and MOVIES_DIR have to be specified in videodb.settings.'),
- make_option('-d', '--delete',
- action='store_true',
- dest='delete',
- default=False,
- help='Delete old file after having it copied (require --copy, ignored instead).'),
)
def handle(self, *args, **options):
@@ -64,8 +54,6 @@ class Command(BaseCommand):
ofile = options.get('file')
imdbid = options.get('imdbid')
search = options.get('search')
- copy = options.get('copy')
- delete = options.get('delete')
i = IMDb()
@@ -123,30 +111,6 @@ Type 'yes' to continue, or 'no' to cancel: """ % { 'id': imdbid })
imdbdata = get_imdbdata(imdbmovie=movie)
add_imdbdata_to_movie(movie=m, imdbdata=imdbdata)
- if copy:
- #osfile = os.path.realpath(ofile)
- directors = ", ".join([_.person.name for _ in m.director.all()])
- directorspath = os.path.join(settings.DIRECTORS_DIR, directors)
- if os.path.exists(directorspath):
- logger.info("Directory \"%s\" already exists." % directorspath)
- else:
- logger.info("Directory \"%s\" does not exist." % directorspath)
- logger.info("Creating directory \"%s\"." % directorspath)
- os.makedirs(directorspath)
- #realfile = os.path.realpath(ofile)
- moviepath = os.path.join(directorspath, os.path.basename(ofile))
- logger.info("Copying file \"%(file)s\" to \"%(path)s\"." % { 'file': ofile, 'path': moviepath })
- shutil.copyfile(ofile, moviepath)
- movies_dir = settings.MOVIES_DIR
- link_name = os.path.join(movies_dir, os.path.basename(ofile))
- source = os.path.relpath(moviepath, movies_dir)
- logger.info("Creating symlink \"%(link_name)s\" -> \"%(source)s\"." % { 'link_name': link_name, 'source': source })
- os.symlink(source, link_name)
-
- if delete:
- logger.info("Deleting old file \"%s\"" % ofile)
- os.remove(ofile)
-
# Print the result
full_url = ''.join(['http://', get_current_site(None).domain, m.get_absolute_url()])
logger.info("You can see the result on: %s" % full_url)
diff --git a/videodb/management/commands/add_movie_to_user_seen_movies.py b/videodb/management/commands/add_movie_to_user_seen_movies.py
index 906b5f9..2c6e43f 100644
--- a/videodb/management/commands/add_movie_to_user_seen_movies.py
+++ b/videodb/management/commands/add_movie_to_user_seen_movies.py
@@ -35,15 +35,15 @@ class Command(BaseCommand):
if options['username'] and options['imdbid']:
username = options['username']
imdbid = options['imdbid']
- movies = Movie.objects.filter(movieID__iexact = imdbid)
+ movies = Movie.objects.filter(movieID__exact = imdbid)
if len(movies) == 1:
movie = movies[0]
logger.info('select movie "%(title)s" corresponding to imdbid "%(imdbid)s".' %
{ 'title': movie.title, 'imdbid': imdbid})
- users = UserProfile.objects.filter(user__username__iexact = username)
+ users = UserProfile.objects.filter(user__username__exact = username)
if users:
user = users[0]
- seen_movies = user.seen_movies.filter(movieID__iexact = imdbid)
+ seen_movies = user.seen_movies.filter(movieID__exact = imdbid)
if seen_movies:
logger.warn('movie "%(title)s" is already seen by user "%(username)s".' %
{ 'title': movie.title, 'username': username})
diff --git a/videodb/management/commands/copy_movie.py b/videodb/management/commands/copy_movie.py
new file mode 100644
index 0000000..fbc44eb
--- /dev/null
+++ b/videodb/management/commands/copy_movie.py
@@ -0,0 +1,100 @@
+# -*- coding: utf-8 -*-
+from django.core.management.base import BaseCommand, CommandError
+from videodb.models import *
+import sys
+from optparse import OptionParser, make_option
+import warnings
+import logging
+from videodb import settings
+from django.contrib.sites.models import get_current_site
+
+
+logger = logging.getLogger(__name__)
+
+
+class Command(BaseCommand):
+ option_list = BaseCommand.option_list + (
+ make_option('-I', '--id',
+ dest='id',
+ help='Get movie id'),
+ make_option('-i', '--imdbid',
+ dest='imdbid',
+ help='Get IMDb id'),
+ make_option('-f', '--file',
+ dest='file',
+ help='Movie new file'),
+ make_option('-c', '--copy',
+ action='store_true',
+ dest='copy',
+ default=False,
+ help='Copy file to DIRECTORS_DIR/movie_director and symlink it in MOVIES_DIR. DIRECTORS_DIR and MOVIES_DIR have to be specified in videodb.settings.'),
+ make_option('-d', '--delete',
+ action='store_true',
+ dest='delete',
+ default=False,
+ help='Delete old file after having it copied (require --copy, ignored instead).'),
+ )
+
+ def handle(self, *args, **options):
+ ofile = options.get('file')
+ oid = options.get('id')
+ imdbid = options.get('imdbid')
+ search = options.get('search')
+ copy = options.get('copy')
+ delete = options.get('delete')
+
+ if ofile:
+ movies = Movie.objects.filter(file__filename__exact = ofile)
+ logger.info('select movies corresponding to file "%s".' % ofile)
+
+ if oid:
+ movies = movies.filter(id__exact = oid)
+ logger.info('select movies corresponding to id "%s".' % oid)
+ else:
+ if imdbid:
+ movies = movies.filter(movieID__exact = imdbid)
+ logger.info('select movies corresponding to imdbid "%s".' % imdbid)
+
+ if len(movies) == 1:
+ movie = movies[0]
+ logger.info('select movie "%(title)s" (id:"%(id)s").' %
+ { 'title': movie.title, 'id': movie.id })
+
+ if copy:
+ #osfile = os.path.realpath(ofile)
+ directors = ", ".join([_.person.name for _ in movie.director.all()])
+ directorspath = os.path.join(settings.DIRECTORS_DIR, directors)
+ if os.path.exists(directorspath):
+ logger.info("Directory \"%s\" already exists." % directorspath)
+ else:
+ logger.info("Directory \"%s\" does not exist." % directorspath)
+ logger.info("Creating directory \"%s\"." % directorspath)
+ os.makedirs(directorspath)
+ #realfile = os.path.realpath(ofile)
+ moviepath = os.path.join(directorspath, os.path.basename(ofile))
+ logger.info("Copying file \"%(file)s\" to \"%(path)s\"." % { 'file': ofile, 'path': moviepath })
+ shutil.copyfile(ofile, moviepath)
+ movies_dir = settings.MOVIES_DIR
+ link_name = os.path.join(movies_dir, os.path.basename(ofile))
+ source = os.path.relpath(moviepath, movies_dir)
+ logger.info("Creating symlink \"%(link_name)s\" -> \"%(source)s\"." % { 'link_name': link_name, 'source': source })
+ os.symlink(source, link_name)
+
+ if delete:
+ logger.info("Deleting old file \"%s\"" % ofile)
+ os.remove(ofile)
+
+ # Print the result
+ full_url = ''.join(['http://', get_current_site(None).domain, movie.get_absolute_url()])
+ logger.info("You can see the result on: %s" % full_url)
+ elif len(movies) > 1:
+ logger.error('%(number)d movies matching given parameters.' %
+ { 'number': len(movies) })
+ else:
+ logger.error('No movie matching the given parameters.')
+ else:
+ raise CommandError('You have to provide a movie file (--file) matching the movie.')
+
+
+ pass
+
diff --git a/videodb/management/commands/delete_movie.py b/videodb/management/commands/delete_movie.py
index 67762f1..c75aa23 100644
--- a/videodb/management/commands/delete_movie.py
+++ b/videodb/management/commands/delete_movie.py
@@ -47,14 +47,14 @@ class Command(BaseCommand):
if imdbid or ofile or oid:
if imdbid:
- movies = Movie.objects.filter(movieID__iexact = imdbid)
+ movies = Movie.objects.filter(movieID__exact = imdbid)
logger.info('select movies corresponding to imdbid "%s".' % imdbid)
if ofile:
osfile = os.path.basename(ofile)
- movies = Movie.objects.filter(file__filename__iexact = osfile)
+ movies = Movie.objects.filter(file__filename__exact = osfile)
logger.info('select movies corresponding to file "%s".' % osfile)
if oid:
- movies = Movie.objects.filter(id__iexact = oid)
+ movies = Movie.objects.filter(id__exact = oid)
logger.info('select movies corresponding to id "%s".' % oid)
if movies:
diff --git a/videodb/management/commands/update_moviefile_of_movie.py b/videodb/management/commands/update_moviefile_of_movie.py
index 7bb9954..6ffaa89 100644
--- a/videodb/management/commands/update_moviefile_of_movie.py
+++ b/videodb/management/commands/update_moviefile_of_movie.py
@@ -45,13 +45,13 @@ class Command(BaseCommand):
if imdbid or oldfile or oid:
if imdbid:
- movies = Movie.objects.filter(movieID__iexact = imdbid)
+ movies = Movie.objects.filter(movieID__exact = imdbid)
logger.info('select movies corresponding to imdbid "%s".' % imdbid)
if oldfile:
- movies = Movie.objects.filter(file__iexact = oldfile)
+ movies = Movie.objects.filter(file__filename__exact = oldfile)
logger.info('select movies corresponding to oldfile "%s".' % oldfile)
if oid:
- movies = Movie.objects.filter(id__iexact = oid)
+ movies = Movie.objects.filter(id__exact = oid)
logger.info('select movies corresponding to id "%s".' % oid)
if len(movies) == 1: