示例#1
0
文件: importer.py 项目: NaPs/Kolekto
    def _import(self, mdb, mds, args, config, filename):
        printer.debug('Importing file {filename}', filename=filename)
        short_filename = os.path.basename(filename)
        title, ext = os.path.splitext(short_filename)

        title, season_num, episode_num = clean_title_series(title)

        while True:
            # Disable the title input if auto mode is enabled:
            if not args.auto:
                title = printer.input(u'Title to search', default=title)
                season_num = int(printer.input(u'Season number', default=season_num))
                episode_num = int(printer.input(u'Episode number', default=episode_num))
            datasource, episode = self._search(mds, title, short_filename, season_num, episode_num, auto=args.auto)
            if datasource == 'manual':
                episode = self.profile.object_class()
            elif datasource == 'abort':
                printer.p('Aborted import of {filename}', filename=filename)
                return
            break

        if datasource is None:
            return

        return episode

        # Refresh the full data for the choosen movie:
        episode = mds.refresh(episode)
示例#2
0
文件: importer.py 项目: NaPs/Kolekto
    def _import(self, mdb, mds, args, config, filename):
        printer.debug('Importing file {filename}', filename=filename)
        short_filename = os.path.basename(filename)
        title, ext = os.path.splitext(short_filename)

        year, title = clean_title(title)

        # Disable the year filter if auto mode is disabled:
        if not args.auto:
            year = None

        while True:
            # Disable the title input if auto mode is enabled:
            if not args.auto:
                title = printer.input(u'Title to search', default=title)
            datasource, movie = self._search(mds, title, short_filename, year, auto=args.auto)
            if datasource == 'manual':
                movie = self.profile.object_class()
            elif datasource == 'abort':
                printer.p('Aborted import of {filename}', filename=filename)
                return
            break

        if datasource is None:
            return

        return movie
示例#3
0
文件: importer.py 项目: NaPs/Kolekto
    def run(self, args, config):
        # Check the args:
        if args.symlink and args.delete:
            raise KolektoRuntimeError('--delete can\'t be used with --symlink')
        elif args.symlink and args.hardlink:
            raise KolektoRuntimeError('--symlink and --hardlink are mutually exclusive')

        # Load the metadata database:
        mdb = self.get_metadata_db(args.tree)

        # Load informations from db:
        mds = MovieDatasource(config.subsections('datasource'), args.tree, self.profile.object_class)

        attachment_store = AttachmentStore(os.path.join(args.tree, '.kolekto', 'attachments'))

        for filename in args.file:
            filename = filename.decode('utf8')
            movie = self._import(mdb, mds, args, config, filename)

            # Refresh the full data for the choosen movie:
            movie = mds.refresh(movie)

            # Append the import date
            movie['import_date'] = datetime.datetime.now().strftime('%d/%m/%Y %H:%M:%S')

            if args.show:
                show(movie)
                printer.p('')

            # Edit available data:
            if not args.auto and printer.ask('Do you want to edit the movie metadata', default=False):
                movie = self.profile.object_class(json.loads(printer.edit(json.dumps(movie, indent=True))))

            # Hardlink or copy the movie in the tree
            if args.hardlink or args.symlink:
                printer.p('\nComputing movie sha1sum...')
                movie_hash = link(args.tree, filename, args.symlink)
            else:
                printer.p('\nCopying movie in kolekto tree...')
                movie_hash = copy(args.tree, filename)
            printer.p('')

            mdb.save(movie_hash, movie)
            printer.debug('Movie {hash} saved to the database', hash=movie_hash)

            if args.delete:
                os.unlink(filename)
                printer.debug('Deleted original file {filename}', filename=filename)

            # Import the attachments
            if movie_hash is not None and args.import_attachments:
                attachments = list_attachments(filename)
                if attachments:
                    printer.p('Found {nb} attachment(s) for this movie:', nb=len(attachments))
                    for attach in attachments:
                        printer.p(' - {filename}', filename=attach)
                    if not args.auto and printer.ask('Import them?', default=True):
                        for attach in attachments:
                            _, ext = os.path.splitext(attach)
                            attachment_store.store(movie_hash, ext.lstrip('.'), open(attach))
示例#4
0
文件: tmdb.py 项目: nadley/Kolekto
 def _get(self, uri, *args, **kwargs):
     url = self.config.get("base_url").rstrip("/") + uri
     for _ in xrange(3):
         printer.debug("Requesting {url}", url=url)
         response = requests_session.get(url, params=kwargs)
         if not response.ok:
             printer.debug("Got error ({http_err}), retrying in 3s...", http_err=response.status_code)
             time.sleep(3)
             continue
         return json.loads(response.text)
     else:
         err_msg = "Unable to get the URL, server reported error: %s" % response.status_code
         # Show the error reason message to the user if the requests
         # version is sufficiently recent:
         if hasattr(response, "reason"):
             err_msg += " (%s)" % response.reason
         raise KolektoRuntimeError(err_msg)
示例#5
0
文件: tmdb.py 项目: NaPs/Kolekto
 def _get(self, url, *args, **kwargs):
     ak = self.config.get('api_key')
     url = url % dict(api_key=ak, **kwargs)
     for _ in xrange(3):
         printer.debug('Requesting {url}', url=url)
         response = requests.get(url)
         if not response.ok:
             printer.debug('Got error ({http_err}), retrying in 3s...', http_err=response.status_code)
             time.sleep(3)
             continue
         return json.loads(response.text)
     else:
         err_msg = 'Unable to get the URL, server reported error: %s' % response.status_code
         # Show the error reason message to the user if the requests
         # version is sufficiently recent:
         if hasattr(response, 'reason'):
             err_msg += ' (%s)' % response.reason
         raise KolektoRuntimeError(err_msg)
示例#6
0
    def _import(self, mdb, mds, args, config, filename):
        printer.debug('Importing file {filename}', filename=filename)
        short_filename = os.path.basename(filename)
        title, ext = os.path.splitext(short_filename)

        year, title = clean_title(title)

        # Disable the year filter if auto mode is disabled:
        if not args.auto:
            year = None

        while True:
            # Disable the title input if auto mode is enabled:
            if not args.auto:
                title = printer.input(u'Title to search', default=title)
            datasource, movie = self._search(mds, title, short_filename, year, auto=args.auto)
            if datasource == 'manual':
                movie = self.profile.object_class
            elif datasource == 'abort':
                printer.p('Aborted import of {filename}', filename=filename)
                return
            break

        if datasource is None:
            return

        # Refresh the full data for the choosen movie:
        movie = mds.refresh(movie)

        if args.show:
            show(movie)
            printer.p('')

        # Edit available data:
        if not args.auto and printer.ask('Do you want to edit the movie metadata', default=False):
            movie = self.profile.object_class(json.loads(printer.edit(json.dumps(movie, indent=True))))

        # Hardlink or copy the movie in the tree
        if args.hardlink or args.symlink:
            printer.p('\nComputing movie sha1sum...')
            movie_hash = link(args.tree, filename, args.symlink)
        else:
            printer.p('\nCopying movie in kolekto tree...')
            movie_hash = copy(args.tree, filename)
        printer.p('')

        mdb.save(movie_hash, movie)
        printer.debug('Movie {hash} saved to the database', hash=movie_hash)

        if args.delete:
            os.unlink(filename)
            printer.debug('Deleted original file {filename}', filename=filename)