Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # V2. Now supports TV shows and Movies.
- #
- # User token. Take from the URL you have when navigating to the plex server in a browser.
- token=1111111111111111111111111111111111111111
- # Plex URL
- host=http://hostsv.megaspeednet.com
- # Plex server port, default is 32400
- port=32400
- # The media directory you choose to drop scraped media into
- destination=/path/to/directory
- if [ ! -d $destination ]; then mkdir -p $destination; fi
- if [ -f .temp1.xml ]; then rm .temp1.xml; fi
- if [ -f .temp2.xml ]; then rm .temp2.xml; fi
- if [ -f .tempshows.xml ]; then rm .tempshows.xml; fi
- if [ -f .tempshows1.xml ]; then rm .tempshows1.xml; fi
- wget -qO- $host:$port/library/sections?X-Plex-Token=$token > .temp1.xml
- itemCount=`xmllint --xpath 'count(//MediaContainer/Directory)' .temp1.xml`
- movie=()
- show=()
- for (( y=0; y <= $itemCount; y++ )); do
- sectionkey[$y]="$(xmllint --xpath '//MediaContainer/Directory['$y']/@key' .temp1.xml)"
- sectiontype[$y]="$(xmllint --xpath '//MediaContainer/Directory['$y']/@type' .temp1.xml)"
- sectionkey[$y]=${sectionkey[$y]:6:-1}
- sectiontype[$y]=${sectiontype[$y]:7:-1}
- if [[ ${sectiontype[$y]} == "movie" ]] ; then movie+=(${sectionkey[$y]}); fi
- if [[ ${sectiontype[$y]} == "show" ]] ; then show+=(${sectionkey[$y]}); fi
- done
- for (( i=1; i <= $itemsCount; i++ )); do
- tt[$i]="$(xmllint --xpath '//MediaContainer/Video['$i']/Media/Part/@key' .temp.xml)"
- tg[$i]="$(xmllint --xpath '//MediaContainer/Video['$i']/@title' .temp.xml)"
- name=${tg[$i]:8:-1}
- name=${name// /_}
- name=${name//:/_}
- name=${name//!/}
- name=${name//&/&}
- ext=`echo "${tt[$i]}" | cut -d'.' -f2`
- if [ ! -f "$destination$name.${ext:0:-1}" ]; then
- wget --limit-rate $limit -O $destination$name.${ext:0:-1} "$host:$port${tt[$i]:6:-1}?download=1&X-Plex-Token=$token"
- fi
- done
- rm .temp.xml
- done
- for f in "${show[@]}"; do
- wget -qO- $host:$port/library/sections/$f/all?X-Plex-Token=$token >> .tempshows.xml
- hh=`xmllint --xpath 'count(//MediaContainer/Directory)' .tempshows.xml`
- declare -a qq=( )
- for (( i=1; i <= $hh; i++ )); do
- qq[$i]="$(xmllint --xpath '//MediaContainer/Directory['$i']/@key' .tempshows.xml)"
- wget -qO- $host:$port${qq[$i]:6:-9}allLeaves?X-Plex-Token=$token >> .tempshows1.xml
- declare -a tt=( )
- declare -a tg=( )
- jj=`xmllint --xpath 'count(//MediaContainer/Video)' .tempshows1.xml`
- for (( uy=1; uy <= $jj; uy++ )); do
- tt[$uy]="$(xmllint --xpath '//MediaContainer/Video['$uy']/Media/Part/@key' .tempshows1.xml)"
- tg[$uy]="$(xmllint --xpath '//MediaContainer/Video['$uy']/@title' .tempshows1.xml)"
- season[$uy]="$(xmllint --xpath '//MediaContainer/Video['$uy']/@parentIndex' .tempshows1.xml)"
- episode[$uy]="$(xmllint --xpath '//MediaContainer/Video['$uy']/@index' .tempshows1.xml)"
- showname="$(xmllint --xpath '//MediaContainer/@title2' .tempshows1.xml)"
- season[$uy]=${season[$uy]:14:-1}
- episode[$uy]=${episode[$uy]:8:-1}
- showname=${showname:9:-1}
- showname=${showname// /_}
- showname=${showname//:/_}
- showname=${showname//!/}
- showname=${showname//&/&}
- name=${tg[$uy]:8:-1}
- name=${name// /_}
- name=${name//:/_}
- name=${name//!/}
- name=${name//&/&}
- name=${showname}_${season[$uy]}x${episode[$uy]}_$name
- ext=`echo "${tt[$uy]}" | cut -d'.' -f2`
- if [ ! -d $destination$showname ]; then mkdir -p $destination$showname; fi
- if [ ! -f "$destination$showname/$name.${ext:0:-1}" ]; then
- wget --limit-rate $limit -O $destination$showname/$name.${ext:0:-1} "$host:$port${tt[$uy]:6:-1}?download=1&X-Plex-Token=$token"
- fi
- done
- rm .tempshows1.xml
- done
- rm .tempshows.xml
- done
Add Comment
Please, Sign In to add comment