content-core 1.0.0__py3-none-any.whl → 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of content-core might be problematic. Click here for more details.

@@ -1,3 +1,4 @@
1
+ import asyncio
1
2
  import re
2
3
  import ssl
3
4
 
@@ -68,69 +69,86 @@ async def _extract_youtube_id(url):
68
69
 
69
70
 
70
71
  async def get_best_transcript(video_id, preferred_langs=["en", "es", "pt"]):
71
- try:
72
- transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
73
-
74
- # First try: Manual transcripts in preferred languages
75
- manual_transcripts = []
76
- try:
77
- for transcript in transcript_list:
78
- if not transcript.is_generated and not transcript.is_translatable:
79
- manual_transcripts.append(transcript)
80
-
81
- if manual_transcripts:
82
- # Sort based on preferred language order
83
- for lang in preferred_langs:
84
- for transcript in manual_transcripts:
85
- if transcript.language_code == lang:
86
- return transcript.fetch()
87
- # If no preferred language found, return first manual transcript
88
- return manual_transcripts[0].fetch()
89
- except NoTranscriptFound:
90
- pass
91
-
92
- # Second try: Auto-generated transcripts in preferred languages
93
- generated_transcripts = []
94
- try:
95
- for transcript in transcript_list:
96
- if transcript.is_generated and not transcript.is_translatable:
97
- generated_transcripts.append(transcript)
98
-
99
- if generated_transcripts:
100
- # Sort based on preferred language order
101
- for lang in preferred_langs:
102
- for transcript in generated_transcripts:
103
- if transcript.language_code == lang:
104
- return transcript.fetch()
105
- # If no preferred language found, return first generated transcript
106
- return generated_transcripts[0].fetch()
107
- except NoTranscriptFound:
108
- pass
109
-
110
- # Last try: Translated transcripts in preferred languages
111
- translated_transcripts = []
72
+ max_attempts = 5
73
+ for attempt in range(max_attempts):
112
74
  try:
113
- for transcript in transcript_list:
114
- if transcript.is_translatable:
115
- translated_transcripts.append(transcript)
116
-
117
- if translated_transcripts:
118
- # Sort based on preferred language order
119
- for lang in preferred_langs:
120
- for transcript in translated_transcripts:
121
- if transcript.language_code == lang:
122
- return transcript.fetch()
123
- # If no preferred language found, return translation to first preferred language
124
- translation = translated_transcripts[0].translate(preferred_langs[0])
125
- return translation.fetch()
126
- except NoTranscriptFound:
127
- pass
128
-
129
- raise Exception("No suitable transcript found")
130
-
131
- except Exception as e:
132
- logger.error(f"Failed to get transcript for video {video_id}: {e}")
133
- return None
75
+ transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
76
+
77
+ # First try: Manual transcripts in preferred languages
78
+ manual_transcripts = []
79
+ try:
80
+ for transcript in transcript_list:
81
+ if not transcript.is_generated and not transcript.is_translatable:
82
+ manual_transcripts.append(transcript)
83
+
84
+ if manual_transcripts:
85
+ # Sort based on preferred language order
86
+ for lang in preferred_langs:
87
+ for transcript in manual_transcripts:
88
+ if transcript.language_code == lang:
89
+ return transcript.fetch()
90
+ # If no preferred language found, return first manual transcript
91
+ return manual_transcripts[0].fetch()
92
+ except NoTranscriptFound:
93
+ pass
94
+
95
+ # Second try: Auto-generated transcripts in preferred languages
96
+ generated_transcripts = []
97
+ try:
98
+ for transcript in transcript_list:
99
+ if transcript.is_generated and not transcript.is_translatable:
100
+ generated_transcripts.append(transcript)
101
+
102
+ if generated_transcripts:
103
+ # Sort based on preferred language order
104
+ for lang in preferred_langs:
105
+ for transcript in generated_transcripts:
106
+ if transcript.language_code == lang:
107
+ return transcript.fetch()
108
+ # If no preferred language found, return first generated transcript
109
+ return generated_transcripts[0].fetch()
110
+ except NoTranscriptFound:
111
+ pass
112
+
113
+ # Last try: Translated transcripts in preferred languages
114
+ translated_transcripts = []
115
+ try:
116
+ for transcript in transcript_list:
117
+ if transcript.is_translatable:
118
+ translated_transcripts.append(transcript)
119
+
120
+ if translated_transcripts:
121
+ # Sort based on preferred language order
122
+ for lang in preferred_langs:
123
+ for transcript in translated_transcripts:
124
+ if transcript.language_code == lang:
125
+ return transcript.fetch()
126
+ # If no preferred language found, return translation to first preferred language
127
+ translation = translated_transcripts[0].translate(
128
+ preferred_langs[0]
129
+ )
130
+ return translation.fetch()
131
+ except NoTranscriptFound:
132
+ pass
133
+
134
+ raise Exception("No suitable transcript found")
135
+
136
+ except Exception as e:
137
+ if e.__class__.__name__ == "ParserError":
138
+ logger.warning(
139
+ f"ParserError on attempt {attempt+1}/5 for video {video_id}. Retrying..."
140
+ )
141
+ if attempt == max_attempts - 1:
142
+ logger.error(
143
+ f"Failed to get transcript for video {video_id} after {max_attempts} attempts due to repeated ParserError."
144
+ )
145
+ return None
146
+ await asyncio.sleep(2)
147
+ continue
148
+ else:
149
+ logger.error(f"Failed to get transcript for video {video_id}: {e}")
150
+ return None
151
+ return None
134
152
 
135
153
 
136
154
  async def extract_youtube_transcript(state: ProcessSourceState):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: content-core
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Extract what matters from any media source
5
5
  Author-email: LUIS NOVO <lfnovo@gmail.com>
6
6
  License-File: LICENSE
@@ -27,13 +27,13 @@ content_core/processors/pdf.py,sha256=9jf-eROAqw6yQwdlbsxPXsaJXY26hVG7nSTPH9n4af
27
27
  content_core/processors/text.py,sha256=kKHA60-NYjLmCTYUnk8TdJxQQ0Shkg-K61Ezqaelz7k,1158
28
28
  content_core/processors/url.py,sha256=6WT8Sw2VHiKyhgWXi_jZjKjwnT_QPSPcH4P99RKbjgU,7521
29
29
  content_core/processors/video.py,sha256=3WnZwTswvTLm8PtQhKwoqJ2BH6YZi62dMUjALwJiebo,5196
30
- content_core/processors/youtube.py,sha256=g_A-rv5bzq2GIuwqMH70YAnDK-4BZqpgQP0IQ3j9zXE,6340
30
+ content_core/processors/youtube.py,sha256=pLyNy6ebz80T0e-XnBnj36o22Gm4s_jfjkGCNtKz0so,7254
31
31
  content_core/tools/__init__.py,sha256=DuJmd7fE-NpDvLP8IW1XY5MUkAQcdks52rn2jk4N8jQ,231
32
32
  content_core/tools/cleanup.py,sha256=5IdKedsFyRQMdYzgFSKtsfyxJldbroXQXHesHICNENI,523
33
33
  content_core/tools/extract.py,sha256=-r2_jsuMMXyXxGVqWhh1ilNPo_UMYAbw3Pkp1FzPy5g,577
34
34
  content_core/tools/summarize.py,sha256=DPfeglLWB08q8SvHrsKpOKZ35XjduUDs2J02ISwjdj0,596
35
- content_core-1.0.0.dist-info/METADATA,sha256=0TBaT17WQQ3u3YKX4dZYGXLkvnnyFwuxe1Z5uHQr9rQ,11819
36
- content_core-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
37
- content_core-1.0.0.dist-info/entry_points.txt,sha256=9fGQUk6bxBVXj9PRwfWVPn54ClSEJV7J-KBLXtjOhQw,99
38
- content_core-1.0.0.dist-info/licenses/LICENSE,sha256=myj0z2T4qIkenCgLsRfx7Wk6UqCQNj5c7O14Qx4zpGg,1066
39
- content_core-1.0.0.dist-info/RECORD,,
35
+ content_core-1.0.1.dist-info/METADATA,sha256=ANYJN5e0FUF1rozZd1dpbncKwHiUJlLlu_DsF43DDAE,11819
36
+ content_core-1.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
37
+ content_core-1.0.1.dist-info/entry_points.txt,sha256=9fGQUk6bxBVXj9PRwfWVPn54ClSEJV7J-KBLXtjOhQw,99
38
+ content_core-1.0.1.dist-info/licenses/LICENSE,sha256=myj0z2T4qIkenCgLsRfx7Wk6UqCQNj5c7O14Qx4zpGg,1066
39
+ content_core-1.0.1.dist-info/RECORD,,