Skip to content

Commit

Permalink
Fixed memory issue in videoduration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Demmenie committed Jul 12, 2024
1 parent efddef6 commit 6ab66aa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions videohash2/videoduration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from shutil import which
import shutil
from subprocess import PIPE, Popen
from typing import Optional
from .exceptions import DidNotSupplyPathOrUrl
Expand Down Expand Up @@ -46,7 +46,7 @@ def video_duration(url: Optional[str] = None,
raise ValueError("Specify either a path or an URL and NOT both.")

if not ffmpeg_path:
ffmpeg_path = str(which("ffmpeg"))
ffmpeg_path = str(shutil.which("ffmpeg"))

if url:
video_dir, video_download_dir = _create_required_dirs_and_check_for_errors(
Expand Down Expand Up @@ -76,4 +76,11 @@ def video_duration(url: Optional[str] = None,

hours, minutes, seconds = duration_string.strip().split(":")

cutPath = path[:path.find("/temp_storage_dir")]

try:
shutil.rmtree(cutPath)
except OSError as e:
print("Error: %s - %s." % (e.filename, e.strerror))

return float(hours) * 60.00 * 60.00 + float(minutes) * 60.00 + float(seconds)

0 comments on commit 6ab66aa

Please sign in to comment.