📜 ⬆️ ⬇️

Podcasts and programming

Long listening to the podcast "Tits Pussy Show", I realized that I got a job! :-)

The podcast was so exciting that I could not put it down. And then I decided that it would be nice to listen to him in the subway. So, I have a PDA that can connect to a computer like a USB flash drive.

From here I had 2 tasks:

For the work!

For programmers there are no unsolvable problems.
')
We solve the first problem. We need a script that downloads all podcasts from a page based on a URL. A good function would be to stop if the podcast is already present on the media (for downloading only new ones).

In the course of work, I got the following script:

#!/bin/bash

#
function usage
{
echo 'Usage: rpod-get.sh -u -f <dest. folder> [-s | -d]'
echo ' -u url'
echo ' -f folder path'
echo ' -d delete old files'
echo ' -s stop on old file'
}

#
TMP=`getopt -ou:f:sd -n 'rpod-get.sh' '--' "$@"`
if [ $? != 0 ] ; then usage; exit 1; fi
eval set '--' "$TMP"
DELETE_OLD_FILES=0
STOP_ON_OLD_FILE=0
while true ; do
case "$1" in
-u) URL=$2; shift 2;;
-f) FOLDER=$2; shift 2;;
-d) DELETE_OLD_FILES=1 ; shift ;;
-s) STOP_ON_OLD_FILE=1 ; shift ;;
--) shift ; break ;;
esac
done

#
if [ "$URL" = "" ]; then
usage
exit 1
fi
if [ "$FOLDER" = "" ]; then
usage
exit 1
fi
if [ "$DELETE_OLD_FILES" -eq "1" -a "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo "Cannot use -s and -d args together"
usage
exit 1
fi

# mp3-
LINKS=`wget -cq -O - $URL | grep 'mp3?' | iconv -f cp1251 -t utf-8 | sed -r -e 's/.*"(.*)".*/\1/'`

#
DONE=0

#
for LINK in $LINKS; do
FILENAME=`echo $LINK | sed -r -e 's/.*\/([^\/]+)\?.*/\1/'`
if [ -e $FOLDER/$FILENAME ]; then
if [ "$DELETE_OLD_FILES" -eq "1" ]; then
rm $FOLDER/$FILENAME
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
if [ "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo $DONE
exit 0
fi
else
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
done
echo $DONE

?
, siski-piski-show.rpod.ru . -s - .

.


, . . .

#!/bin/bash

#
function usage
{
echo 'Usage: rpod-get.sh -u -f <dest. folder> [-s | -d]'
echo ' -u url'
echo ' -f folder path'
echo ' -d delete old files'
echo ' -s stop on old file'
}

#
TMP=`getopt -ou:f:sd -n 'rpod-get.sh' '--' "$@"`
if [ $? != 0 ] ; then usage; exit 1; fi
eval set '--' "$TMP"
DELETE_OLD_FILES=0
STOP_ON_OLD_FILE=0
while true ; do
case "$1" in
-u) URL=$2; shift 2;;
-f) FOLDER=$2; shift 2;;
-d) DELETE_OLD_FILES=1 ; shift ;;
-s) STOP_ON_OLD_FILE=1 ; shift ;;
--) shift ; break ;;
esac
done

#
if [ "$URL" = "" ]; then
usage
exit 1
fi
if [ "$FOLDER" = "" ]; then
usage
exit 1
fi
if [ "$DELETE_OLD_FILES" -eq "1" -a "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo "Cannot use -s and -d args together"
usage
exit 1
fi

# mp3-
LINKS=`wget -cq -O - $URL | grep 'mp3?' | iconv -f cp1251 -t utf-8 | sed -r -e 's/.*"(.*)".*/\1/'`

#
DONE=0

#
for LINK in $LINKS; do
FILENAME=`echo $LINK | sed -r -e 's/.*\/([^\/]+)\?.*/\1/'`
if [ -e $FOLDER/$FILENAME ]; then
if [ "$DELETE_OLD_FILES" -eq "1" ]; then
rm $FOLDER/$FILENAME
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
if [ "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo $DONE
exit 0
fi
else
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
done
echo $DONE

?
, siski-piski-show.rpod.ru . -s - .

.


, . . .

#!/bin/bash

#
function usage
{
echo 'Usage: rpod-get.sh -u -f <dest. folder> [-s | -d]'
echo ' -u url'
echo ' -f folder path'
echo ' -d delete old files'
echo ' -s stop on old file'
}

#
TMP=`getopt -ou:f:sd -n 'rpod-get.sh' '--' "$@"`
if [ $? != 0 ] ; then usage; exit 1; fi
eval set '--' "$TMP"
DELETE_OLD_FILES=0
STOP_ON_OLD_FILE=0
while true ; do
case "$1" in
-u) URL=$2; shift 2;;
-f) FOLDER=$2; shift 2;;
-d) DELETE_OLD_FILES=1 ; shift ;;
-s) STOP_ON_OLD_FILE=1 ; shift ;;
--) shift ; break ;;
esac
done

#
if [ "$URL" = "" ]; then
usage
exit 1
fi
if [ "$FOLDER" = "" ]; then
usage
exit 1
fi
if [ "$DELETE_OLD_FILES" -eq "1" -a "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo "Cannot use -s and -d args together"
usage
exit 1
fi

# mp3-
LINKS=`wget -cq -O - $URL | grep 'mp3?' | iconv -f cp1251 -t utf-8 | sed -r -e 's/.*"(.*)".*/\1/'`

#
DONE=0

#
for LINK in $LINKS; do
FILENAME=`echo $LINK | sed -r -e 's/.*\/([^\/]+)\?.*/\1/'`
if [ -e $FOLDER/$FILENAME ]; then
if [ "$DELETE_OLD_FILES" -eq "1" ]; then
rm $FOLDER/$FILENAME
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
if [ "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo $DONE
exit 0
fi
else
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
done
echo $DONE

?
, siski-piski-show.rpod.ru . -s - .

.


, . . .

#!/bin/bash

#
function usage
{
echo 'Usage: rpod-get.sh -u -f <dest. folder> [-s | -d]'
echo ' -u url'
echo ' -f folder path'
echo ' -d delete old files'
echo ' -s stop on old file'
}

#
TMP=`getopt -ou:f:sd -n 'rpod-get.sh' '--' "$@"`
if [ $? != 0 ] ; then usage; exit 1; fi
eval set '--' "$TMP"
DELETE_OLD_FILES=0
STOP_ON_OLD_FILE=0
while true ; do
case "$1" in
-u) URL=$2; shift 2;;
-f) FOLDER=$2; shift 2;;
-d) DELETE_OLD_FILES=1 ; shift ;;
-s) STOP_ON_OLD_FILE=1 ; shift ;;
--) shift ; break ;;
esac
done

#
if [ "$URL" = "" ]; then
usage
exit 1
fi
if [ "$FOLDER" = "" ]; then
usage
exit 1
fi
if [ "$DELETE_OLD_FILES" -eq "1" -a "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo "Cannot use -s and -d args together"
usage
exit 1
fi

# mp3-
LINKS=`wget -cq -O - $URL | grep 'mp3?' | iconv -f cp1251 -t utf-8 | sed -r -e 's/.*"(.*)".*/\1/'`

#
DONE=0

#
for LINK in $LINKS; do
FILENAME=`echo $LINK | sed -r -e 's/.*\/([^\/]+)\?.*/\1/'`
if [ -e $FOLDER/$FILENAME ]; then
if [ "$DELETE_OLD_FILES" -eq "1" ]; then
rm $FOLDER/$FILENAME
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
if [ "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo $DONE
exit 0
fi
else
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
done
echo $DONE

?
, siski-piski-show.rpod.ru . -s - .

.


, . . .

#!/bin/bash

#
function usage
{
echo 'Usage: rpod-get.sh -u -f <dest. folder> [-s | -d]'
echo ' -u url'
echo ' -f folder path'
echo ' -d delete old files'
echo ' -s stop on old file'
}

#
TMP=`getopt -ou:f:sd -n 'rpod-get.sh' '--' "$@"`
if [ $? != 0 ] ; then usage; exit 1; fi
eval set '--' "$TMP"
DELETE_OLD_FILES=0
STOP_ON_OLD_FILE=0
while true ; do
case "$1" in
-u) URL=$2; shift 2;;
-f) FOLDER=$2; shift 2;;
-d) DELETE_OLD_FILES=1 ; shift ;;
-s) STOP_ON_OLD_FILE=1 ; shift ;;
--) shift ; break ;;
esac
done

#
if [ "$URL" = "" ]; then
usage
exit 1
fi
if [ "$FOLDER" = "" ]; then
usage
exit 1
fi
if [ "$DELETE_OLD_FILES" -eq "1" -a "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo "Cannot use -s and -d args together"
usage
exit 1
fi

# mp3-
LINKS=`wget -cq -O - $URL | grep 'mp3?' | iconv -f cp1251 -t utf-8 | sed -r -e 's/.*"(.*)".*/\1/'`

#
DONE=0

#
for LINK in $LINKS; do
FILENAME=`echo $LINK | sed -r -e 's/.*\/([^\/]+)\?.*/\1/'`
if [ -e $FOLDER/$FILENAME ]; then
if [ "$DELETE_OLD_FILES" -eq "1" ]; then
rm $FOLDER/$FILENAME
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
if [ "$STOP_ON_OLD_FILE" -eq "1" ]; then
echo $DONE
exit 0
fi
else
wget -cq -O $FOLDER/$FILENAME $LINK
let DONE=$DONE+1
fi
done
echo $DONE

?
, siski-piski-show.rpod.ru . -s - .

.


, . . .

Source: https://habr.com/ru/post/27080/


All Articles