Example #1
0
def _rescan(request):
    library = Library.objects.default
    files = (
        movie_files()
    )  # _files_in_dir(settings.MOVIE_ROOT, ignore_paths=[os.path.join(settings.MOVIE_ROOT, "Backup")])
    context = {"page": "tools", "filenames": files, "library": library}
    return render_to_response("tools/rebuild.html", context)
Example #2
0
def rebuild_actions(request):
    actions = []
    files = movie_files()
    files.sort()
    for f in files:
        short_name, _ = os.path.splitext(f.split("/")[-1])

        # add movie to the system
        actions.append(
            {
                "action": "Add",
                "details": short_name,
                "action_url": reverse("rebuild_operation"),
                "action_params": {"path": quote(f)},
            }
        )

        # find recommendations for movie
        actions.append(
            {
                "action": "Get Recommendations",
                "details": short_name,
                "action_url": reverse("get_recommendations"),
                "action_params": {"path": quote(f), "max_recommendations": 10},
            }
        )
    return HttpResponse(json.dumps(actions))
Example #3
0
def rebuild_actions(request):
    actions = []
    files = movie_files()
    files.sort()
    for f in files:
        short_name, _ = os.path.splitext(f.split("/")[-1])

        # add movie to the system
        actions.append({
            'action': "Add",
            'details': short_name,
            'action_url': reverse('rebuild_operation'),
            'action_params': {'path': quote(f)}
        })

        # find recommendations for movie
        actions.append({
            'action': "Get Recommendations",
            'details': short_name,
            'action_url': reverse('get_recommendations'),
            'action_params': {
                'path': quote(f),
                'max_recommendations': 10}
        })
    return HttpResponse(json.dumps(actions))
Example #4
0
def _rescan(request):
    library = Library.objects.default
    files = movie_files()  # _files_in_dir(settings.MOVIE_ROOT, ignore_paths=[os.path.join(settings.MOVIE_ROOT, "Backup")])
    context = {'page': 'tools',
               'filenames': files,
               'library': library}
    return render_to_response('tools/rebuild.html', context)
Example #5
0
def repopulate_movies():
    Movie.objects.all().delete()
    for image in Image.objects.all():
        image.delete()
    Library.objects.all().delete()
    files = movie_files()  # _files_in_dir(settings.MOVIE_ROOT, ignore_paths=[os.path.join(settings.MOVIE_ROOT, "Backup")])
    for filepath in files:
        movie, created = Movie.objects.get_or_create_from_filepath(filepath)
        Library.objects.default.add_movie(movie)
Example #6
0
def rebuild_operation(request):
    if request.method != "POST":
        return HttpResponseBadRequest()

    filepath = unquote(request.POST.get("path"))
    if not filepath or filepath not in movie_files():
        return HttpResponseBadRequest()

    library = Library.objects.default
    movie, created = Movie.objects.get_or_create_from_filepath(filepath)
    if movie:
        library.add_movie(movie)
        return HttpResponse()

    return HttpResponseNotFound()
Example #7
0
def get_recommendations_for_movie(request):
    if request.method != 'POST':
        return HttpResponseBadRequest()

    filepath = unquote(request.POST.get('path'))
    max_recommendations = int(request.POST.get('max_recommendations'))
    if not max_recommendations or not filepath or filepath not in movie_files():
        return HttpResponseBadRequest()

    movie, created = Movie.objects.get_or_create_from_filepath(filepath)
    if movie:
        recommendations = movie.get_recommendation_list()
        max_len = min(len(recommendations), max_recommendations)
        for recommendation in recommendations[:max_len]:
            recommended_movie, created = Movie.objects.create_from_moviedb_id(moviedb_id=recommendation.get("id"))
            Recommendation.objects.create_from_moviedb_info(movie, recommended_movie, recommendation)

    return HttpResponse()