diff options
Diffstat (limited to 'lib/_ak_zchain')
-rwxr-xr-x | lib/_ak_zchain | 71 |
1 files changed, 64 insertions, 7 deletions
diff --git a/lib/_ak_zchain b/lib/_ak_zchain index 0c1ae9d..0d1ba57 100755 --- a/lib/_ak_zchain +++ b/lib/_ak_zchain @@ -17,10 +17,12 @@ ### You should have received a copy of the GNU General Public License ### along with this program. If not, see <http://www.gnu.org/licenses/>. ### -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_zblock -source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_lib_load +_ak_lib_load _ak_script +_ak_lib_load _ak_datetime +_ak_lib_load _ak_log +_ak_lib_load _ak_ipfs +_ak_lib_load _ak_zblock function _ak_zchain_reset(){ _ak_log_info "Reseting AK_ZLATEST to AK_ZGENESIS" @@ -48,7 +50,7 @@ function _ak_zchain_reset(){ if [ $? -eq 0 ] then _ak_log_info "Archive the previous AK_ZLATEST" - _ak_ipfs_files_cp /zlatest /zarchive/$(date -u +%s)-$(_ak_ipfs_files_stat /zlatest | head -n 1) + _ak_ipfs_files_cp /zlatest /zarchive/$(_ak_datetime_unix)-$(_ak_ipfs_files_stat /zlatest | head -n 1) if [ $? -ne 0 ] then _ak_log_error "Failed to copy /zlatest to /zarchive" @@ -99,7 +101,7 @@ function _ak_zchain_rebase(){ _ak_ipfs_files_mkdir /zarchive if [ $? != 0 ]; then echo "Folder already there"; fi echo "Archive the previous ZLATEST" - _ak_ipfs_files_cp /zlatest /zarchive/$(date -u +%s)-$(_ak_ipfs_files_stat /zlatest | head -n 1) + _ak_ipfs_files_cp /zlatest /zarchive/$(_ak_datetime_unix)-$(_ak_ipfs_files_stat /zlatest | head -n 1) if [ $? != 0 ]; then exit 1; fi echo "Removing previous /zlatest entry" _ak_ipfs_files_rm /zlatest @@ -282,7 +284,7 @@ function _ak_zchain_crawl_remote_ipns(){ } function _ak_zchain_get_latest(){ - _ak_ipfs_files_stat /zlatest | head -n 1| tr -d '\n' + cat $AK_ZLATEST | tr -d '\n' } # _ak_zchain_announce(){} @@ -486,3 +488,58 @@ function _ak_zchain_get_latest(){ # fi # done # } + +function _ak_zchain_output_types(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + zblock="$(ak zchain --get-latest)" + else + zblock="$1" + fi + seed="$(cat $AK_ZGENESIS)" + previous="$(_ak_zblock_show "$zblock" | jq -r '.previous')" + timestamp="$(_ak_zblock_show "$zblock" | jq -r '.timestamp')" + block="$(_ak_zblock_show "$zblock" | jq -r '.block')" + data="$(_ak_zblock_show "$zblock" | jq -r '.data')" + ak zblock --show $zblock | jq -r '.zblock,.module' | tr $'\n' ' ' | sed -e 's/ $/\n/' | while read zblock module + do + if [ "$module" == "mixtape" ] + then + ipfs="$(_ak_ipfs_cat $data | jq -r '.ipfs')" + file $AK_IPFS_ARTIFACTS/$ipfs | grep 'Ogg' > /dev/null + if [ $? -eq 0 ] + then + fdur="$(ogginfo $AK_IPFS_ARTIFACTS/$ipfs | grep 'Playback length' | cut -d ':' -f 2-)" + mins="$(echo -n $fdur | cut -d 'm' -f 1)" + secs="$(echo -n $fdur | cut -d ':' -f 2|cut -d '.' -f 1)" + msecs="$(echo -n $fdur | cut -d ':' -f 2|cut -d '.' -f 2 | cut -d 's' -f 1)" + smins="$(($mins * 60))" + #echo "$mins => $smins" + #echo "Duration is $mins minutes, $secs seconds and $msecs milliseconds" + if [ $msecs -gt 0 ] + then + sdur="$(( $smins + $secs + 1))" + else + sdur="$(( $smins + $secs))" + fi + #echo "Zblock: $zblock is a $module type added on $timestamp with duration $sdur seconds" + #echo "Output to file would be:" + echo "$timestamp $zblock $block $data $ipfs $sdur" >> $AK_WORKDIR/mixtapes_index + tmpfile="$(_ak_make_temp_file)" + cat $AK_WORKDIR/mixtapes_index | sort -n | uniq > $tmpfile + cat $tmpfile > $AK_WORKDIR/mixtapes_index + rm $tmpfile + fi + else + echo "Zblock: $zblock is a $module type added on $timestamp" + fi + done + if [ "$seed" == "$previous" ] + then + _ak_log_info "Reached genesis, exiting..." + exit 0 + fi + _ak_zchain_output_types $previous +} + +_ak_log_debug "_ak_zchain loaded $(caller)" |