Пример #1
0
    def save(self, *args, **kwargs):
        if self.id and self.info:
            self.path = self.normalize_path()
        if self.item:
            data = self.get_path_info()
            self.extension = data.get('extension')
            self.language = data.get('language')
            self.part = ox.sort_string(unicode(data.get('part') or ''))
            self.part_title = ox.sort_string(unicode(data.get('partTitle')) or '')
            self.type = data.get('type') or 'unknown'
            self.version = data.get('version')

        if self.path:
            self.sort_path = utils.sort_string(self.path)
            self.is_audio = self.type == 'audio'
            self.is_video = self.type == 'video'
            self.is_subtitle = self.path.endswith('.srt')

        if self.type not in ('audio', 'video'):
            self.duration = None
        else:
            duration = sum([s.info.get('duration', 0)
                for s in self.streams.filter(source=None)])
            if duration:
                self.duration = duration

        if self.is_subtitle:
            self.available = self.data and True or False
        else:
            self.available = not self.uploading and \
                self.streams.filter(source=None, available=True).count() > 0
        super(File, self).save(*args, **kwargs)
Пример #2
0
    def save(self, *args, **kwargs):
        if not self.uploading:
            if self.file:
                self.size = self.file.size
                if self.extension == 'pdf' and not os.path.exists(self.thumbnail()):
                    self.make_thumbnail()

        self.name_sort = ox.sort_string(self.name or u'')[:255].lower()
        self.description_sort = ox.sort_string(self.description or u'')[:512].lower()

        super(Document, self).save(*args, **kwargs)
    def save(self, *args, **kwargs):
        if not self.uploading:
            if self.file:
                self.size = self.file.size
                if self.extension == 'pdf' and not os.path.exists(
                        self.thumbnail()):
                    self.make_thumbnail()
                self.get_info()

        self.name_sort = ox.sort_string(self.name or u'')[:255].lower()
        self.description_sort = ox.sort_string(self.description
                                               or u'')[:512].lower()

        super(Document, self).save(*args, **kwargs)
        self.update_matches()
Пример #4
0
 def save(self):
     if not self.sortname:
         self.sortname = ox.get_sort_name(self.name)
         self.sortname = unicodedata.normalize("NFKD", self.sortname)
     self.sortsortname = ox.sort_string(self.sortname)
     self.numberofnames = len(self.name.split(" "))
     state.db.session.add(self)
     state.db.session.commit()
Пример #5
0
 def save(self):
     if not self.sortname:
         self.sortname = ox.get_sort_name(self.name)
         self.sortname = unicodedata.normalize('NFKD', self.sortname)
     self.sortsortname = ox.sort_string(self.sortname)
     self.numberofnames = len(self.name.split(' '))
     state.db.session.add(self)
     state.db.session.commit()
Пример #6
0
def sort_title(title):

    title = title.replace('Æ', 'Ae')
    if isinstance(title, str):
        title = str(title)
    title = ox.sort_string(title)

    #title
    title = re.sub('[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
    return title.strip()
Пример #7
0
def sort_title(title):

    title = title.replace('Æ', 'Ae')
    if isinstance(title, str):
        title = str(title)
    title = ox.sort_string(title)

    #title
    title = re.sub('[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
    return title.strip()
Пример #8
0
 def update_sort(self):
     update = False
     s = Sort.get_or_create(self.id)
     for key in config['itemKeys']:
         if key.get('sort'):
             value = self.json().get(key['id'], None)
             sort_type = key.get('sortType', key['type'])
             if value:
                 if sort_type == 'integer':
                     if isinstance(value, str):
                         value = int(re.sub('[^0-9]', '', value))
                     else:
                         value = int(value)
                 elif sort_type == 'float':
                     value = float(value)
                 elif sort_type == 'date':
                     pass
                 elif sort_type == 'person':
                     if not isinstance(value, list):
                         value = [value]
                     value = list(map(get_sort_name, value))
                     value = ox.sort_string('\n'.join(value)).lower()
                 elif sort_type == 'title':
                     if isinstance(value, dict):
                         value = list(value.values())
                     if isinstance(value, list):
                         value = ''.join(value)
                     value = ox.get_sort_title(value)
                     value = utils.sort_title(value).lower()
                 else:
                     if isinstance(value, list):
                         value = '\n'.join(value)
                     if value:
                         value = str(value)
                         value = ox.sort_string(value).lower()
             elif isinstance(value, list): #empty list
                 value = ''
             if getattr(s, key['id']) != value:
                 setattr(s, key['id'], value)
                 update = True
     if update:
         state.db.session.add(s)
Пример #9
0
    def save(self, *args, **kwargs):
        if self.id and self.info:
            self.path = self.normalize_path()
        if self.item:
            data = self.get_path_info()
            self.extension = data.get('extension')
            self.language = data.get('language')
            self.part = ox.sort_string(unicode(data.get('part') or ''))
            self.part_title = ox.sort_string(
                unicode(data.get('partTitle')) or '')
            self.type = data.get('type') or 'unknown'
            self.version = data.get('version')

        if self.path:
            self.sort_path = utils.sort_string(self.path)
            self.is_audio = self.type == 'audio'
            self.is_video = self.type == 'video'
            #uwe added following line
            self.is_image = self.type == 'image'
            self.is_subtitle = self.path.endswith('.srt')
        #wafaa
        #if self.type not in ('audio', 'video'):
        if self.type not in ('audio', 'video', 'image'):
            self.duration = None
        else:
            duration = sum([
                s.info.get('duration', 0)
                for s in self.streams.filter(source=None)
            ])
            if duration:
                self.duration = duration

        if self.is_subtitle:
            self.available = self.data and True or False
        else:
            self.available = not self.uploading and \
                self.streams.filter(source=None, available=True).count() > 0
        super(File, self).save(*args, **kwargs)
Пример #10
0
def lookup(key, value):
    if not isvalid_id(key, value):
        return {}
    data = {key: [value]}
    ids = set([(key, value)])
    provider_data = {}
    done = False

    while not done:
        done = True
        for provider, id in providers:
            result = lookup_provider((provider, id, ids, key, value))
            done = not result - ids
            ids.update(result)
    logger.debug('FIXME: sort ids')
    ids = sorted(ids, key=lambda i: ox.sort_string(''.join(i)))
    logger.debug('IDS %s', ids)
    for k, v in ids:
        for provider, id in providers:
            if id == k:
                if provider not in provider_data:
                    provider_data[provider] = {}
                for k_, v_ in globals()[provider].lookup(v).items():
                    if k_ not in provider_data[provider]:
                        provider_data[provider][k_] = v_
    for provider in sorted(list(provider_data.keys()),
                           key=lambda x: -len(provider_data[x])):
        logger.debug('%s %s %s', provider, len(provider_data[provider]),
                     list(provider_data[provider].keys()))
        for k_, v_ in provider_data[provider].items():
            if not k_ in data:
                data[k_] = v_
    for k, v in ids:
        if k not in data:
            data[k] = []
        if v not in data[k]:
            data[k].append(v)
    for key in [
            k['id'] for k in settings.config['itemKeys']
            if isinstance(k['type'], list)
    ]:
        if key in data and not isinstance(data[key], list):
            data[key] = [data[key]]
    return data
Пример #11
0
def lookup(key, value):
    if not isvalid_id(key, value):
        return {}
    data = {key: [value]}
    ids = set([(key, value)])
    provider_data = {}
    done = False

    while not done:
        done = True
        for provider, id in providers:
            result = lookup_provider((provider, id, ids, key, value))
            done = not result - ids
            ids.update(result)
    logger.debug('FIXME: sort ids')
    ids = sorted(ids, key=lambda i: ox.sort_string(''.join(i)))
    logger.debug('IDS %s', ids)
    for k, v in ids:
        for provider, id in providers:
            if id == k:
                if provider not in provider_data:
                    provider_data[provider] = {}
                for k_, v_ in globals()[provider].lookup(v).items():
                    if k_ not in provider_data[provider]:
                        provider_data[provider][k_] = v_
    for provider in sorted(
        list(provider_data.keys()),
        key=lambda x: -len(provider_data[x])
    ):
        logger.debug('%s %s %s', provider, len(provider_data[provider]), list(provider_data[provider].keys()))
        for k_, v_ in provider_data[provider].items():
            if not k_ in data:
                data[k_] = v_
    for k, v in ids:
        if k not in data:
            data[k] = []
        if v not in data[k]:
            data[k].append(v)
    for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
        if key in data and not isinstance(data[key], list):
            data[key] = [data[key]]
    return data
Пример #12
0
def getUsers(data):
    """
        returns {
            users: []
        }
    """
    users = []
    ids = set()
    for u in models.User.query.filter(models.User.id != settings.USER_ID).all():
        users.append(u.json())
        ids.add(u.id)
    if state.nodes:
        for id in state.nodes._local._nodes:
            if id not in ids:
                n = state.nodes._local._nodes[id].copy()
                n["online"] = True
                n["name"] = n["username"]
                users.append(n)
    users.sort(key=lambda u: ox.sort_string(str(u.get("index", "")) + "Z" + (u.get("name") or "")))
    return {"users": users}
Пример #13
0
def getUsers(data):
    '''
        returns {
            users: []
        }
    '''
    users = []
    ids = set()
    for u in models.User.query.filter(
            models.User.id != settings.USER_ID).all():
        users.append(u.json())
        ids.add(u.id)
    if state.nodes:
        for id in state.nodes._local._nodes:
            if id not in ids:
                n = state.nodes._local._nodes[id].copy()
                n['online'] = True
                n['name'] = n['username']
                users.append(n)
    users.sort(key=lambda u: ox.sort_string(
        str(u.get('index', '')) + 'Z' + (u.get('name') or '')))
    return {"users": users}