-
Notifications
You must be signed in to change notification settings - Fork 1
/
m3u.sh
64 lines (59 loc) · 2.46 KB
/
m3u.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
KEY="XXXXX-XXX-XXX-XXX-XXXXX"
if [ -z $1 ]
then
echo "usage m3u.sh /opt/rclone/Film ftp://synology.me TEST"
exit 0
fi
if [ -z $2 ]
then
echo "usage m3u.sh /opt/rclone/Film ftp://synology.me TEST"
exit 0
fi
if [ -z $3 ]
then
echo "usage m3u.sh /opt/rclone/Film ftp://synology.me TEST"
exit 0
fi
pattern=$2
echo pattern is $pattern
echo "#EXTM3U" > /opt/$3.m3u
find "$1" -type f -name *.mkv -o -name *.iso -o -name *.m2ts -o -name *.mp4 -o -name *.mp3 -o -name *.flac | sed "s+$1+$2+g" > /opt/$3.txt
while IFS= read -r line; do
#exclude xattr folder
echo $line | grep ".xattr"
if [ $? -eq 0 ]
then
continue
fi
FILESIZE=$(ls -lh "$(echo $line | sed "s+$2+$1+g")" | awk '{print $5}')
echo "Size of $line = $FILESIZE"
name=$(echo $line | sed "s+$pattern++g" | rev | cut -d "/" -f 2- | rev )
nname=$(echo $line | sed "s+$pattern++g" | rev | cut -d "/" -f 1 | rev | cut -d "." -f 1)
rev_name=$(echo $line | sed "s+$pattern++g" | rev | cut -d "/" -f 1 | rev | cut -d "." -f 1 | tr "_" " " | tr "-" " ")
post=$(echo $line | sed "s+$2+$1+g")
poster_path=${post%.*}
postter=$poster_path"-poster.jpg"
fake_poster=$(echo $pattern${name}/poster.jpg | sed "s+$2+$1+g")
# get kp id from name search
real_kp=$(echo $line | grep -oP 'kp-\K\w+')
if [ -z $real_kp ]
then
kp=$(curl -k --silent -G "https://kinopoiskapiunofficial.tech/api/v2.1/films/search-by-keyword" --data-urlencode "keyword=$rev_name" -H "accept: application/json" -H "X-API-KEY: $KEY" | jq -r '.films[0].filmId')
else
kp=$real_kp
fi
#posters
if [ -f "$postter" ]; then
poster=$(echo $postter | sed "s+$1+$2+g" | sed "s+ +%20+g")
elif [ -f "$fake_poster" ]; then
poster=$(echo $pattern${name}/poster.jpg | sed "s+ +%20+g")
else
poster=$(curl -k --silent -X GET "https://kinopoiskapiunofficial.tech/api/v2.2/films/$kp" -H "accept: application/json" -H "X-API-KEY: $KEY" | jq -r '.posterUrl')
fi
#get m3u options from api
options=$(curl -k --silent -X GET "https://kinopoiskapiunofficial.tech/api/v2.2/films/$kp" -H "accept: application/json" -H "X-API-KEY: $KEY" | jq -r '. | "video-title=\"\(.countries[0].country).\(.year).(КП:\(.ratingKinopoisk) | IMDb:\(.ratingImdb))\" video-desc=\"\(.description)\" group-title=\"\(.genres[0].genre)\"" ')
#form m3u
echo "#EXTINF:-1 $(echo $options | tr -d '\011\012\013\015') tvg-logo=\"$poster\", $name/$nname | $FILESIZE" >> /opt/$3.m3u
echo $line >> /opt/$3.m3u
done < /opt/$3.txt