Mercurial > code > home > repos > video
comparison video_file_store.py @ 20:cf6842952e13
serve api/folderTree
author | drewp@bigasterisk.com |
---|---|
date | Mon, 17 Apr 2023 00:42:59 -0700 |
parents | 53d99454f394 |
children | ed16fdbb3996 |
comparison
equal
deleted
inserted
replaced
19:f0a773084a2e | 20:cf6842952e13 |
---|---|
1 import asyncio | 1 import asyncio |
2 import hashlib | 2 import hashlib |
3 import re | 3 import re |
4 import os | |
4 from dataclasses import dataclass | 5 from dataclasses import dataclass |
5 from pathlib import Path | 6 from pathlib import Path |
6 from typing import Iterable, Iterator, NewType | 7 from typing import Iterable, Iterator, NewType |
8 | |
9 IGNORE = {'_thumb'} | |
7 | 10 |
8 | 11 |
9 @dataclass | 12 @dataclass |
10 class VideoFile: | 13 class VideoFile: |
11 diskPath: Path | 14 diskPath: Path |
41 | 44 |
42 def findSubdirs(self, subdir: str) -> Iterable: | 45 def findSubdirs(self, subdir: str) -> Iterable: |
43 if subdir[0] != '/': raise ValueError | 46 if subdir[0] != '/': raise ValueError |
44 here = self.top / subdir[1:] | 47 here = self.top / subdir[1:] |
45 for p in here.iterdir(): | 48 for p in here.iterdir(): |
46 if p.is_dir() and p.name not in {'_thumb'}: | 49 if p.is_dir() and p.name not in IGNORE: |
47 yield { | 50 yield { |
48 'label': p.name, | 51 'label': p.name, |
49 'path': '/' + str(p.relative_to(self.top)) | 52 'path': '/' + str(p.relative_to(self.top)) |
50 } | 53 } |
51 | 54 |
72 raise ValueError(f'{p} exists') | 75 raise ValueError(f'{p} exists') |
73 data = b'' | 76 data = b'' |
74 for c in chunks: | 77 for c in chunks: |
75 data += c | 78 data += c |
76 p.write_bytes(data) | 79 p.write_bytes(data) |
80 | |
81 def folderTree(self): | |
82 out = {'name': 'TOP'} | |
83 | |
84 def fill(node: dict, pathToHere: Path): | |
85 for subName in sorted(os.listdir(pathToHere)): | |
86 if subName in IGNORE: | |
87 continue | |
88 subDir = pathToHere / subName | |
89 if subDir.is_dir(): | |
90 subNode = {'name': subName} | |
91 node.setdefault('children', []).append(subNode) | |
92 fill(subNode, subDir) | |
93 | |
94 fill(out, self.top) | |
95 return out |