Skip to content

Instantly share code, notes, and snippets.

@geolaw
Created April 12, 2022 12:09
Show Gist options
  • Select an option

  • Save geolaw/c296fbdb56e1014aa5773c64eb55a8b8 to your computer and use it in GitHub Desktop.

Select an option

Save geolaw/c296fbdb56e1014aa5773c64eb55a8b8 to your computer and use it in GitHub Desktop.

Revisions

  1. geolaw created this gist Apr 12, 2022.
    34 changes: 34 additions & 0 deletions sqlite_download.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/bin/bash

    # video downloader. uses ~/urls.db as reference.
    # seperate script watches the clip board for any http links and puts them in the
    # table

    # all downloads to /data/p/Downloads
    cd /data/p/Downloads
    while true; do

    while true; do
    num=$(sqlite3 ~/urls.db "select count (UID) from urls where processed=0;")
    if [ $num -eq 0 ]; then
    echo "no more current URLS, sleeping for 60 seconds"
    break
    fi
    url=$(sqlite3 ~/urls.db "select url from urls where processed=0 limit 1;")
    echo "Starting $url"
    # use the --no-mtime to avoid old file date stamps
    youtube-dl -q --no-mtime "$url"
    # if the download failed, e.g. unsupported, whatever, then log this
    if [ "$?" != "0" ]; then
    sqlite3 ~/urls.db "update urls set processed = 2 where url='$url';"
    echo $line >> ~/failed_downloads
    else
    sqlite3 ~/urls.db "update urls set processed = 1 where url='$url';"
    notify-send "Download of $url done"
    echo "$url done"
    fi
    done
    sleep 60
    done

    echo "db done,Reader exiting"