#!/bin/bash
input_path=""
input_id=""
while [ "$input_id" = "" ] || [ -d $input_path ]
do
if [ "$input_id" = "" ]; then
echo "Enter the directory ID where the files to located(/root/yt/v/$ID):"
else
echo "Directory:'$input_path' already exists! Reenter:"
fi
read input_id
input_path="/root/yt/v/$input_id"
done
mkdir -p "$input_path"
cd "$input_path"
echo "Current in '$(pwd)', input 'y' to continue:"
read input_y
if [ "$input_y" != "y" ]; then
exit
fi
input_url=""
input_y=""
while [ "$input_y" != "y" ] || [ "${input_url:0:5}" != "https" ]
do
if [ "$input_url" != "" ] && [ "${input_url:0:5}" != "https" ]; then
echo "Input URL:'${input_url}' is invalid, please type in like 'https://www.youtube.com/playlist?list=XX'"
else
echo "Enter the palylist page URL:"
fi
read input_url
if [ "${input_url:0:5}" != "https" ]; then
continue
fi
echo "Current URL is '$input_url', input 'y' to continue or Reenter URL:"
read input_y
done
echo $(yt-dlp -i "$input_url")
echo ">>>>url: $input_url :" |tee -a "${input_path}/n.log"
echo ">>>>path: $input_path :" |tee -a "${input_path}/n.log"
mp4_count=0
title=""
for file in *;do
#echo "$file"
suffix=${file##*.}
#echo "$suffix"
if [ "$suffix" != "mp4" ]; then
continue
fi
if [ "$title" = "" ]; then
title=${file%[*}
#echo "\${file%.*} ${file%.*}"
#echo "\${file%%.*} ${file%%.*}"
fi
mp4_count=$((mp4_count+1))
#if [ $i -lt 10 ]; then
#mv "$file" "0$i.$suffix"
#else
mv "./$file" "$mp4_count.$suffix"
echo "\"$file\" -->> $mp4_count.$suffix" |tee -a "${input_path}/n.log"
#fi
done
echo "mp4 files count: $mp4_count" |tee -a "${input_path}/n.log"
echo "SQL ->->:" |tee -a "${input_path}/n.log"
echo "INSERT INTO \`t_user\` (\`email\`, \`full_name\`, \`picture_url\`, \`user_type\`, \`user_status\`, \`creator\`, \`create_status\`, \`third_user_id\`, \`wallet_address\`, \`pass_word\`, \`create_time\`) VALUES ('yt${input_id}@qq.com', NULL, NULL, 4, 0, 2, 4, NULL, NULL, '66E01CC791F37FCC4676B29497A6137C', '2024-01-16 09:11:53');" | tee -a "${input_path}/n.log"
echo "SET @user_id = LAST_INSERT_ID();" | tee -a "${input_path}/n.log"
echo "SET @collection_id = ${input_id};" | tee -a "${input_path}/n.log"
echo "SET @title = '${title}';" | tee -a "${input_path}/n.log"
echo "SET @mp4_count = ${mp4_count};" | tee -a "${input_path}/n.log"
echo "#SET @collection_id = 101;" | tee -a "${input_path}/n.log"
echo "#SET @title = 'test';" | tee -a "${input_path}/n.log"
echo "#SET @mp4_count = 3;" | tee -a "${input_path}/n.log"
echo "INSERT INTO \`t_account\` (\`user_id\`, \`balance\`, \`create_time\`, \`update_time\`) VALUES (@user_id, 0.00, '2024-01-16 09:11:53', '2024-01-16 09:11:53');" | tee -a "${input_path}/n.log"
echo "INSERT INTO \`t_creator\` ( \`user_id\`, \`email\`, \`name\`, \`phone\`, \`create_time\`) VALUES (@user_id, 'yt${input_id}@qq.com', 'yt${input_id}', '16657109069', '2024-01-16 14:37:57');" | tee -a "${input_path}/n.log"
echo "INSERT INTO \`t_videos_collection\` (\`collection_id\`, \`user_id\`, \`title\`, \`description\`, \`cover_url\`, \`category_id\`, \`tag_id\`, \`number_upload_episodes\`, \`collection_sort\`, \`collection_label\`, \`create_time\`, \`update_time\`, \`status\`) VALUES (@collection_id, @user_id, @title, @title, '', NULL, NULL, @mp4_count, 1, NULL, NULL, NULL, 1);" | tee -a "${input_path}/n.log"
for ((i = 1; i <= ${mp4_count}; ++i)); do
echo "INSERT INTO \`t_single_videos\` (\`episodes\`, \`user_id\`, \`title\`, \`description\`, \`cover_url\`, \`videos_url\`, \`video_price\`, \`duration\`, \`collection_id\`, \`category_id\`, \`tag_id\`, \`create_time\`, \`update_time\`, \`lock_status\`, \`status\`) VALUES (@mp4_count, @user_id, NULL, NULL, NULL, 'https://www.fireroll.net/api/file/v/${i}.mp4', 0.00, NULL, @collection_id, NULL, NULL, NULL, NULL, 1, 1);" | tee -a "${input_path}/n.log"
done
shell脚本抓取视频,SQL入库
最新推荐文章于 2025-04-11 13:46:39 发布