Exemplo n.º 1
0
def research_movie(tmdb_id):
    mov = Movie.query.filter_by(tmdb_id=tmdb_id).first()
    if mov is None:
        data = tmdb.get_movie(tmdb_id)
        if not data:
            return jsonify({'result': False, 'data': 'Movie not found'})
        mov = Movie(data)
    return jsonify({'result': True, 'data': 'Movie manual search scheduled'})
Exemplo n.º 2
0
def refresh_movie(tmdb_id):
    mov = Movie.query.filter_by(tmdb_id=tmdb_id).first()
    if mov is None:
        data = tmdb.get_movie(tmdb_id)
        if not data:
            return jsonify({'result': False, 'data': 'Movie not found'})
        mov = Movie(data)
    Library.refresh_movie_item(mov)
    return jsonify({'result': True, 'data': 'Movie refresh scheduled'})
Exemplo n.º 3
0
def unwatch_movie(tmdb_id):
    mov = Movie.query.filter_by(tmdb_id=tmdb_id).first()
    if mov is None:
        data = tmdb.get_movie(tmdb_id)
        if not data:
            return jsonify({'result': False, 'data': 'Movie not found'})
        mov = Movie(data)
    mov.watching = False
    mov.save()
    return jsonify({'result': True, 'data': 'Movie updated'})
Exemplo n.º 4
0
def movie(tmdb_id):
    mov = Movie.query.filter_by(tmdb_id=tmdb_id).first()
    if mov is None:
        data = tmdb.get_movie(tmdb_id)
        if not data:
            flash('Movie %s not found.' % tmdb_id)
            return redirect('/')
        mov = Movie(data)
    imdb = 'http://www.dereferer.org/?' + urllib.parse.quote_plus(
        'http://www.imdb.com/title/' + mov.imdb_id)
    settings_form = QualityForm()
    settings_form.quality.data = mov.search_quality
    return render_template('movies/view.html',
                           title=mov.title,
                           heading=mov.title,
                           media=mov,
                           search_form=SearchForm(),
                           settings_form=settings_form,
                           imdb_link=imdb,
                           refreshing=Library.refreshing_movie(tmdb_id))
Exemplo n.º 5
0
    def __refresh_movie_local(self):
        dpath = Settings.get(self.SETTINGS_MOVIE_DOWNLOAD_PATH)
        mpath = Settings.get(self.SETTINGS_MOVIE_MEDIA_PATH)
        ptn = filemedia.PTN()

        downloads = Path(dpath)
        media_files = chain.from_iterable(
            downloads.rglob(os.path.join('**', '*' + p))
            for p in filemedia.video_file_extensions)

        for path in media_files:
            ptn_data = ptn.parse(path.name)
            newfile = self.__generate_movie_file_from_ptn(
                ptn_data) + path.suffix
            newdir = os.path.join(
                mpath, self.__generate_movie_folder_from_ptn(ptn_data))
            newpath = os.path.join(newdir, newfile)
            oldpath = str(path)

            if 'year' in ptn_data:
                movies = tmdb.search_movie(ptn_data['title'], ptn_data['year'])
            else:
                movies = tmdb.search_movie(ptn_data['title'])

            if len(movies) < 1 or 'id' not in movies[0]:
                continue

            movie = Movie.query.filter_by(tmdb_id=movies[0]['id']).first()
            if movie is None:
                data = tmdb.get_movie(movies[0]['id'])
                if not data:
                    Log.error('Movie %s not found.' % movies[0]['id'])
                    return False
                movie = Movie(data)

            if movie.has_files:
                Log.error(
                    'Movie %s already has files in the library' %
                    movies[0]['id'], 'Ignoring download file: %s' % oldpath)
            elif os.path.isfile(newpath):
                Log.warning(
                    'Destination file for movie %s already exists' %
                    movies[0]['id'],
                    'Ignoring download file: %s\nAdding media file:%s' %
                    (oldpath, newpath))
                movie.add_file(newpath)
            else:
                # TODO: Move the file to the newpath first then add this
                Log.info('Creating directory', newdir)
                os.makedirs(newdir, exist_ok=True)
                Log.info('Moving media file',
                         'Src: %s\nDst: %s' % (oldpath, newpath))
                os.rename(oldpath, newpath)
                if app.config['symlink_files']:
                    try:
                        os.symlink(newpath, oldpath)
                    except OSError as e:
                        Log.error(
                            'Error creating symlink', 'Src: %s\nDst: %s\n%s' %
                            (oldpath, newpath, e.strerror))
                elif app.config['hardlink_files']:
                    try:
                        os.link(newpath, oldpath)
                    except OSError as e:
                        Log.error(
                            'Error creating hardlink', 'Src: %s\nDst: %s\n%s' %
                            (oldpath, newpath, e.strerror))
                        try:
                            os.symlink(newpath, oldpath)
                        except OSError as e:
                            Log.error(
                                'Error creating symlink',
                                'Src: %s\nDst: %s\n%s' %
                                (oldpath, newpath, e.strerror))
                movie.add_file(newpath)
        pass