Spaces:
Sleeping
Sleeping
Meilleure détection de word et pdf
Browse files
app.py
CHANGED
|
@@ -2698,36 +2698,54 @@ else:
|
|
| 2698 |
st.markdown("---")
|
| 2699 |
st.markdown("**Ajouter un document (max 50 Mo) depuis un lien public**")
|
| 2700 |
|
| 2701 |
-
|
| 2702 |
-
|
| 2703 |
-
def make_direct_link(file_url: str) -> str:
|
| 2704 |
"""
|
| 2705 |
-
Convertit les liens Google Drive / Dropbox / OneDrive en liens directs téléchargeables.
|
|
|
|
| 2706 |
Retourne le lien original si aucun cas particulier n'est détecté.
|
| 2707 |
"""
|
| 2708 |
-
|
| 2709 |
-
|
| 2710 |
-
|
| 2711 |
-
|
| 2712 |
-
|
| 2713 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2714 |
else:
|
| 2715 |
-
|
|
|
|
| 2716 |
if file_id:
|
| 2717 |
return f"https://drive.google.com/uc?export=download&id={file_id}"
|
|
|
|
| 2718 |
|
| 2719 |
# --- Dropbox ---
|
| 2720 |
-
if "dropbox.com" in
|
| 2721 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2722 |
|
| 2723 |
# --- OneDrive ---
|
| 2724 |
-
if "1drv.ms" in
|
| 2725 |
-
if "
|
| 2726 |
-
|
| 2727 |
-
|
| 2728 |
-
return
|
| 2729 |
-
|
| 2730 |
-
|
|
|
|
| 2731 |
|
| 2732 |
file_url = st.text_input(
|
| 2733 |
"🔗 Collez ici le lien public vers votre document (Google Drive, Dropbox, OneDrive, etc.) :",
|
|
|
|
| 2698 |
st.markdown("---")
|
| 2699 |
st.markdown("**Ajouter un document (max 50 Mo) depuis un lien public**")
|
| 2700 |
|
| 2701 |
+
def make_direct_link(file_url: str, prefer_format: str = "docx") -> str:
|
|
|
|
|
|
|
| 2702 |
"""
|
| 2703 |
+
Convertit les liens Google Docs / Google Drive / Dropbox / OneDrive en liens directs téléchargeables.
|
| 2704 |
+
- prefer_format: "docx" ou "pdf" pour Google Docs.
|
| 2705 |
Retourne le lien original si aucun cas particulier n'est détecté.
|
| 2706 |
"""
|
| 2707 |
+
u = file_url.strip()
|
| 2708 |
+
|
| 2709 |
+
# --- Google Docs (document, pas un fichier Drive) ---
|
| 2710 |
+
if "docs.google.com/document" in u:
|
| 2711 |
+
m = re.search(r"/document/d/([^/]+)/", u)
|
| 2712 |
+
doc_id = m.group(1) if m else None
|
| 2713 |
+
if doc_id:
|
| 2714 |
+
fmt = "docx" if prefer_format == "docx" else "pdf"
|
| 2715 |
+
return f"https://docs.google.com/document/d/{doc_id}/export?format={fmt}"
|
| 2716 |
+
return u
|
| 2717 |
+
|
| 2718 |
+
# --- Google Drive (fichiers) ---
|
| 2719 |
+
if "drive.google.com" in u:
|
| 2720 |
+
file_id = None
|
| 2721 |
+
if "/d/" in u:
|
| 2722 |
+
file_id = u.split("/d/")[1].split("/")[0]
|
| 2723 |
else:
|
| 2724 |
+
qs_id = parse_qs(urlparse(u).query).get("id", [None])[0]
|
| 2725 |
+
file_id = qs_id or file_id
|
| 2726 |
if file_id:
|
| 2727 |
return f"https://drive.google.com/uc?export=download&id={file_id}"
|
| 2728 |
+
return u
|
| 2729 |
|
| 2730 |
# --- Dropbox ---
|
| 2731 |
+
if "dropbox.com" in u:
|
| 2732 |
+
parsed = urlparse(u)
|
| 2733 |
+
# Force le download binaire
|
| 2734 |
+
if "dl=" in parsed.query:
|
| 2735 |
+
return re.sub(r"dl=\d", "dl=1", u)
|
| 2736 |
+
# sinon ajouter dl=1
|
| 2737 |
+
sep = "&" if parsed.query else "?"
|
| 2738 |
+
return u + f"{sep}dl=1"
|
| 2739 |
|
| 2740 |
# --- OneDrive ---
|
| 2741 |
+
if "1drv.ms" in u or "onedrive.live.com" in u:
|
| 2742 |
+
if "download=" not in u:
|
| 2743 |
+
parsed = urlparse(u)
|
| 2744 |
+
sep = "&" if parsed.query else "?"
|
| 2745 |
+
return u + f"{sep}download=1"
|
| 2746 |
+
return u
|
| 2747 |
+
|
| 2748 |
+
return u
|
| 2749 |
|
| 2750 |
file_url = st.text_input(
|
| 2751 |
"🔗 Collez ici le lien public vers votre document (Google Drive, Dropbox, OneDrive, etc.) :",
|