|
1 | 1 | from datetime import datetime |
2 | 2 | from enum import Enum, EnumMeta |
3 | 3 | from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple, Union |
| 4 | +from urllib.parse import parse_qs, urlparse |
4 | 5 | from warnings import warn |
5 | 6 |
|
6 | 7 | if TYPE_CHECKING: |
@@ -1736,6 +1737,89 @@ def __init__(self, **data: Any): |
1736 | 1737 | super().__init__(**data) |
1737 | 1738 |
|
1738 | 1739 |
|
| 1740 | +class ListTranscriptParameters(BaseModel): |
| 1741 | + """ |
| 1742 | + The query parameters when listing transcripts. |
| 1743 | + """ |
| 1744 | + |
| 1745 | + after_id: Optional[str] |
| 1746 | + "Get transcripts that were created after this transcript ID" |
| 1747 | + |
| 1748 | + before_id: Optional[str] |
| 1749 | + "Get transcripts that were created before this transcript ID" |
| 1750 | + |
| 1751 | + created_on: Optional[str] |
| 1752 | + "Get only transcripts created on this date" |
| 1753 | + |
| 1754 | + limit: Optional[int] |
| 1755 | + "Maximum amount of transcripts to retrieve. Default is 10" |
| 1756 | + |
| 1757 | + status: Optional[TranscriptStatus] |
| 1758 | + "Filter by transcript status" |
| 1759 | + |
| 1760 | + throttled_only: Optional[bool] |
| 1761 | + "Get only throttled transcripts, overrides the status filter" |
| 1762 | + |
| 1763 | + class Config: |
| 1764 | + use_enum_values = True # Populate the enum value for the query parameters |
| 1765 | + |
| 1766 | + |
| 1767 | +class PageDetails(BaseModel): |
| 1768 | + """ |
| 1769 | + Details of the transcript page. |
| 1770 | + """ |
| 1771 | + |
| 1772 | + current_url: str |
| 1773 | + "The URL used to retrieve the current page of transcripts" |
| 1774 | + |
| 1775 | + limit: int |
| 1776 | + "The number of results this page is limited to" |
| 1777 | + |
| 1778 | + next_url: Optional[str] |
| 1779 | + "The URL to the next page of transcripts. The next URL always points to a page with newer transcripts." |
| 1780 | + |
| 1781 | + prev_url: Optional[str] |
| 1782 | + "The URL to the next page of transcripts. The previous URL always points to a page with older transcripts." |
| 1783 | + |
| 1784 | + result_count: int |
| 1785 | + "The actual number of results in the page" |
| 1786 | + |
| 1787 | + @property |
| 1788 | + def before_id_of_prev_url(self) -> Optional[str]: |
| 1789 | + """ |
| 1790 | + The `before_id` contained in the `prev_url` query params. Can be used as the |
| 1791 | + `ListTranscriptParameters.before_id` for the subsequent `list_transcripts()` call to paginate over results. |
| 1792 | + """ |
| 1793 | + if not self.prev_url: |
| 1794 | + return None |
| 1795 | + parsed_query_params = parse_qs(urlparse(self.prev_url).query) |
| 1796 | + before_id_list = parsed_query_params.get("before_id") |
| 1797 | + return before_id_list[0] if before_id_list else None |
| 1798 | + |
| 1799 | + |
| 1800 | +class TranscriptItem(BaseModel): |
| 1801 | + audio_url: str |
| 1802 | + completed: Optional[str] |
| 1803 | + created: str |
| 1804 | + error: Optional[str] |
| 1805 | + id: str |
| 1806 | + resource_url: str |
| 1807 | + status: TranscriptStatus |
| 1808 | + |
| 1809 | + |
| 1810 | +class ListTranscriptResponse(BaseModel): |
| 1811 | + """ |
| 1812 | + A list of returned transcripts along with page details. |
| 1813 | + Transcripts are sorted from newest to oldest. The previous URL always points to a page with older transcripts. |
| 1814 | + """ |
| 1815 | + |
| 1816 | + page_details: PageDetails |
| 1817 | + "Details of the returned transcript page" |
| 1818 | + |
| 1819 | + transcripts: List[TranscriptItem] |
| 1820 | + "A list of transcripts sorted from newest to oldest" |
| 1821 | + |
| 1822 | + |
1739 | 1823 | class LemurSourceType(str, Enum): |
1740 | 1824 | """ |
1741 | 1825 | The source type of the LeMUR request |
|
0 commit comments