Pass in user session for nndownload
This commit is contained in:
		
					parent
					
						
							
								1ce10dfae4
							
						
					
				
			
			
				commit
				
					
						fe5c547055
					
				
			
		
					 1 changed files with 8 additions and 2 deletions
				
			
		
							
								
								
									
										10
									
								
								app.py
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								app.py
									
										
									
									
									
								
							|  | @ -32,9 +32,11 @@ CACHE_SIZE_LIMIT = 100 * 1024 * 1024  # 100 MB | ||||||
| 
 | 
 | ||||||
| cache = None if os.environ.get('NICONICOGAY_DISABLE_CACHE', '') != '' else Cache("disk_cache", size_limit=CACHE_SIZE_LIMIT) | cache = None if os.environ.get('NICONICOGAY_DISABLE_CACHE', '') != '' else Cache("disk_cache", size_limit=CACHE_SIZE_LIMIT) | ||||||
| 
 | 
 | ||||||
|  | user_session = None | ||||||
| cookie_jar = http.cookiejar.MozillaCookieJar('cookies.txt') | cookie_jar = http.cookiejar.MozillaCookieJar('cookies.txt') | ||||||
| try: | try: | ||||||
|     cookie_jar.load(ignore_discard=True, ignore_expires=True) |     cookie_jar.load(ignore_discard=True, ignore_expires=True) | ||||||
|  |     user_session = next((cookie.value for cookie in cookie_jar if cookie.name == 'user_session'), None) | ||||||
| except FileNotFoundError: | except FileNotFoundError: | ||||||
|     logger.warning("cookies.txt not found, starting with empty cookie jar") |     logger.warning("cookies.txt not found, starting with empty cookie jar") | ||||||
| 
 | 
 | ||||||
|  | @ -79,13 +81,17 @@ def download_and_upload_video(video_id, url, video_quality): | ||||||
|          |          | ||||||
|         try: |         try: | ||||||
|             logger.info(f"Starting download for video ID: {video_id}") |             logger.info(f"Starting download for video ID: {video_id}") | ||||||
|             nndownload.execute( |             nndownload_args = [ | ||||||
|                 "--no-login", |                 "--no-login", | ||||||
|                 "--user-agent", "Googlebot/2.1", |                 "--user-agent", "Googlebot/2.1", | ||||||
|                 "--video-quality", video_quality, |                 "--video-quality", video_quality, | ||||||
|                 "--output-path", temp_path, |                 "--output-path", temp_path, | ||||||
|                 url |                 url | ||||||
|             ) |             ] | ||||||
|  |             if user_session: | ||||||
|  |                 nndownload_args += ["--session-cookie", user_session] | ||||||
|  |                 nndownload_args = nndownload_args[1:] | ||||||
|  |             nndownload.execute(*nndownload_args) | ||||||
|              |              | ||||||
|             if os.path.exists(temp_path) and s3_client: |             if os.path.exists(temp_path) and s3_client: | ||||||
|                 logger.info(f"Downloaded video {video_id}, uploading to CDN") |                 logger.info(f"Downloaded video {video_id}, uploading to CDN") | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue