Skip to content

Commit e2afd72

Browse files
committed
feat: activer l'automatisation YouTube - détection nouvelles vidéos et mise à jour du site
1 parent 8fa76f6 commit e2afd72

3 files changed

Lines changed: 214 additions & 10 deletions

File tree

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,106 @@
1-
name: social-media-post
2-
3-
permissions:
4-
contents: read
1+
name: 🎵 YouTube Auto-Sync
52

63
on:
7-
# Pour l’instant: uniquement déclenché à la main depuis l’onglet Actions
4+
schedule:
5+
# Vérifie les nouvelles vidéos tous les jours à 10h UTC (12h CEST)
6+
- cron: '0 10 * * *'
7+
push:
8+
branches: [gh-pages]
9+
paths:
10+
- 'music.html'
811
workflow_dispatch:
912

13+
permissions:
14+
contents: write
15+
1016
jobs:
11-
social-post:
17+
youtube-sync:
18+
name: Sync dernières vidéos YouTube
1219
runs-on: ubuntu-latest
1320

1421
steps:
15-
- name: Checkout repository
22+
- name: Checkout
1623
uses: actions/checkout@v4
24+
with:
25+
ref: gh-pages
26+
27+
- name: Setup Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: '3.11'
31+
32+
- name: Installer les dépendances
33+
run: pip install requests
34+
35+
- name: Récupérer les dernières vidéos YouTube
36+
env:
37+
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
38+
run: |
39+
python3 << 'EOF'
40+
import requests
41+
import json
42+
import os
43+
44+
api_key = os.environ.get('YOUTUBE_API_KEY')
45+
channel_handle = 'DavidKRKofficial'
46+
47+
# Étape 1 : Trouver le channelId depuis le handle
48+
search_url = f'https://www.googleapis.com/youtube/v3/search?key={api_key}&q={channel_handle}&type=channel&part=snippet&maxResults=1'
49+
r = requests.get(search_url)
50+
data = r.json()
51+
52+
if 'items' not in data or len(data['items']) == 0:
53+
print('Erreur: chaîne YouTube introuvable')
54+
exit(1)
55+
56+
channel_id = data['items'][0]['snippet']['channelId']
57+
print(f'Channel ID trouvé: {channel_id}')
58+
59+
# Étape 2 : Récupérer les 6 dernières vidéos
60+
videos_url = f'https://www.googleapis.com/youtube/v3/search?key={api_key}&channelId={channel_id}&part=snippet,id&order=date&maxResults=6&type=video'
61+
r2 = requests.get(videos_url)
62+
videos = r2.json()
63+
64+
if 'items' not in videos:
65+
print('Erreur: impossible de récupérer les vidéos')
66+
print(videos)
67+
exit(1)
68+
69+
# Étape 3 : Générer le JSON pour le site
70+
video_list = []
71+
for item in videos['items']:
72+
video_id = item['id']['videoId']
73+
title = item['snippet']['title']
74+
thumb = item['snippet']['thumbnails']['high']['url']
75+
published = item['snippet']['publishedAt'][:10]
76+
video_list.append({
77+
'id': video_id,
78+
'title': title,
79+
'thumbnail': thumb,
80+
'published': published,
81+
'url': f'https://www.youtube.com/watch?v={video_id}'
82+
})
83+
84+
with open('assets/data/youtube-videos.json', 'w', encoding='utf-8') as f:
85+
json.dump(video_list, f, ensure_ascii=False, indent=2)
86+
87+
print(f'{len(video_list)} vidéos sauvegardées dans assets/data/youtube-videos.json')
88+
for v in video_list:
89+
print(f" - [{v[\"published\"]}] {v[\"title\"]}")
90+
EOF
91+
92+
- name: Créer le dossier data si nécessaire
93+
run: mkdir -p assets/data
1794

18-
- name: Placeholder social post
95+
- name: Commit et push si nouvelles vidéos
1996
run: |
20-
echo "Social media auto-post non configuré pour le moment."
21-
echo "Ce workflow existe juste pour que le badge soit vert."
97+
git config user.name "github-actions[bot]"
98+
git config user.email "github-actions[bot]@users.noreply.github.com"
99+
git add assets/data/youtube-videos.json
100+
if git diff --staged --quiet; then
101+
echo "Aucune nouvelle vidéo détectée."
102+
else
103+
git commit -m "🎵 Auto-sync: mise à jour des vidéos YouTube $(date +%Y-%m-%d)"
104+
git push
105+
echo "Vidéos mises à jour et pushées !"
106+
fi
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: 🌐 Mise à jour section YouTube du site
2+
3+
on:
4+
push:
5+
branches: [gh-pages]
6+
paths:
7+
- 'assets/data/youtube-videos.json'
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
update-music-page:
15+
name: Injecter les vidéos dans music.html
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
ref: gh-pages
23+
24+
- name: Setup Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.11'
28+
29+
- name: Injecter les vidéos YouTube dans music.html
30+
run: |
31+
python3 << 'EOF'
32+
import json
33+
import re
34+
35+
with open('assets/data/youtube-videos.json', 'r', encoding='utf-8') as f:
36+
videos = json.load(f)
37+
38+
# Générer le HTML de la grille vidéos
39+
cards = ''
40+
for v in videos:
41+
if v['id'] == 'placeholder':
42+
continue
43+
cards += f'''
44+
<a href="{v['url']}" target="_blank" rel="noopener noreferrer" class="yt-card">
45+
<div class="yt-thumb">
46+
<img src="{v['thumbnail']}" alt="{v['title']}" loading="lazy" width="320" height="180">
47+
<span class="yt-play">▶</span>
48+
</div>
49+
<p class="yt-title">{v['title']}</p>
50+
<span class="yt-date">{v['published']}</span>
51+
</a>'''
52+
53+
youtube_block = f'''<!-- YOUTUBE-AUTO-START -->
54+
<div class="yt-grid">
55+
<a href="https://www.youtube.com/@DavidKRKofficial" target="_blank" rel="noopener noreferrer" class="yt-channel-link">🎬 Voir toutes les vidéos sur YouTube</a>
56+
<div class="yt-cards">{cards}
57+
</div>
58+
</div>
59+
<!-- YOUTUBE-AUTO-END -->'''
60+
61+
with open('music.html', 'r', encoding='utf-8') as f:
62+
content = f.read()
63+
64+
# Remplacer le bloc existant ou injecter avant </main>
65+
pattern = r'<!-- YOUTUBE-AUTO-START -->.*?<!-- YOUTUBE-AUTO-END -->'
66+
if re.search(pattern, content, re.DOTALL):
67+
content = re.sub(pattern, youtube_block, content, flags=re.DOTALL)
68+
else:
69+
content = content.replace('</main>', youtube_block + '\n </main>')
70+
71+
with open('music.html', 'w', encoding='utf-8') as f:
72+
f.write(content)
73+
74+
print('music.html mis à jour avec les vidéos YouTube !')
75+
EOF
76+
77+
- name: Injecter le CSS YouTube dans assets/css/style.css
78+
run: |
79+
if ! grep -q 'yt-grid' assets/css/style.css; then
80+
cat >> assets/css/style.css << 'CSSEOF'
81+
82+
/* === YouTube Auto-Section === */
83+
.yt-grid { max-width: 960px; margin: 2rem auto; padding: 0 1rem; text-align: center; }
84+
.yt-channel-link { display: inline-block; margin-bottom: 1.5rem; color: #ff0000; font-weight: bold; font-size: 1.1rem; text-decoration: none; }
85+
.yt-channel-link:hover { opacity: 0.8; }
86+
.yt-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; }
87+
.yt-card { display: flex; flex-direction: column; background: rgba(0,0,0,0.45); border-radius: 10px; overflow: hidden; text-decoration: none; color: #fff; transition: transform 0.2s ease, box-shadow 0.2s ease; }
88+
.yt-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(255,0,0,0.2); }
89+
.yt-thumb { position: relative; }
90+
.yt-thumb img { width: 100%; height: 180px; object-fit: cover; display: block; }
91+
.yt-play { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 2.5rem; opacity: 0.85; pointer-events: none; }
92+
.yt-title { padding: 0.6rem 0.8rem 0.2rem; font-size: 0.9rem; font-weight: 600; text-align: left; }
93+
.yt-date { padding: 0 0.8rem 0.8rem; font-size: 0.75rem; color: #aaa; text-align: left; }
94+
CSSEOF
95+
echo 'CSS YouTube ajouté à style.css'
96+
else
97+
echo 'CSS YouTube déjà présent dans style.css'
98+
fi
99+
100+
- name: Commit et push
101+
run: |
102+
git config user.name "github-actions[bot]"
103+
git config user.email "github-actions[bot]@users.noreply.github.com"
104+
git add music.html assets/css/style.css
105+
if git diff --staged --quiet; then
106+
echo "Aucun changement à commiter."
107+
else
108+
git commit -m "🌐 Auto-update: section YouTube mise à jour sur music.html"
109+
git push
110+
fi

assets/data/youtube-videos.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"id": "placeholder",
4+
"title": "Chargement des vidéos YouTube...",
5+
"thumbnail": "",
6+
"published": "2026-01-01",
7+
"url": "https://www.youtube.com/@DavidKRKofficial"
8+
}
9+
]

0 commit comments

Comments
 (0)