Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	Commit 
							
							·
						
						342ea2f
	
1
								Parent(s):
							
							5bea760
								
Add optional Webshare usage
Browse files
    	
        app/services/video_service.py
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
         | 
|
| 1 | 
         
             
            import uuid
         
     | 
| 2 | 
         
             
            from typing import List, Dict, Any, Optional
         
     | 
| 3 | 
         
             
            import re
         
     | 
| 
         @@ -5,6 +6,7 @@ from datetime import datetime 
     | 
|
| 5 | 
         
             
            from sentence_transformers import SentenceTransformer
         
     | 
| 6 | 
         
             
            from qdrant_client.http import models
         
     | 
| 7 | 
         
             
            from youtube_transcript_api import YouTubeTranscriptApi
         
     | 
| 
         | 
|
| 8 | 
         
             
            import yt_dlp
         
     | 
| 9 | 
         
             
            from app.models.video import VideoSegment, Video, SearchResult
         
     | 
| 10 | 
         
             
            from app.services.qdrant_service import qdrant_client
         
     | 
| 
         @@ -171,7 +173,18 @@ def get_video_transcript(video_id: str) -> List[Dict[str, Any]]: 
     | 
|
| 171 | 
         | 
| 172 | 
         
             
                try:
         
     | 
| 173 | 
         
             
                    # Try to get available transcript languages
         
     | 
| 174 | 
         
            -
                     
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 175 | 
         | 
| 176 | 
         
             
                    # First, look for English transcript
         
     | 
| 177 | 
         
             
                    english_transcript = None
         
     | 
| 
         | 
|
| 1 | 
         
            +
            import os
         
     | 
| 2 | 
         
             
            import uuid
         
     | 
| 3 | 
         
             
            from typing import List, Dict, Any, Optional
         
     | 
| 4 | 
         
             
            import re
         
     | 
| 
         | 
|
| 6 | 
         
             
            from sentence_transformers import SentenceTransformer
         
     | 
| 7 | 
         
             
            from qdrant_client.http import models
         
     | 
| 8 | 
         
             
            from youtube_transcript_api import YouTubeTranscriptApi
         
     | 
| 9 | 
         
            +
            from youtube_transcript_api.proxies import WebshareProxyConfig
         
     | 
| 10 | 
         
             
            import yt_dlp
         
     | 
| 11 | 
         
             
            from app.models.video import VideoSegment, Video, SearchResult
         
     | 
| 12 | 
         
             
            from app.services.qdrant_service import qdrant_client
         
     | 
| 
         | 
|
| 173 | 
         | 
| 174 | 
         
             
                try:
         
     | 
| 175 | 
         
             
                    # Try to get available transcript languages
         
     | 
| 176 | 
         
            +
                    webshare_username = os.environ.get("WEBSHARE_USERNAME")
         
     | 
| 177 | 
         
            +
                    webshare_password = os.environ.get("WEBSHARE_PASSWORD")
         
     | 
| 178 | 
         
            +
                    if webshare_username and webshare_password:
         
     | 
| 179 | 
         
            +
                        yt_transcript_api = YouTubeTranscriptApi(
         
     | 
| 180 | 
         
            +
                            proxy_config=WebshareProxyConfig(
         
     | 
| 181 | 
         
            +
                                proxy_username=webshare_username,
         
     | 
| 182 | 
         
            +
                                proxy_password=webshare_password,
         
     | 
| 183 | 
         
            +
                            )
         
     | 
| 184 | 
         
            +
                        )
         
     | 
| 185 | 
         
            +
                    else:
         
     | 
| 186 | 
         
            +
                        yt_transcript_api = YouTubeTranscriptApi()
         
     | 
| 187 | 
         
            +
                    transcript_list = yt_transcript_api.list(video_id)
         
     | 
| 188 | 
         | 
| 189 | 
         
             
                    # First, look for English transcript
         
     | 
| 190 | 
         
             
                    english_transcript = None
         
     |