Ejemplo n.º 1
0
 def test_no_storage_root_path(self):
     file_properties = utils.FileProperties(
         '/tmp/foo/baz/bazinga/movie1337.mp4')
     assert_that(file_properties.storage_root_path, equal_to('/'))
     assert_that(file_properties.relative_path,
                 equal_to('tmp/foo/baz/bazinga/movie1337.mp4'))
     assert_that(file_properties.subdirectory_path,
                 equal_to('tmp/foo/baz/bazinga'))
Ejemplo n.º 2
0
 def test_empty(self):
     file_properties = utils.FileProperties('')
     assert_that(file_properties.base_name, equal_to(''))
     assert_that(file_properties.file_path, equal_to(''))
     assert_that(file_properties.extension, equal_to(''))
     assert_that(file_properties.storage_root_path, equal_to('/'))
     assert_that(file_properties.relative_path, equal_to(''))
     assert_that(file_properties.subdirectory_path, equal_to(''))
Ejemplo n.º 3
0
 def test_full(self):
     file_properties = utils.FileProperties(
         '/tmp/foo/baz/bazinga/movie1337.mp4', storage_root_path='/tmp/foo')
     assert_that(file_properties.base_name, equal_to('movie1337'))
     assert_that(file_properties.file_path,
                 equal_to('/tmp/foo/baz/bazinga/movie1337.mp4'))
     assert_that(file_properties.extension, equal_to('.mp4'))
     assert_that(file_properties.storage_root_path, equal_to('/tmp/foo'))
     assert_that(file_properties.relative_path,
                 equal_to('baz/bazinga/movie1337.mp4'))
     assert_that(file_properties.subdirectory_path, equal_to('baz/bazinga'))
Ejemplo n.º 4
0
    def __init__(self, file_properties, api=None, scene_properties=None):
        # Filter out dates like 091224 or (20)150101
        self._unlikely_shootid_date_re = re.compile('([01]\d)({})({})'.format(
            '|'.join(['{:02}'.format(i) for i in range(1, 13)]),
            '|'.join(['{:02}'.format(i) for i in range(1, 32)])))
        self.api = api

        if type(file_properties) is dict:
            self.file_properties = utils.FileProperties(**file_properties)
        else:
            self.file_properties = file_properties

        if type(scene_properties) is dict:
            self.scene_properties = utils.SceneProperties(**scene_properties)
        elif type(scene_properties) is utils.SceneProperties:
            self.scene_properties = scene_properties
        else:
            self.scene_properties = utils.SceneProperties()

        if self.settings is None:
            logging.warning(
                'Settings were not set by calling class! This will break!')
Ejemplo n.º 5
0
    def read(self):
        """ Read in/Create the database from file"""
        if not path.exists(self._path):
            logging.info("No database found at '{}', recreating!".format(self._path))
            return

        if not access(self._path, W_OK):
            logging.error("No write-permissions for database '{}'!".format(self._path))
            return
        if not access(self._path, R_OK):
            logging.error("No read-permissions for database '{}'!".format(self._path))
            return

        try:
            with open(self._path, 'r') as f:
                _data = f.read()

            if not _data:
                logging.info("Database at '{}' was empty, recreating!".format(self._path))
                return

            _decoded = json.loads(_data)
            self.original = _decoded.pop('original', False)

            Movie.settings = self._settings
            _movies = OrderedDict()
            for file_path, serialized in _decoded.items():
                api = self._settings.apis.get(serialized.pop('api', None), None)
                file_properties = utils.FileProperties(**serialized.pop('file_properties', {}))
                scene_properties = utils.SceneProperties(**serialized.get('scene_properties',{}))

                m_ = Movie(file_properties, api, scene_properties=scene_properties)
                _movies[file_path] = m_

        except Exception as e:
            logging.error("Database '{}' possibly corrupted (Error: '{}'), recreating!".format(self._path, e))
            return
        self.movies = _movies
Ejemplo n.º 6
0
                    p=self.file_properties).replace('/', '_')
            return '[<untagged>] {p.base_name}{p.extension}'.format(
                p=self.file_properties).replace('/', '_')

        ret = str(self.scene_properties)
        if not self.scene_properties.is_filled():
            ret += ' | [<incompletely_tagged>] {p.base_name}{p.extension}'.format(
                p=self.file_properties)

        ret += self.file_properties.extension
        return ret.replace('/', '_')

    def __bool__(self):
        return self.scene_properties.is_filled()


if __name__ == '__main__':
    import sys
    path = sys.argv[1]
    logging.basicConfig(format='%(funcName)-30s: %(message)s',
                        level=logging.DEBUG)
    file_properties_ = utils.FileProperties(path, storage_root_path='')
    settings_ = utils.Settings({'shootid_template_dir': 'apis/templates'})
    Movie.settings = settings_
    m = Movie(file_properties=file_properties_,
              api=settings_.apis.get('Kink.com', None),
              scene_properties=None)

    m.update_details()

    print(m)