Zachary Kotlarek 12 лет назад
Родитель
Сommit
e24ce81b43
1 измененных файлов с 13 добавлено и 13 удалено
  1. 13 13
      plexCmd/recentlyUnwatched.sh

+ 13 - 13
plexCmd/recentlyUnwatched.sh

@@ -1,19 +1,19 @@
 #!/bin/bash
 
 HOST="http://beddy.uberzach.com:32400"
+NUM_SERIES=10
+NUM_EPISODES=5
 
 # Select a configuration mode
 URL1="${HOST}/library/sections/2/recentlyViewedShows/"
 URL2_POST="allLeaves?unwatched=1"
 ELEMENT="Directory"
-NUM_EPISODES=5
 MOVIES=0
 if echo "${1}" | grep -iq Movie; then
 	MOVIES=1
 	URL1="${HOST}/library/sections/1/recentlyAdded/"
 	URL2_POST=""
 	ELEMENT="Video"
-	NUM_EPISODES=10
 fi
 
 SERIES="`curl --silent "${URL1}" | \
@@ -36,35 +36,35 @@ if [ "${MOVIES}" -gt 0 ]; then
 	SERIES="${UNWATCHED}"
 fi
 
-nscount=0
+SERIES_COUNT=0
 IFS=$'\n'
 for i in $SERIES; do
+	SERIES_COUNT=$(( $SERIES_COUNT + 1 ))
 	FILES="`curl --silent "${HOST}/library/metadata/${i}/${URL2_POST}" | \
 		grep '<Part ' | \
 		sed 's%^.*file="\([^\"]*\)".*$%\1%' | \
 		sed "s%^.*/media/%%"`"
 
-	scounts=()
+	SEASON_COUNTS=()
 	IFS=$'\n'
 	for j in $FILES; do
 		# Find the season number and increment the count
 		# Account no-season items (i.e. movies) separately
-		season="`echo "${j}" | sed 's%^.*/Season \([0-9]*\)/.*$%\1%'`"
-		if ! echo "${season}" | grep -q '^[0-9]*$'; then
-			season=-1
-			nscount=$(( $nscount + 1 ))
+		SEASON="`echo "${j}" | sed 's%^.*/Season \([0-9]*\)/.*$%\1%'`"
+		if ! echo "${SEASON}" | grep -q '^[0-9]*$'; then
+			SEASON=-1
 		else
-			scounts[$season]=$(( ${scounts[$season]} + 1 ))
+			SEASON_COUNTS[$SEASON]=$(( ${SEASON_COUNTS[$SEASON]} + 1 ))
 		fi
 
-		# For no-season items, output only NUM_EPISODES total
-		if [ $season -lt 0 ]; then
-			if [ $nscount -gt $NUM_EPISODES ]; then
+		# Limit the number of series (or movies)
+		if [ $SEASON -lt 0 ]; then
+			if [ $SERIES_COUNT -gt $NUM_SERIES ]; then
 				continue
 			fi
 		# Only output NUM_EPISODES files per season
 		# This allows discontinous output, but that's desirable compared to only getting season 0
-		elif [ ${scounts[$season]} -gt $NUM_EPISODES ]; then
+		elif [ ${SEASON_COUNTS[$SEASON]} -gt $NUM_EPISODES ]; then
 			continue
 		fi