13 Commits
new ... master

Author SHA1 Message Date
9842e52806 chore: make youtube_transcript_downloader.py executable
Changed the file mode from 100644 (non-executable) to 100755 (executable) to allow the script to be run directly.
2026-04-07 13:01:17 -04:00
b7eabcaa07 Delete generated_transcripts/transcript_v75iZrtI6hw_translated.txt 2026-04-07 12:50:02 -04:00
592ac93d40 Delete generated_transcripts/transcript_TWV4JQtGxTA.txt 2026-04-07 12:49:56 -04:00
2b6d608618 feat: add generated transcript and update gitignore pattern
- Add new transcript file `generated_transcripts/transcript_TWV4JQtGxTA.txt` containing 946 lines of content
- Update .gitignore to ignore transcript files in root directory with leading slash pattern
2026-04-07 12:48:18 -04:00
423b9250c5 chore(language-codes): add English words and adjust detection threshold
- Added 'has', 'acquire', and 'without' to COMMON_ENGLISH_WORDS dictionary
- Modified is_english detection threshold from 0.05 to 0.04 matches ratio
- Added debug logging to show matches count during English detection
2026-04-07 12:43:06 -04:00
6138018fa3 feat: centralize common English words for language detection
Move COMMON_ENGLISH_WORDS set from youtube_transcript_downloader.py to language_codes.py as a shared constant. This improves code organization and reusability, allowing other modules to reference the same word list for English language detection.
2026-04-07 12:27:49 -04:00
98b1a676cb feat: centralize common English words for language detection
Move COMMON_ENGLISH_WORDS set from youtube_transcript_downloader.py to language_codes.py as a shared constant. This improves code organization and reusability, allowing other modules to reference the same word list for English language detection
2026-04-07 12:24:52 -04:00
25e9e36372 remove unused function 2026-04-07 12:22:42 -04:00
98b76e8f23 Delete __pycache__/youtube_transcript_downloader.cpython-312.pyc 2026-04-07 12:19:38 -04:00
6a0881e1ee Merge branch 'new' 2026-04-07 12:18:50 -04:00
d07b46561a Add comprehensive YouTube language codes arrays for transcript downloader 2026-04-07 12:12:20 -04:00
c3051c1c12 Refine download_captions function with enhanced fallback languages and better error handling 2026-04-07 11:53:49 -04:00
f14665d47d Add download_captions function to download YouTube captions with English preference 2026-04-07 11:33:30 -04:00
4 changed files with 21 additions and 38 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
__pycache__
transcript_*.txt
/transcript_*.txt

View File

@@ -24,6 +24,19 @@ COMMON_FALLBACK_LANGUAGES = [
ENGLISH_LANGUAGES = ['en', 'en-US', 'en-GB']
# This can be used as the list of allowed fallback languages
ALLOWED_FALLBACK_LANGUAGES = COMMON_FALLBACK_LANGUAGES
COMMON_ENGLISH_WORDS = {
'the', 'be', 'to', 'of', 'and', 'a', 'in', 'that','has','acquire', 'have', 'i',
'it', 'for', 'not', 'on', 'with', 'he', 'as', 'you', 'do', 'at',
'this', 'but', 'his', 'by', 'from', 'they', 'we', 'say', 'her',
'she', 'or', 'an', 'will', 'my', 'one', 'all', 'would', 'there',
'their', 'what', 'so', 'up', 'out', 'if', 'about', 'who', 'get',
'which', 'go', 'me', 'when', 'make', 'can', 'like', 'time', 'no',
'just', 'him', 'know', 'take', 'people', 'into', 'year', 'your',
'good', 'some', 'could', 'them', 'see', 'other', 'than', 'then',
'now', 'look', 'only', 'come', 'its', 'over', 'think', 'also',
'back', 'after', 'use', 'two', 'how', 'our', 'work', 'first', 'well',
'way', 'even', 'new', 'want', 'because', 'any', 'these', 'give', 'day', 'without'
}
if __name__ == "__main__":
print("YouTube Language Codes:")

44
youtube_transcript_downloader.py Normal file → Executable file
View File

@@ -19,36 +19,17 @@ def extract_video_id(url):
patterns = [
r'(?:v=|\/)([0-9A-Za-z_-]{11}).*',
r'youtu\.be\/([0-9A-Za-z_-]{11})',
r'([0-9A-Za-z_-]{11})'
]
for pattern in patterns:
match = re.search(pattern, url)
if match:
return match.group(1)
return None
def get_transcript(video_id, languages=None):
"""
Get transcript for a YouTube video.
Args:
video_id: The YouTube video ID
languages: List of language codes to try (default: ['en', 'en-US'])
Returns:
Transcript object or None if not found
"""
if languages is None:
languages = ['en', 'en-US']
try:
transcript = YouTubeTranscriptApi().fetch(video_id, languages=languages)
return transcript
except Exception as e:
print(f"Error getting transcript: {e}")
return None
def get_transcript_text(transcript):
"""Extract plain text from transcript."""
@@ -212,26 +193,15 @@ def main():
def is_english(text):
"""Simple check to determine if text is likely English."""
# Common English words to check against
common_english_words = {
'the', 'be', 'to', 'of', 'and', 'a', 'in', 'that', 'have', 'i',
'it', 'for', 'not', 'on', 'with', 'he', 'as', 'you', 'do', 'at',
'this', 'but', 'his', 'by', 'from', 'they', 'we', 'say', 'her',
'she', 'or', 'an', 'will', 'my', 'one', 'all', 'would', 'there',
'their', 'what', 'so', 'up', 'out', 'if', 'about', 'who', 'get',
'which', 'go', 'me', 'when', 'make', 'can', 'like', 'time', 'no',
'just', 'him', 'know', 'take', 'people', 'into', 'year', 'your',
'good', 'some', 'could', 'them', 'see', 'other', 'than', 'then',
'now', 'look', 'only', 'come', 'its', 'over', 'think', 'also',
'back', 'after', 'use', 'two', 'how', 'our', 'work', 'first', 'well',
'way', 'even', 'new', 'want', 'because', 'any', 'these', 'give', 'day'
}
# Simple heuristic: count common English words
words = set(text.lower().split())
matches = sum(1 for word in words if word in common_english_words)
matches = sum(1 for word in words if word in language_codes.COMMON_ENGLISH_WORDS)
word_count = len(words)
print(f"found matches: {matches} out of {word_count} words")
# If we find many common English words, it's likely English
return matches > len(words) * 0.05 if words else False
return matches > len(words) * 0.04 if words else False
def download_captions(video_id):