ujwal55 commited on
Commit
16ae63f
·
1 Parent(s): a70e756

fixed error in app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -32,7 +32,7 @@ def run_cmd(cmd: list[str], timeout: int = 120) -> bool:
32
  )
33
  return True
34
  except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
35
- print(f"Command failed: {' '.join(cmd[:3])}... - {str(e)}")
36
  return False
37
 
38
  def yt_urls(query: str, max_results: int) -> List[str]:
@@ -54,11 +54,12 @@ def dl_video(url: str, out: Path) -> bool:
54
  out.parent.mkdir(exist_ok=True)
55
  cmd = [
56
  "yt-dlp",
57
- "-f", "worst[height<=480]/worst", # Lower quality for HF Spaces
58
  "--merge-output-format", "mp4",
59
  "-o", str(out),
60
  "--max-duration", str(MAX_VIDEO_LENGTH),
61
  "--no-playlist",
 
62
  url,
63
  ]
64
  return run_cmd(cmd, timeout=60)
@@ -66,7 +67,9 @@ def dl_video(url: str, out: Path) -> bool:
66
  def make_card(text: str, out: Path, dur: int = TITLE_DUR) -> bool:
67
  """Create title card with text"""
68
  # Wrap text for better display
69
- wrapped = "\\n".join(textwrap.wrap(text, width=25))
 
 
70
 
71
  cmd = [
72
  "ffmpeg",
@@ -74,7 +77,7 @@ def make_card(text: str, out: Path, dur: int = TITLE_DUR) -> bool:
74
  "-f", "lavfi", "-i", f"color=c=navy:s={SIZE}:d={dur}",
75
  "-f", "lavfi", "-i", "anullsrc=r=44100:cl=stereo",
76
  "-vf", (
77
- f"drawtext=text='{wrapped}':fontcolor=white:fontsize=60:"
78
  "x=(w-text_w)/2:y=(h-text_h)/2:fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
79
  ),
80
  "-shortest", "-r", str(FPS),
 
32
  )
33
  return True
34
  except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
35
+ print(f"Command failed:\n{' '.join(cmd)}\nError:\n{e.stderr if hasattr(e, 'stderr') else str(e)}")
36
  return False
37
 
38
  def yt_urls(query: str, max_results: int) -> List[str]:
 
54
  out.parent.mkdir(exist_ok=True)
55
  cmd = [
56
  "yt-dlp",
57
+ "-f", "mp4",
58
  "--merge-output-format", "mp4",
59
  "-o", str(out),
60
  "--max-duration", str(MAX_VIDEO_LENGTH),
61
  "--no-playlist",
62
+ "--no-check-certificate",
63
  url,
64
  ]
65
  return run_cmd(cmd, timeout=60)
 
67
  def make_card(text: str, out: Path, dur: int = TITLE_DUR) -> bool:
68
  """Create title card with text"""
69
  # Wrap text for better display
70
+ wrapped = textwrap.wrap(text, width=25)
71
+ safe_text = "\\n".join(w.replace("'", r"\\'") for w in wrapped)
72
+
73
 
74
  cmd = [
75
  "ffmpeg",
 
77
  "-f", "lavfi", "-i", f"color=c=navy:s={SIZE}:d={dur}",
78
  "-f", "lavfi", "-i", "anullsrc=r=44100:cl=stereo",
79
  "-vf", (
80
+ f"drawtext=text='{safe_text}':fontcolor=white:fontsize=60:"
81
  "x=(w-text_w)/2:y=(h-text_h)/2:fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
82
  ),
83
  "-shortest", "-r", str(FPS),