#compdef tizonia

# tizonia zsh completion

local curcontext="$curcontext" state state_descr line
typeset -A opt_args

local rc=1

_arguments -S -s \
  '--help[Help topics.]:Help topics by area:(global openmax server client spotify googlemusic soundcloud tunein youtube plex chromecast keyboard config examples)' \
  '(-b)--buffer-seconds[Size of the audio buffer to use while downloading streams.]' \
  '(-c)--cast[Cast to a Chromecast device (arg: device name, fiendly name or ip address).]' \
  '(-d)--daemon[Run in the brackground.]' \
  '(-r)--recurse[Recursively process a given path.]' \
  '(-s)--shuffle[Shuffle the playlist.]' \
  '(-v)--version[Print the version information.]' \
  '(-C)--comps-of-role[Display the OpenMAX IL components that implement the role.]' \
  '(-L)--comp-list[Enumerate all the OpenMAX IL components in the system.]' \
  '(-R)--roles-of-comp[Display the OpenMAX IL roles found in component.]' \
  '--proxy-server[Url to the proxy server that should be used (works wih Spotify only).]' \
  '--proxy-user[User name to be used during proxy server authentication.]' \
  '--proxy-password[Password to be used during proxy server authentication.]' \
  '--spotify-user[Spotify user name.]' \
  '--spotify-password[Spotify user password.]' \
  '--spotify-owner[The owner of the playlist (optional, may be used in conjunction with --spotify-playlist).]' \
  '--spotify-recover-lost-token[Allow Tizonia to recover the play token and keep playing after a spurious token loss (default: false).]' \
  '--spotify-allow-explicit-tracks[Allow Tizonia to play explicit tracks from Spotify (default: false).]' \
  '--spotify-preferred-bitrate[Three possible values (kbps): 96, 160, or 320 (default: 320)]' \
  '--spotify-tracks[Search and play from Spotify by track name.]' \
  '--spotify-artist[Search and play from Spotify by artist name.]' \
  '--spotify-album[Search and play from Spotify by album name.]' \
  '--spotify-playlist[Search and play public playlists (owner is assumed current user, unless --spotify-owner is provided).]' \
  '--spotify-track-id[Play from Spotify by track ID, URI or URL.]' \
  '--spotify-artist-id[Play from Spotify by artist ID, URI or URL.]' \
  '--spotify-album-id[Play from Spotify by album ID, URI or URL.]' \
  '--spotify-playlist-id[Play public playlists from Spotify by ID, URI or URL.]' \
  '--spotify-related-artists[Search and play from Spotify the top songs from a selection of related artists.]' \
  '--spotify-featured-playlist[Search and play a featured playlist from Spotify.]' \
  '--spotify-new-releases[Search and play a newly released album from Spotify.]' \
  '--spotify-recommendations-by-track-id[Play Spotify recommendations by track ID, URI or URL.]' \
  '--spotify-recommendations-by-artist-id[Play Spotify recommendations by artist ID, URI or URL.]' \
  '--spotify-recommendations-by-track[Play Spotify recommendations by track name.]' \
  '--spotify-recommendations-by-artist[Play Spotify recommendations by artist name.]' \
  '--spotify-recommendations-by-genre[Play Spotify recommendations by genre name.]' \
  '--spotify-user-liked-tracks[Play the user liked tracks.]' \
  '--spotify-user-recent-tracks[Play the user most recently played tracks.]' \
  '--spotify-user-top-tracks[Play the user top tracks.]' \
  '--spotify-user-top-artists[Play top tracks from the user top artists.]' \
  '--spotify-user-playlist[Play a playlist from the user private library (including Daily Mixes and Discover Weekly).]' \
  '--gmusic-user[Google Play Music user name (not required if provided via config file).]' \
  '--gmusic-password[Google Play Music users password (not required if provided via config file).]' \
  '--gmusic-device-id[Google Play Music device id (not required if provided via config file).]' \
  '--gmusic-album[Play an album from the users library.]' \
  '--gmusic-artist[Play tracks from the users library by artist.]' \
  '--gmusic-library[Play all tracks from the users library.]' \
  '--gmusic-playlist[A playlist from the users library.]' \
  '--gmusic-podcast[Search and play Google Play Music podcasts.]' \
  '--gmusic-station[Search and play Google Play Music free stations.]' \
  '--gmusic-tracks[Play tracks from the users library.]' \
  '--gmusic-unlimited-activity[Search and play Google Play Music Unlimited tracks by activity.]' \
  '--gmusic-unlimited-album[Search and play Google Play Music Unlimited tracks by album (best match only).]' \
  '--gmusic-unlimited-artist[Search and play Google Play Music Unlimited tracks by artist (best match only).]' \
  '--gmusic-unlimited-feeling-lucky-station[Play the users Google Play Music Unlimited Im Feeling Lucky station.]' \
  '--gmusic-unlimited-genre[Search and play Google Play Music Unlimited tracks by genre.]' \
  '--gmusic-unlimited-playlist[Search and play Google Play Music Unlimited playlists.]' \
  '--gmusic-unlimited-promoted-tracks[Play Google Play Music Unlimited promoted tracks.]' \
  '--gmusic-unlimited-station[Search and play Google Play Music Unlimited stations found in the users library.]' \
  '--gmusic-unlimited-tracks[Search and play Google Play Music Unlimited tracks by name (50 first matches only).]' \
  '--soundcloud-oauth-token[SoundCloud user OAuth token (not required if provided via config file).]' \
  '--soundcloud-user-stream[Play the tracks currently listed in the users stream.]' \
  '--soundcloud-user-likes[Play the tracks liked by the user.]' \
  '--soundcloud-user-playlist[Play a playlist from the users collection.]' \
  '--soundcloud-creator[Search and play the top 50 tracks from a creator.]' \
  '--soundcloud-tracks[Search and play tracks by title (50 first matches only).]' \
  '--soundcloud-playlists[Search and play playlists by title.]' \
  '--soundcloud-genres[Search and play genres top tracks (arg is a command-separated list).]' \
  '--soundcloud-tags[Search and play tags top tracks (arg is a command-separated list).]' \
  '--tunein-search[TuneIn global station/podcast search.]' \
  '--tunein-local[TuneIn 'local' category search.]' \
  '--tunein-music[TuneIn 'music' category search.]' \
  '--tunein-talk[TuneIn 'talk' category search.]' \
  '--tunein-sports[TuneIn 'sports' category search.]' \
  '--tunein-location[TuneIn 'location' category search.]' \
  '--tunein-podcasts[TuneIn 'podcasts' category search.]' \
  '--tunein-trending[TuneIn 'trending' category search.]' \
  '--tunein-type[Narrow down the search to specific type: 'stations', 'shows', or 'all' (default: all). Optional.]' \
  '--tunein-keywords[Additional keywords that may be used in conjunction with the TuneIn options. Optional (may be repeated).]' \
  '--youtube-api-key[The users YouTube DATA API v3 key (Optional but RECOMMENDED).]' \
  '--youtube-audio-mix[Play a YouTube mix from a video url or video id.]' \
  '--youtube-audio-mix-search[Play a YouTube mix from a search term.]' \
  '--youtube-audio-playlist[Play a YouTube audio playlist from a playlist url or playlist id.]' \
  '--youtube-audio-search[Search and play YouTube audio streams.]' \
  '--youtube-audio-stream[Play a YouTube audio stream from a video url or video id.]' \
  '--youtube-audio-channel-playlist[Play a playlist from particular YouTube channel.]' \
  '--youtube-audio-channel-uploads[Play all videos uploaded to a YouTube channel.]' \
  '--plex-server-base-url[Plex server base URL (e.g. http://plexserver:32400. Not required if provided via config file).]' \
  '--plex-auth-token arg[Plex account authentication token (not required if provided via config file).]' \
  '--plex-music-section arg[Name of the Plex music section (needed if different from 'Music'; not required if provided via config file).]' \
  '--plex-audio-tracks[Search and play audio tracks from a Plex server.]' \
  '--plex-audio-artist[Search and play an artist audio tracks from a Plex server.]' \
  '--plex-audio-album[Search and play a music album from a Plex server.]' \
  '--plex-audio-playlist[Search and play playlists from a Plex server.]' \
  '--iheart-search[Iheart station search.]' \
  '--iheart-keywords[Additional keywords that may be used in conjunction with the Iheart search option. Optional (may be repeated).]' \
  '--server[Stream media files using the SHOUTcast/ICEcast streaming protocol.]' \
  '(-p)--port[TCP port to be used for Icecast/SHOUTcast streaming. Optional. Default: 8010.]' \
  '--station-name[The Icecast/SHOUTcast station name. Optional.]' \
  '--station-genre[The Icecast/SHOUTcast station genre. Optional.]' \
  '--no-icy-metadata[Disables Icecast/SHOUTcast metadata in the stream. Optional.]' \
  '--bitrate-modes[A comma-separated list of bitrate modes (e.g. 'CBR,VBR'). Only media with these bitrate modes will be streamed. Optional. Default: any.]' \
  '--sampling-rates[A comma-separated list of sampling rates. Only media with these rates will be streamed. Optional. Default: any.]' \
  '*:files:->mfiles' && rc=0

case $state in

  files)
    compset -P '*,'
    compset -S ',*'
    _files -r ',/ \t\n\-' && rc=0
  ;;

  mfiles)
    local expl
    _tags files urls
    while _tags; do
      _requested files expl 'media file' _files -g \
        "*.(#i)(asf|asx|avi|flac|flv|m1v|m2p|m2v|m4v|mjpg|mka|mkv|mov|mp3|mp4|mpe|mpeg|mpg|ogg|ogm|ogv|qt|rm|ts|vob|wav|webm|wma|wmv)(-.)" && rc=0
      if _requested urls; then
        while _next_label urls expl URL; do
          _urls "$expl[@]" && rc=0
          compadd -S '' "$expl[@]" http:// https:// && rc=0
        done
      fi
      (( rc )) || return 0
    done
  ;;
esac

return rc
