https://cs1-45v4.vk-cdn.net/p20/short_hash_from_filename.240.mp4
https://cs1-44v4.vk-cdn.net/p4/short_hash_from_filename.360.mp4
https://cs1-45v4.vk-cdn.net/p7/short_hash_from_filename.480.mp4
https://cs1-51v4.vk-cdn.net/p7/short_hash_from_filename.720.mp4
.............................................................
./videos
├── 240
│ └── links.txt
├── 360
│ └── links.txt
├── 480
│ └── links.txt
└── 720
└── links.txt
RESOLUTIONS="240 360 …"
for RES in $RESOLUTIONS
do
mkdir $RES
fgrep $RES.mp4 sourcefile > $RES/links.txt
done
#!/bin/bash
mkdir -p ./videos/{240,360,480,720}
FILE_LINKS=$1
RESULT_ROOT="./videos"
RESULT_FILE="links.txt"
HD_PATTERN="^.*\(240\|360\|480\|720\)\.mp4$"
cat $FILE_LINKS | sort | while read LINK;
do
HD=$(echo -e $LINK | sed -e "s%$HD_PATTERN%\1%")
echo "$LINK" >> ${RESULT_ROOT}/${HD}/${RESULT_FILE}
done
#!/bin/bash
get_url()
{
echo "$1"
}
get_subdir()
{
echo "$1" | sed 's/.*\.\([0-9]*\)\.mp4$/\1/'
}
main()
{
ifname="links.txt"
odir="videos"
ofname="links.txt"
[ ! -d "$odir" ] && mkdir "$odir"
cat "$ifname" | while read line; do
ourl=`get_url "$line"`
osubdir=`get_subdir "$line"`
[ ! -d "$odir/$osubdir" ] && mkdir "$odir/$osubdir"
opath="$odir/$osubdir/$ofname"
echo "$ourl" >> "$opath"
done
}
main "$@" || exit 1
exit 0
import os
path = './videos'
videos_dir = ['240', '360', '480', '720']
def write_file(name_file, text):
with open(name_file, 'a') as file:
file.write(text)
def read_file(name_file):
with open(name_file, 'r') as lines:
for line in lines:
write_file(path+'/'+line.split('.')[-2]+'/'+'links.txt', line)
for dir in videos_dir:
try:
os.makedirs(path+'/'+dir)
except FileExistsError:
continue
read_file('link.txt')