Add support for piping a playlist in through STDIN
This commit is contained in:
		
							
								
								
									
										12
									
								
								ptgdp
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								ptgdp
									
									
									
									
									
								
							@@ -290,13 +290,8 @@ playlist() {
 | 
				
			|||||||
	local -i totallines=0
 | 
						local -i totallines=0
 | 
				
			||||||
	while read line; do
 | 
						while read line; do
 | 
				
			||||||
		totallines+=1
 | 
							totallines+=1
 | 
				
			||||||
		validateline "$line" || continue
 | 
					 | 
				
			||||||
		goodlines+=1
 | 
					 | 
				
			||||||
	done < "$1"
 | 
					 | 
				
			||||||
	log "Parsed playlist \"$1\" with $goodlines songs"
 | 
					 | 
				
			||||||
	log "Playlist has $totallines total lines" 2
 | 
					 | 
				
			||||||
	while read line; do
 | 
					 | 
				
			||||||
		if validateline "$line"; then
 | 
							if validateline "$line"; then
 | 
				
			||||||
 | 
								goodlines+=1
 | 
				
			||||||
			queuesong "$line" || error "Failed to enqueue song: \"$line\""
 | 
								queuesong "$line" || error "Failed to enqueue song: \"$line\""
 | 
				
			||||||
			case $_returnstatus in
 | 
								case $_returnstatus in
 | 
				
			||||||
				dl)
 | 
									dl)
 | 
				
			||||||
@@ -321,6 +316,7 @@ playlist() {
 | 
				
			|||||||
		backend-execqueue
 | 
							backend-execqueue
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
	log "Finished: $dlcache cached, $dlsuccess downloaded, $dlerr failed"
 | 
						log "Finished: $dlcache cached, $dlsuccess downloaded, $dlerr failed"
 | 
				
			||||||
 | 
						log "Playlist has $totallines total lines, $goodlines of them songs" 1
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Main
 | 
					# Main
 | 
				
			||||||
@@ -404,9 +400,13 @@ main() {
 | 
				
			|||||||
		error "Failed to find program: $_return" 1
 | 
							error "Failed to find program: $_return" 1
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
	if [ -n "${_args[*]}" ]; then
 | 
						if [ -n "${_args[*]}" ]; then
 | 
				
			||||||
 | 
							# Files specified on the command line have priority
 | 
				
			||||||
		for arg in "${_args[@]}"; do
 | 
							for arg in "${_args[@]}"; do
 | 
				
			||||||
			playlist "$arg"
 | 
								playlist "$arg"
 | 
				
			||||||
		done
 | 
							done
 | 
				
			||||||
 | 
						elif ! [ -t 0 ]; then
 | 
				
			||||||
 | 
							# If there are none of those, read from STDIN
 | 
				
			||||||
 | 
							playlist "/dev/stdin"
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		warn "Nothing to do"
 | 
							warn "Nothing to do"
 | 
				
			||||||
		exit 0
 | 
							exit 0
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user