Mercurial > code > home > repos > video
comparison video_file_store.py @ 38:0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
author | drewp@bigasterisk.com |
---|---|
date | Wed, 04 Dec 2024 21:50:16 -0800 |
parents | 7cacfae58430 |
children |
comparison
equal
deleted
inserted
replaced
37:7cacfae58430 | 38:0aea9e55899b |
---|---|
2 import hashlib | 2 import hashlib |
3 import logging | 3 import logging |
4 import os | 4 import os |
5 from dataclasses import dataclass | 5 from dataclasses import dataclass |
6 from pathlib import Path | 6 from pathlib import Path |
7 import re | |
7 from typing import Iterable, Iterator | 8 from typing import Iterable, Iterator |
8 | 9 |
9 import pymongo.collection | 10 import pymongo.collection |
10 | 11 |
11 log = logging.getLogger('vfs') | 12 log = logging.getLogger('vfs') |
18 webDataPath: str | 19 webDataPath: str |
19 label: str | 20 label: str |
20 # perms, playlists, req by/when | 21 # perms, playlists, req by/when |
21 | 22 |
22 | 23 |
24 def numSort(docs: list): | |
25 | |
26 def pad(match): | |
27 return match.group(0).zfill(10) | |
28 | |
29 docs.sort(key=lambda doc: re.sub(r"\d+", pad, doc['label'])) | |
30 | |
23 @dataclass | 31 @dataclass |
24 class VideoFileStore: | 32 class VideoFileStore: |
25 fs: pymongo.collection.Collection | 33 fs: pymongo.collection.Collection |
26 | 34 |
27 def findInDir(self, subdir: str) -> Iterable[VideoFile]: | 35 def findInDir(self, subdir: str) -> Iterable[VideoFile]: |
36 log.warning(f'findInDir: {subdir=}') | |
28 webRelParent = '.' if subdir == '/' else subdir | 37 webRelParent = '.' if subdir == '/' else subdir |
29 for doc in self.fs.find({ | 38 docs = list(self.fs.find({ |
30 'type': 'file', | 39 'type': 'file', |
31 'webRelParent': webRelParent | 40 'webRelParent': webRelParent |
32 }, sort=[('label', 1)]): | 41 })) |
42 numSort(docs) | |
43 for doc in docs: | |
33 yield VideoFile(Path(doc['diskPath']), doc['webRelPath'], | 44 yield VideoFile(Path(doc['diskPath']), doc['webRelPath'], |
34 doc['webDataPath'], doc['label']) | 45 doc['webDataPath'], doc['label']) |
35 | 46 |
36 def findSubdirs(self, subdir: str) -> Iterable: | 47 def findSubdirs(self, subdir: str) -> Iterable: |
37 for doc in self.fs.find({ | 48 docs = list(self.fs.find({ |
38 'type': | 49 'type': |
39 'dir', | 50 'dir', |
40 'webRelParent': | 51 'webRelParent': |
41 '.' if subdir == '/' else subdir | 52 '.' if subdir == '/' else subdir |
42 }, sort=[('label', 1)]): | 53 })) |
54 numSort(docs) | |
55 | |
56 for doc in docs: | |
43 yield { | 57 yield { |
44 'label': doc['label'], | 58 'label': doc['label'], |
45 'path': doc['webRelPath'], | 59 'path': doc['webRelPath'], |
46 } | 60 } |
47 | 61 |