Upload 8 files
Browse files- data/db/videos.db +0 -0
- databases.py +46 -6
- page_modules/analyze_audiodescriptions.py +7 -1
data/db/videos.db
CHANGED
|
Binary files a/data/db/videos.db and b/data/db/videos.db differ
|
|
|
databases.py
CHANGED
|
@@ -565,7 +565,10 @@ def get_audiodescription(sha1sum: str, version: str) -> Optional[sqlite3.Row]:
|
|
| 565 |
return None
|
| 566 |
|
| 567 |
|
| 568 |
-
def get_videos_from_audiodescriptions(
|
|
|
|
|
|
|
|
|
|
| 569 |
"""Retorna vídeos disponibles segons audiodescriptions.db i videos.db.
|
| 570 |
|
| 571 |
1) Llegeix demo/temp/db/audiodescriptions.db i obté els DISTINCT sha1sum.
|
|
@@ -587,7 +590,15 @@ def get_videos_from_audiodescriptions() -> List[Dict[str, Any]]:
|
|
| 587 |
if not sha1_list:
|
| 588 |
return []
|
| 589 |
|
| 590 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
result: List[Dict[str, Any]] = []
|
| 592 |
try:
|
| 593 |
with _connect_videos_db() as vconn:
|
|
@@ -595,12 +606,18 @@ def get_videos_from_audiodescriptions() -> List[Dict[str, Any]]:
|
|
| 595 |
for sha1 in sha1_list:
|
| 596 |
try:
|
| 597 |
row = vcur.execute(
|
| 598 |
-
"SELECT video_name FROM videos WHERE sha1sum = ? LIMIT 1",
|
| 599 |
(sha1,),
|
| 600 |
).fetchone()
|
| 601 |
-
if row is
|
| 602 |
-
|
| 603 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 604 |
# Sense nom humà, ignorem aquest vídeo al desplegable
|
| 605 |
continue
|
| 606 |
except sqlite3.OperationalError:
|
|
@@ -611,6 +628,29 @@ def get_videos_from_audiodescriptions() -> List[Dict[str, Any]]:
|
|
| 611 |
if vname == sha1:
|
| 612 |
continue
|
| 613 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 614 |
result.append({"sha1sum": sha1, "video_name": vname})
|
| 615 |
except sqlite3.OperationalError:
|
| 616 |
# Si videos.db no existeix o té un esquema incompatible, no retornem res
|
|
|
|
| 565 |
return None
|
| 566 |
|
| 567 |
|
| 568 |
+
def get_videos_from_audiodescriptions(
|
| 569 |
+
session_id: str | None = None,
|
| 570 |
+
role: str | None = None,
|
| 571 |
+
) -> List[Dict[str, Any]]:
|
| 572 |
"""Retorna vídeos disponibles segons audiodescriptions.db i videos.db.
|
| 573 |
|
| 574 |
1) Llegeix demo/temp/db/audiodescriptions.db i obté els DISTINCT sha1sum.
|
|
|
|
| 590 |
if not sha1_list:
|
| 591 |
return []
|
| 592 |
|
| 593 |
+
# Determinar telèfon associat a la sessió actual (si aplica)
|
| 594 |
+
session_phone: str = ""
|
| 595 |
+
if session_id:
|
| 596 |
+
try:
|
| 597 |
+
_, session_phone = get_latest_user_phone_for_session(session_id)
|
| 598 |
+
except sqlite3.OperationalError:
|
| 599 |
+
session_phone = ""
|
| 600 |
+
|
| 601 |
+
# Map sha1sum -> video_name utilitzant videos.db, amb filtres de visibility/rol/phone
|
| 602 |
result: List[Dict[str, Any]] = []
|
| 603 |
try:
|
| 604 |
with _connect_videos_db() as vconn:
|
|
|
|
| 606 |
for sha1 in sha1_list:
|
| 607 |
try:
|
| 608 |
row = vcur.execute(
|
| 609 |
+
"SELECT video_name, visibility, owner FROM videos WHERE sha1sum = ? LIMIT 1",
|
| 610 |
(sha1,),
|
| 611 |
).fetchone()
|
| 612 |
+
if row is None:
|
| 613 |
+
# Sense registre a videos.db, ignorem aquest sha1
|
| 614 |
+
continue
|
| 615 |
+
|
| 616 |
+
vname = str(row["video_name"]) if row["video_name"] else ""
|
| 617 |
+
visibility_val = str(row["visibility"] or "").strip().lower()
|
| 618 |
+
owner_val = str(row["owner"] or "").strip()
|
| 619 |
+
|
| 620 |
+
if not vname:
|
| 621 |
# Sense nom humà, ignorem aquest vídeo al desplegable
|
| 622 |
continue
|
| 623 |
except sqlite3.OperationalError:
|
|
|
|
| 628 |
if vname == sha1:
|
| 629 |
continue
|
| 630 |
|
| 631 |
+
# Regles d'accés segons visibility + rol + telèfon de sessió
|
| 632 |
+
is_public = visibility_val == "public"
|
| 633 |
+
is_private = visibility_val == "private" or not visibility_val
|
| 634 |
+
|
| 635 |
+
allowed = False
|
| 636 |
+
if is_public:
|
| 637 |
+
allowed = True
|
| 638 |
+
else:
|
| 639 |
+
# Vídeos privats
|
| 640 |
+
if role in {"verd", "blau"}:
|
| 641 |
+
# Administrador i revisor veuen tots els privats
|
| 642 |
+
allowed = True
|
| 643 |
+
elif role == "groc":
|
| 644 |
+
# Col·laborador verificat només si el seu telèfon coincideix amb owner
|
| 645 |
+
if session_phone and owner_val and session_phone == owner_val:
|
| 646 |
+
allowed = True
|
| 647 |
+
else:
|
| 648 |
+
# Altres rols (taronja, vermell, o desconegut) no veuen privats
|
| 649 |
+
allowed = False
|
| 650 |
+
|
| 651 |
+
if not allowed:
|
| 652 |
+
continue
|
| 653 |
+
|
| 654 |
result.append({"sha1sum": sha1, "video_name": vname})
|
| 655 |
except sqlite3.OperationalError:
|
| 656 |
# Si videos.db no existeix o té un esquema incompatible, no retornem res
|
page_modules/analyze_audiodescriptions.py
CHANGED
|
@@ -182,7 +182,13 @@ def render_analyze_audiodescriptions_page(api, permissions: Dict[str, bool]) ->
|
|
| 182 |
st.header("Analitzar audiodescripcions")
|
| 183 |
|
| 184 |
# Llista de vídeos disponibles segons demo/temp/db/audiodescriptions.db
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
# Base de media: demo/temp/media/<sha1sum>
|
| 188 |
base_dir = Path(__file__).resolve().parent.parent
|
|
|
|
| 182 |
st.header("Analitzar audiodescripcions")
|
| 183 |
|
| 184 |
# Llista de vídeos disponibles segons demo/temp/db/audiodescriptions.db
|
| 185 |
+
# i els permisos de visibilitat/rol de l'usuari actual
|
| 186 |
+
session_id = st.session_state.get("session_id", "")
|
| 187 |
+
role = None
|
| 188 |
+
if st.session_state.get("user") and isinstance(st.session_state.get("user"), dict):
|
| 189 |
+
role = st.session_state["user"].get("role")
|
| 190 |
+
|
| 191 |
+
accessible_rows = get_videos_from_audiodescriptions(session_id=session_id or None, role=role)
|
| 192 |
|
| 193 |
# Base de media: demo/temp/media/<sha1sum>
|
| 194 |
base_dir = Path(__file__).resolve().parent.parent
|