diff --git a/README.md b/README.md index 1e97a13..79f8c8d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # nyaa -cli tool for downloading torrents from [nyaa.si](https://nyaa.si), heavily inspired by [notflix](https://github.com/Bugswriter/notflix) +cli tool for streaming and downloading torrents from [nyaa.si](https://nyaa.si), heavily inspired by [notflix](https://github.com/Bugswriter/notflix) ## Dependencies @@ -10,9 +10,30 @@ cli tool for downloading torrents from [nyaa.si](https://nyaa.si), heavily inspi ## Usage ```sh -$ nyaa -$ nyaa -q "XYZ" # Search for XYZ (otherwise show search prompt) -$ nyaa -d some/dir # Download to some/dir, defaults to $HOME/Downloads +$ nyaa # will prompt for query +$ nyaa your query here +$ nyaa fate apocrypha # an example +``` + +### Flags + +- d) download torrent to $NYAA_DIR using aria2 +- p) create a playlist of all files in the torrent +- x) query [sukebei.nyaa.si](https://sukebei.nyaa.si) + +### Config + +The program sources the file at $XDG_CONFIG_HOME/nyaa/config or $HOME/.config/nyaa/config +Currently, there are only 2 environmental variables available + +- NYAA_DIR -> directory to which the torrents will be downloaded +- NYAA_PLAYER_ARGS -> arguments passed to mpv + +Example of the config file: + +```sh +NYAA_DIR=$HOME/Torrents +NYAA_PLAYER_ARGS="--slang=eng --alang=jpn" ``` ## Installation @@ -21,3 +42,6 @@ $ nyaa -d some/dir # Download to some/dir, defaults to $HOME/Downloads $ sudo curl -sL "https://gitlab.com/yaemiku/nyaa/-/raw/main/nyaa" -o /usr/local/bin/nyaa $ sudo chmod +x /usr/local/bin/nyaa ``` + +To upgrade, you only need to run the first command + diff --git a/nyaa b/nyaa index b0cdccd..1a52ea7 100755 --- a/nyaa +++ b/nyaa @@ -1,23 +1,46 @@ -#!/usr/bin/env bash +#!/bin/sh + +save_dir=$NYAA_DIR +if test -f $XDG_CONFIG_HOME/nyaa/config || test -f $HOME/.config/nyaa/config; +then + source "${XDG_CONFIG_HOME:-'$HOME/.config'}/nyaa/config" 2> /dev/null; # source config +fi +NYAA_DIR=$save_dir mkdir -p "${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa" temp="${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa" -dir=${NYAA_DIR:-"$HOME/Downloads"} +download=0 +dir=${NYAA_DIR:-"."} url="https://nyaa.si" +extra_flags="-i" trap "rm -rf $temp" SIGINT SIGTERM ERR EXIT -while getopts axd:q: flag; do - case "${flag}" in - x) url="https://sukebei.nyaa.si";; - d) dir=${OPTARG};; - q) query=${OPTARG};; - esac +# https://gist.github.com/caruccio/836c2dda2bdfa5666c5f9b0230978f26 +ARGS=() +while [ $# -gt 0 ]; do + while getopts xdp flag; do + case "${flag}" in + x) url="https://sukebei.nyaa.si";; + d) download=1;; + p) extra_flags="--playlist";; + esac + done + [ $? -eq 0 ] || exit 1 + [ $OPTIND -gt $# ] && break + + shift $[$OPTIND - 1] + OPTIND=1 + ARGS[${#ARGS[*]}]=$1 + shift done -if [ -z "$query" ]; then +query=${ARGS[*]} + +if test -z "$query"; +then query=$(pmenu -p "Search Torrent: ") - if [ -z "$query" ]; then + if test -z "$query"; then exit 0; fi fi @@ -25,30 +48,37 @@ fi query="$(echo $query | sed 's/ /+/g')" curl -s "$url/?s=seeders&q=$query" > $temp/html -grep -o '(.*?)" \ +| sed -E 's/