Omar-youssef commited on
Commit
6ae0a89
·
1 Parent(s): b6d644c
Files changed (2) hide show
  1. app.py +3 -2
  2. link_processor.py +20 -25
app.py CHANGED
@@ -31,7 +31,7 @@ def download_file_button(file_path, label, file_name, mime_type):
31
  ):
32
  # Reset the processing state after download
33
  st.session_state.processing_complete = False
34
- st.rerun()
35
 
36
 
37
  def reset_processing_state():
@@ -271,7 +271,8 @@ with tab3:
271
  if st.session_state.processing_complete:
272
  if st.button("Process Another File"):
273
  reset_processing_state()
274
- st.rerun()
 
275
 
276
  # Sidebar
277
  with st.sidebar:
 
31
  ):
32
  # Reset the processing state after download
33
  st.session_state.processing_complete = False
34
+ st.experimental_rerun()
35
 
36
 
37
  def reset_processing_state():
 
271
  if st.session_state.processing_complete:
272
  if st.button("Process Another File"):
273
  reset_processing_state()
274
+ st.experimental_rerun()
275
+
276
 
277
  # Sidebar
278
  with st.sidebar:
link_processor.py CHANGED
@@ -24,7 +24,7 @@ class LinkDownloader:
24
  temp_filename = 'downloaded_video.%(ext)s'
25
  temp_filepath = str(self.output_dir / temp_filename)
26
 
27
- # Configure yt-dlp options with more robust authentication handling
28
  ydl_opts = {
29
  'format': 'best',
30
  'outtmpl': temp_filepath,
@@ -33,31 +33,29 @@ class LinkDownloader:
33
  'extract_audio': False,
34
  'ignoreerrors': True, # Continue on download errors
35
  'no_check_certificate': True, # Skip HTTPS certificate validation
36
- 'username': None, # Will be filled by user if needed
37
- 'password': None, # Will be filled by user if needed
38
  }
39
 
40
- # First try without authentication
41
- try:
42
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
43
  info = ydl.extract_info(url, download=False)
44
- if info:
45
- ydl.download([url])
46
- except yt_dlp.utils.DownloadError as e:
47
- if "Sign in" in str(e):
48
- # If authentication is required, prompt for credentials
49
- st.warning("Authentication required. Please enter your YouTube credentials.")
50
- username = st.text_input("YouTube Email", key="yt_email")
51
- password = st.text_input("YouTube Password", type="password", key="yt_pass")
52
 
53
- if username and password:
54
- ydl_opts['username'] = username
55
- ydl_opts['password'] = password
56
 
57
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
58
- info = ydl.extract_info(url, download=True)
59
- else:
60
- raise e
 
 
 
 
 
 
 
61
 
62
  # Get the actual extension and filepath
63
  ext = info.get('ext', 'mp4')
@@ -65,13 +63,10 @@ class LinkDownloader:
65
 
66
  # Verify file exists
67
  if not os.path.exists(actual_filepath):
68
- print(f"Files in directory: {os.listdir(self.output_dir)}")
69
  raise FileNotFoundError(f"Downloaded file not found at {actual_filepath}")
70
 
71
- print(f"File size: {os.path.getsize(actual_filepath)} bytes")
72
  return actual_filepath
73
 
74
  except Exception as e:
75
  st.error(f"Error during download: {str(e)}")
76
- print(f"Download error details: {str(e)}")
77
- return None
 
24
  temp_filename = 'downloaded_video.%(ext)s'
25
  temp_filepath = str(self.output_dir / temp_filename)
26
 
27
+ # Configure yt-dlp options
28
  ydl_opts = {
29
  'format': 'best',
30
  'outtmpl': temp_filepath,
 
33
  'extract_audio': False,
34
  'ignoreerrors': True, # Continue on download errors
35
  'no_check_certificate': True, # Skip HTTPS certificate validation
 
 
36
  }
37
 
38
+ # Try to extract video information
39
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
40
+ try:
41
  info = ydl.extract_info(url, download=False)
42
+ if not info:
43
+ raise ValueError("Failed to extract video information.")
 
 
 
 
 
 
44
 
45
+ # Download video
46
+ ydl.download([url])
 
47
 
48
+ except yt_dlp.utils.DownloadError as e:
49
+ if "Sign in" in str(e):
50
+ st.warning("Authentication required. Please pass cookies from your browser.")
51
+ st.info(
52
+ "Follow the instructions at "
53
+ "[yt-dlp FAQ](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp) "
54
+ "to pass cookies for authentication."
55
+ )
56
+ return None
57
+ else:
58
+ raise e
59
 
60
  # Get the actual extension and filepath
61
  ext = info.get('ext', 'mp4')
 
63
 
64
  # Verify file exists
65
  if not os.path.exists(actual_filepath):
 
66
  raise FileNotFoundError(f"Downloaded file not found at {actual_filepath}")
67
 
 
68
  return actual_filepath
69
 
70
  except Exception as e:
71
  st.error(f"Error during download: {str(e)}")
72
+ return None