File size: 1,954 Bytes
a1a36a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import subprocess
import os
def download_fb_content(url, cookies_path):
"""
Downloads content from a direct Facebook URL using gallery-dl.
Args:
url (str): The direct URL to the Facebook content.
cookies_path (str): The path to the cookies.txt file.
"""
# First, check if the cookies file exists before attempting to download.
if not os.path.exists(cookies_path):
print(f"Error: Cookies file not found at '{cookies_path}'")
print("Please ensure the file exists and the path is correct.")
return # Stop the function if cookies are missing
# --- Direct download logic ---
print("-" * 20)
print(f"Running gallery-dl for: {url}")
print("-" * 20)
cmd = [
"gallery-dl",
"--cookies", cookies_path,
url
]
try:
# Run the command and check for any errors during execution.
subprocess.run(cmd, check=True)
print("\nDownload completed successfully.")
except FileNotFoundError:
print("\n--- ERROR ---")
print("Command 'gallery-dl' not found.")
print("Please make sure gallery-dl is installed and accessible in your system's PATH.")
except subprocess.CalledProcessError as e:
print("\n--- ERROR ---")
print(f"gallery-dl returned an error (Exit Code: {e.returncode}).")
print("This could be due to an invalid URL, private content, or expired cookies.")
print("Try running the command directly in your terminal for more detailed error messages.")
# --- EXAMPLE ---
# Set the path to your cookies file.
# Make sure it's in the same directory as this script or provide the full path.
cookies_file = "cookies.txt"
print("--- Downloading Facebook Story Content ---")
story_url = "https://www.facebook.com/stories/108639588358960/UzpfSVNDOjE1NjIwNDMzMjg0ODk0ODA=/?view_single=false"
download_fb_content(story_url, cookies_file) |