### Example gallery-dl-view Configuration Source: https://github.com/noctuid/gallery-dl-view/blob/master/README.org An example configuration file for gallery-dl-view, demonstrating how to set options like the gallery URL file, visited URLs file, ignore visited flag, download command, download arguments, and save key. ```conf-unix gallery_url_file=./gallery-dl-view-url visited_urls_file=./visited-urls ignore_visited=yes download_command=aria2c # could also include --cookies to use with sites that require cookies download_args=["-d", ".", "--extra-flag-1"] save_key=x ``` -------------------------------- ### Play Online Galleries with mpv and gallery-dl Source: https://context7.com/noctuid/gallery-dl-view/llms.txt These examples demonstrate how to use mpv to play online media galleries using the `gallery-dl://` protocol. They cover different platforms like Reddit and Imgur, showcasing direct playback of gallery URLs. ```bash mpv gallery-dl://https://reddit.com/r/wallpapers/top ``` ```bash mpv gallery-dl://https://imgur.com/a/abc123 ``` ```bash mpv gallery-dl://https://danbooru.donmai.us/posts?tags=landscape ``` -------------------------------- ### Build Release Version for MPV (Bash) Source: https://context7.com/noctuid/gallery-dl-view/llms.txt Builds the project's release version using Shadow-CLJS, specifically targeting ES5 JavaScript compatibility required by mpv's mujs engine. This involves installing dependencies via npm and then running the Shadow-CLJS release command or a Makefile target. The output is a `main.js` file. ```bash # Install dependencies npm install # Build release version (ES5 for mpv's mujs engine) clojure -M:shadow-cljs release app # or make release # Output: main.js (compiled ClojureScript -> JavaScript ES5) # Installation git clone ~/.config/mpv/scripts/gallery-dl-view cd ~/.config/mpv/scripts/gallery-dl-view make release ``` -------------------------------- ### Ranger Integration for Opening Galleries Source: https://github.com/noctuid/gallery-dl-view/blob/master/README.org Examples for Ranger's rifle.conf to open galleries stored in text files using the mvigallery script. It shows configurations with and without the tdrop utility for managing the mpv window. ```shell # open text file storing gallery url as gallery in mpv/mvi file, has mvigallery, name gallery(-dl-url)?$ = tdrop -a auto_hide && mvigallery "$@" ./ && tdrop -a auto_show ``` ```shell # or without tdrop file, has mvigallery, name gallery(-dl-url)?$ = mvigallery "$@" ./ ``` -------------------------------- ### Ranger File Manager Integration for gallery-dl-view Source: https://context7.com/noctuid/gallery-dl-view/llms.txt This configuration for Ranger's `rifle.conf` sets up a rule to open gallery-dl URLs with mpv. When Ranger encounters a file or URL matching `gallery(-dl-url)?`, it will use mpv to play the content, starting from the first item in the playlist. ```bash file, has mpv, name gallery(-dl-url)?$ = mpv --playlist-start=0 "$(cat "$@")" ``` -------------------------------- ### Playlist Loading and Navigation with MPV Hooks (ClojureScript) Source: https://context7.com/noctuid/gallery-dl-view/llms.txt Manages playlist loading for gallery-dl URLs and handles automatic range transitions within mpv. It registers hooks for `on_load` and `on_load_fail` to process URLs starting with `gallery-dl://`. It also handles navigation logic, including loading the next range of items when the end of the current range is reached or when wrapping around the playlist. Dependencies include the mpv library. ```clojure ;; Hook registration from core.cljs:291-298 (defn init "Entrypoint. Add hook to load files that begin with gallery-dl:// as galleries." [] (mp add_hook "on_load" 50 maybe-open-gallery) (when-not (settings :require_prefix) (mp add_hook "on_load_fail" 50 maybe-open-gallery-on-failure)) (mp register_event "shutdown" write-visited-urls)) ;; Navigation handling from core.cljs:247-280 (defn maybe-open-gallery [_hook] (let [url (mp get_property "stream-open-filename")] (cond (starts-with? url gdl-prefix) (open-gallery url false) (url-previously-visited?) (mp commandv "playlist-remove" (mp get_property "playlist-pos")) :else (do (maybe-mark-url-visited) (let [pos (js/parseInt (mp get_property "playlist-pos")) max-pos (get-max-playlist-pos)] ;; Load next range when reaching end (cond (and (= pos max-pos) (= previous-playlist-pos 0) (not (= start-index 1))) (do (update-range true) (load-range) (mp set_property "playlist-pos" (str (get-max-playlist-pos)))) ;; Load next range when wrapping around (and (= pos 0) (= previous-playlist-pos max-pos)) (do (update-range) (load-range))) (set! previous-playlist-pos pos)))))) ;; Example flow: ;; 1. User opens: mpv gallery-dl://https://reddit.com/r/wallpapers/top ;; 2. on_load hook fires -> maybe-open-gallery ;; 3. Loads images 1-200 into playlist ;; 4. User navigates to image 200 (max-pos) ;; 5. User presses right arrow -> wraps to image 0 ;; 6. Hook detects wrap-around, loads images 201-400 ;; 7. Playlist now contains images 1-400 ``` -------------------------------- ### Automatic gallery-dl Fallback in mpv Source: https://context7.com/noctuid/gallery-dl-view/llms.txt This usage example shows how mpv can automatically attempt to use gallery-dl to load a URL if it cannot be played natively. This is useful for direct links to media that are part of a larger gallery or collection. ```bash mpv https://reddit.com/r/EarthPorn ``` -------------------------------- ### File I/O for State Persistence (ClojureScript) Source: https://context7.com/noctuid/gallery-dl-view/llms.txt Provides functions for reading, writing, and appending text to files, used for persisting gallery state and visited URLs. It leverages the `mpv` API's `utils` function for file operations. The functions handle file path construction (e.g., `file://`) and are designed to work within the mpv environment. Examples show saving URLs and visited lists. ```clojure ;; File operations from core.cljs:62-86 (defn read-file "Read text from a file." [fname] (utils read_file fname)) (defn write-file "Write text to a file." [file text] (let [fname (str "file://" file)] (utils write_file fname text))) (defn append-file "Append text to a file." [file text] (let [fname (str "file://" file)] (utils append_file fname text))) ;; Example usage: ;; Save gallery URL for later reopening (write-file "./gallery-dl-view-url" "https://reddit.com/r/wallpapers/top") ;; Append visited URLs (append-file "~/.cache/gallery-dl-view/visited" "https://i.redd.it/abc123.jpg\n") ;; Read visited URLs on startup (def visited-urls (try (set (split-lines (read-file "~/.cache/gallery-dl-view/visited"))) (catch :default _ #{}))) ;; File format for gallery_url_file (single line): ;; https://reddit.com/r/EarthPorn/top ;; File format for visited_urls_file (one URL per line): ;; https://i.redd.it/image1.jpg ;; https://i.redd.it/image2.jpg ;; https://i.imgur.com/image3.png ``` -------------------------------- ### Configure gallery-dl-view mpv Options Source: https://context7.com/noctuid/gallery-dl-view/llms.txt This snippet shows how to configure the gallery-dl-view script for mpv. It defines paths for gallery URLs and visited URLs, and sets options for fetching behavior and download commands. The configuration is stored in a file at `~/.config/mpv/script-opts/gallery-dl-view.conf`. ```bash cat > ~/.config/mpv/script-opts/gallery-dl-view.conf <js {:prefix "gallery-dl://" :require_prefix false :fetch_count 200 :gallery_url_file "" :visited_urls_file "" :ignore_visited false :download_command "gallery-dl" :download_args ["-d" "."] :save_key ""})) ;; Configuration file: ~/.config/mpv/script-opts/gallery-dl-view.conf ;; Example configuration: ;; gallery_url_file=./gallery-dl-view-url ;; visited_urls_file=./visited-urls ;; ignore_visited=yes ;; download_command=aria2c ;; download_args=["-d", ".", "--continue"] ;; save_key=x ;; Accessing settings programmatically (defn settings [prop] (let [clj-settings (js->clj default-settings)] (clj-settings (name prop)))) ;; Usage examples: (settings :prefix) ;; => "gallery-dl://" (settings :fetch_count) ;; => 200 (settings :ignore_visited) ;; => false or true based on config ``` -------------------------------- ### Opening Galleries with gallery-dl-view (ClojureScript) Source: https://context7.com/noctuid/gallery-dl-view/llms.txt Handles opening media galleries by processing URLs. It supports URLs prefixed with `gallery-dl://` and can also attempt to open URLs that fail native loading using gallery-dl. Successfully opened galleries are added to mpv's playlist, and visited URLs are persisted. ```clojurescript ;; Function signature from core.cljs:219-240 (defn open-gallery "Open url as a gallery-dl supported gallery, removing gallery-dl:// prefix. If load-failed? is true, try to open url as-is if possible." [url load-failed?] (let [real-url (if load-failed? url (replace url gdl-prefix "")) res (subprocess-capture ["gallery-dl" "--range" (current-range 1) "--dump-json" real-url])] (if (= (res "status") 0) (do (set! gallery-url real-url) (set! start-index 1) (info "Opening gallery " real-url) (make-keybindings) (when-not (blank? (settings :gallery_url_file)) (write-file (settings :gallery_url_file) real-url)) (load-range res)) (info "Failed to open gallery " real-url " with error " (res "stderr"))))) ;; Command-line usage: ;; mpv gallery-dl://https://reddit.com/r/wallpapers ;; mpv gallery-dl://https://imgur.com/gallery/abc123 ;; With require_prefix=false, this also works: ;; mpv https://reddit.com/r/EarthPorn ;; (will attempt gallery-dl if native loading fails) ``` -------------------------------- ### MPV API Access Macros (ClojureScript) Source: https://context7.com/noctuid/gallery-dl-view/llms.txt Provides ClojureScript macros for convenient access to mpv's JavaScript API, simplifying interactions with mpv functions and utilities. Macros like `mp` and `utils` abstract away direct JavaScript calls, while `subprocess-capture` and `subprocess-detached` facilitate running external commands. No external dependencies beyond mpv. ```clojure ;; Macros from macros.clj:3-55 (defmacro mp "Run an mp function with args." [fun & args] `(. js/mp ~fun ~@args)) (defmacro utils "Run an mp.utils function with args." [fun & args] `(. (. js/mp -utils) ~fun ~@args)) (defmacro subprocess-capture "Same as subprocess but capture stdout." [args & options] `(subprocess ~args :playback_only false :capture_stdout true ~@options)) (defmacro subprocess-detached "Same as subprocess but run detached." [args & options] `(subprocess ~args :playback_only false :detach true ~@options)) ;; Usage examples in core.cljs: (mp get_property "path") ;; Get current file path (mp commandv "loadlist" "memory://urls") ;; Load playlist from memory (utils read_file "filename") ;; Read file using mpv utils (utils write_file "file://path" "content") ;; Write file ;; Subprocess examples: (subprocess-capture ["gallery-dl" "--version"]) ;; => {"status" 0 "stdout" "gallery-dl 1.26.0" "stderr" ""} (subprocess-detached ["aria2c" "-d" "." "https://example.com/file.jpg"]) ;; => Process runs in background, returns immediately ``` -------------------------------- ### Download Media with Custom Command Source: https://context7.com/noctuid/gallery-dl-view/llms.txt Downloads the currently displayed gallery image using a configurable download command and arguments. It integrates with mpv by setting up a keybinding to trigger the download function. The `gallery-dl-download-url` function executes the download process using `subprocess-detached`. ```clojure (defn gallery-dl-download-url "Download the current gallery image." [] (when gallery-url (let [url (mp get_property "path") args (concat [(settings :download_command)] (settings :download_args) [url])] (subprocess-detached args) (show-text "Downloaded " url)))) (defn make-keybindings [] (when-not (blank? (settings :save_key)) (mp add_forced_key_binding (settings :save_key) "gallery-dl-download-url" gallery-dl-download-url))) ``` -------------------------------- ### Tridactyl Browser Integration for gallery-dl-view Source: https://context7.com/noctuid/gallery-dl-view/llms.txt This configuration snippet for Tridactyl allows users to bind a key combination to open the current browser URL in mpv using gallery-dl. It captures the current URL, escapes it for shell safety, and pipes it to mpv with the `gallery-dl://` prefix. ```bash bind tg composite get_current_url | shellescape | !s mpv gallery-dl:// ``` -------------------------------- ### Create Cache Directory for gallery-dl-view Source: https://context7.com/noctuid/gallery-dl-view/llms.txt This command creates the necessary cache directory for gallery-dl-view to store its temporary files and state. The `-p` flag ensures that parent directories are created if they don't exist and that the command doesn't fail if the directory already exists. ```bash mkdir -p ~/.cache/gallery-dl-view ``` -------------------------------- ### Tridactyl Browser Integration Command Source: https://github.com/noctuid/gallery-dl-view/blob/master/README.org A Tridactyl command to bind a key to open the current URL in mpv using the gallery-dl-view script. It captures the current URL, escapes it, and passes it to a script (mvigallery). ```shell bind tg composite get_current_url | shellescape | !s mvigallery ``` -------------------------------- ### Dynamic Range Loading for Galleries (ClojureScript) Source: https://context7.com/noctuid/gallery-dl-view/llms.txt Manages the loading of images from galleries in configurable chunks (ranges). It calculates the current range based on `fetch_count` and allows updating the range to load more content as the user navigates. This enables efficient streaming of large galleries. ```clojurescript ;; Range calculation from core.cljs:132-148 (defn current-range "Return the current range string to pass to gallery-dl." ([start] (let [end (+ start (settings :fetch_count))] (str start "-" (- end 1)))) ([] (current-range start-index))) (defn update-range "Increment or decrement the start index for the current gallery range." ([decrement?] (set! start-index (if decrement? (max 1 (- start-index (settings :fetch_count))) (+ start-index (settings :fetch_count))))) ([] (update-range false))) ;; Example range progression: ;; Initial load: start-index=1, range="1-200" ;; After navigating to last image: start-index=201, range="201-400" ;; Going back to first: start-index=1, range="1-200" ;; gallery-dl command executed: ;; gallery-dl --range 1-200 --dump-json ;; gallery-dl --range 201-400 --dump-json ``` -------------------------------- ### Track Visited URLs Source: https://context7.com/noctuid/gallery-dl-view/llms.txt Manages a set of visited URLs to filter out previously viewed content. URLs are loaded from a file on startup and appended to the file on exit. The `url-previously-visited?` function checks if a given URL has been visited, respecting a configuration setting to ignore visited URLs. ```clojure (def visited-urls "Set of previously visited gallery urls." (try (set (split-lines (read-file (settings :visited_urls_file)))) (catch :default _ #{}))) (def store-urls "A set of urls to write to the visited urls file on exit." #{}) (defn url-previously-visited? [] (let [url (mp get_property "path")] (and (settings :ignore_visited) (gallery-metadata url) (contains? visited-urls url)))) (defn write-visited-urls [] (when (and (not (blank? (settings :visited_urls_file))) (seq store-urls)) (append-file (settings :visited_urls_file) (str (join "\n" store-urls) "\n")))) ``` -------------------------------- ### Parse gallery-dl JSON Output Source: https://context7.com/noctuid/gallery-dl-view/llms.txt Parses gallery-dl's JSON output (Transit encoded) to extract media URLs and their associated metadata. It filters entries to ensure they are valid and returns a list of URLs and a map of URLs to their metadata. Dependencies include the 'transit-clj' library. ```clojure (defn parse-gallery-dl-json "Parse a gallery-dl json dump. Return a list of urls and a map of urls to metadata." [json-dump] (let [entries (filter #(and (seq %) (= (count %) 3) (string? (% 1))) (transit/read (transit/reader :json) json-dump)) urls (map #(% 1) entries) metadata (into (ordered-map) (map #(vector (% 1) (% 2)) entries))] [urls metadata])) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.