Skip to content

feat: Google Docs, Files, PDF URLs need to be converted for their export URL #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docling_core/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from io import BytesIO
from pathlib import Path
from typing import Dict, Optional, Union

import re
import requests
from pydantic import AnyHttpUrl, TypeAdapter, ValidationError
from typing_extensions import deprecated
Expand Down Expand Up @@ -76,6 +76,17 @@ def resolve_source_to_stream(
agent_name = f"docling-core/{importlib.metadata.version('docling-core')}"
req_headers["user-agent"] = agent_name



# Google Docs, Files, PDF URLs need to be converted for their export extraction
googleDocId = re.search(r'google\.com\/(file|document)\/d\/([\w-]+)', http_url)
if googleDocId:
if googleDocId.group(1) == 'file':
http_url = f'https://drive.google.com/uc?export=download&id={googleDocId.group(2)}'
else:
http_url = f'https://docs.google.com/document/d/{googleDocId.group(2)}/export?format=docx'


# fetch the page
res = requests.get(http_url, stream=True, headers=req_headers)
res.raise_for_status()
Expand Down