Update Icons #189
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Icons | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
update-icons: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Clone fanmingming/live | |
run: | | |
git clone --depth 1 --branch main https://github.com/fanmingming/live.git | |
mkdir -p icon | |
mkdir -p icon_new | |
for file in live/tv/*.png; do | |
filename=$(basename "$file" .png | tr '[:lower:]' '[:upper:]' | sed -E 's/[ _-]//g; s/频道$|頻道$|电视台$|電視台$|電視臺$|台$|臺$//g') | |
cp "$file" "icon_new/${filename}.png" | |
done | |
- name: Clone taksssss/TVlogo | |
run: | | |
git clone --depth 1 --branch main https://github.com/taksssss/TVlogo.git | |
- name: Extract channel icons from markdown files | |
run: | | |
md_files="TVlogo/md/*.md" | |
for md_file in $md_files; do | |
while IFS= read -r line; do | |
echo "$line" | awk -F'|' ' | |
{ | |
for (i = 2; i <= NF; i += 2) { | |
channel_name = $i | |
match($(i + 1), /<img src="([^"]+)"/, arr) | |
image_url = arr[1] | |
if (channel_name && image_url) { | |
gsub(/https:\/\/raw.githubusercontent.com\/taksssss\/TVlogo\/.*\/img\//, "TVlogo/img/", image_url) | |
gsub(/[ _-]/, "", channel_name) | |
channel_name = toupper(channel_name) | |
sub(/频道$|頻道$|电视台$|電視台$|電視臺$|台$|臺$/, "", channel_name) | |
printf "%s:%s\n", channel_name, image_url | |
} | |
} | |
} | |
' | while IFS=: read -r channel_name image_url; do | |
target_path="TVlogo/img/$channel_name.png" | |
[[ "$image_url" != "$target_path" ]] && mv "$image_url" "$target_path" || echo "Skipped moving $image_url" | |
done | |
done < "$md_file" | |
done | |
- name: Filter and Copy Icons | |
run: | | |
ignore_keywords=("CCTV") | |
for file in TVlogo/img/*.png; do | |
filename=$(basename "$file") | |
for keyword in "${ignore_keywords[@]}"; do | |
if [[ $filename == *"$keyword"* ]]; then | |
continue 2 | |
fi | |
done | |
cp "$file" "icon_new/$filename" | |
done | |
- name: Fetch and Parse 51zmt Icons | |
run: | | |
if curl --fail -o assets/51zmt.m3u.tmp http://epg.51zmt.top:8000/test.m3u; then | |
mv assets/51zmt.m3u.tmp assets/51zmt.m3u | |
else | |
rm assets/51zmt.m3u.tmp 2>/dev/null | |
echo "下载失败,保持原文件不变" | |
fi | |
awk -F'tvg-logo=|tvg-name="' '/#EXTINF/ { | |
match($2, /"([^"]+)"/, logo); | |
match($3, /([^"]+)"/, name); | |
if (logo[1] && name[1]) { | |
gsub(/[ _-]/, "", name[1]); | |
name[1] = toupper(name[1]); | |
sub(/频道$|頻道$|电视台$|電視台$|電視臺$|台$|臺$/, "", name[1]); | |
printf "%s %s\n", name[1], logo[1]; | |
} | |
}' assets/51zmt.m3u | while read -r tvg_name tvg_logo; do | |
output_file="icon_new/${tvg_name}.png" | |
if [ ! -f "$output_file" ]; then | |
echo "$tvg_logo $output_file" | |
fi | |
done | xargs -P 8 -n 2 bash -c 'curl -s "$0" -o "$1"' | |
- name: Fetch and Parse livednow Icons | |
env: | |
PROXY_URL: ${{ secrets.PROXY_URL }} | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y opencc | |
curl -x "$PROXY_URL" -o guide.html https://assets.livednow.com/guide.html | |
awk -F'\\| *' '/\| *频道 ID *\| *频道名称 *\| *Logo URL *\| *EPG 状态 */ { | |
getline; | |
} | |
NF > 3 { | |
gsub(/`|\\/, "", $4); | |
gsub(/\*\*/, "", $3); | |
channel_name = toupper($3); | |
gsub(/[ _-]/, "", channel_name); | |
sub(/频道$|頻道$|电视台$|電視台$|電視臺$|台$|臺$/, "", channel_name); | |
if ($4 != "" && !index(channel_name, "CCTV") && $4 ~ /^(http|https):\/\/[^\s]+/) { | |
printf "%s %s\n", channel_name, $4; | |
} | |
}' guide.html | while read -r channel_name logo_url; do | |
simp_channel_name=$(echo "$channel_name" | opencc -c t2s) | |
output_file="icon_new/${simp_channel_name}.png" | |
if [ ! -f "$output_file" ]; then | |
if [ ! -f "assets/livednow/${simp_channel_name}.png" ]; then | |
echo "Downloading $logo_url as $output_file" | |
curl -x "$PROXY_URL" -s "$logo_url" -o "$output_file" | |
else | |
echo "Copying existing file to $output_file" | |
cp "assets/livednow/${simp_channel_name}.png" "$output_file" | |
fi | |
else | |
echo "$output_file already exists, skipping" | |
fi | |
done | |
- name: Copy GDCMCCIPTV, MyUKJ and Others Icons | |
run: | | |
for folder in assets/gdcmcciptv assets/myukj assets/others; do | |
for file in $folder/*.png; do | |
filename=$(basename "$file" .png | tr '[:lower:]' '[:upper:]' | sed 's/[ _-]//g') | |
if [ ! -f "icon_new/${filename}.png" ]; then | |
echo "Copying $filename to icon_new" | |
cp "$file" "icon_new/${filename}.png" | |
fi | |
done | |
done | |
- name: Crop Icons | |
run: | | |
for file in icon_new/*.png; do | |
if [ -f "$file" ]; then | |
echo "Processing $file" | |
convert "$file" -trim -resize 600x\> "$file" || echo "Failed to process $file" | |
else | |
echo "File $file does not exist" | |
fi | |
done | |
- name: Compare and Replace | |
run: | | |
for new_file in icon_new/*.png; do | |
filename=$(basename "$new_file") | |
if [ ! -f "icon/$filename" ] || ! compare -metric AE "$new_file" "icon/$filename" null: 2> /dev/null; then | |
cp "$new_file" "icon/$filename" | |
fi | |
done | |
# for old_file in icon/*.png; do | |
# filename=$(basename "$old_file") | |
# if [ ! -f "icon_new/$filename" ]; then | |
# rm "$old_file" | |
# fi | |
# done | |
- name: Generate iconList_default.json | |
run: | | |
echo '{' > iconList_default.json | |
for file in icon/*.png; do | |
filename=$(basename "$file" .png) | |
echo "\"$filename\": \"https://gcore.jsdelivr.net/gh/taksssss/tv/icon/$filename.png\"," >> iconList_default.json | |
done | |
sed -i '$ s/,$//' iconList_default.json | |
echo '}' >> iconList_default.json | |
- name: Commit Changes | |
run: | | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
git add icon iconList_default.json assets/51zmt.m3u | |
git commit -m "Update icons and icon list" || echo "No changes to commit" | |
git push |