|
1 | | -name: YouTube Auto-Sync |
| 1 | +name: social-media-post |
2 | 2 |
|
3 | 3 | on: |
4 | | - schedule: |
5 | | - - cron: '0 10 * * *' |
6 | | - push: |
7 | | - branches: [gh-pages] |
8 | | - paths: |
9 | | - - 'music.html' |
| 4 | + # Pour l'instant: uniquement déclenché à la main depuis l'onglet Actions |
10 | 5 | workflow_dispatch: |
11 | 6 |
|
12 | | -permissions: |
13 | | - contents: write |
14 | | - |
15 | 7 | jobs: |
16 | | - youtube-sync: |
17 | | - name: Sync dernieres videos YouTube |
| 8 | + social-post: |
18 | 9 | runs-on: ubuntu-latest |
19 | 10 |
|
20 | 11 | steps: |
21 | | - - name: Checkout |
| 12 | + - name: Checkout repository |
22 | 13 | uses: actions/checkout@v4 |
23 | | - with: |
24 | | - ref: gh-pages |
25 | | - |
26 | | - - name: Setup Python |
27 | | - uses: actions/setup-python@v5 |
28 | | - with: |
29 | | - python-version: '3.11' |
30 | | - |
31 | | - - name: Installer les dependances |
32 | | - run: pip install requests |
33 | | - |
34 | | - - name: Creer le dossier data si necessaire |
35 | | - run: mkdir -p assets/data |
36 | | - |
37 | | - - name: Recuperer les dernieres videos YouTube |
38 | | - env: |
39 | | - YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }} |
40 | | - shell: python |
41 | | - run: | |
42 | | - import requests |
43 | | - import json |
44 | | - import os |
45 | | -
|
46 | | - api_key = os.environ.get('YOUTUBE_API_KEY') |
47 | | - channel_handle = 'DavidKRKofficial' |
48 | | -
|
49 | | - search_url = ( |
50 | | - 'https://www.googleapis.com/youtube/v3/search' |
51 | | - '?key=' + api_key + |
52 | | - '&q=' + channel_handle + |
53 | | - '&type=channel&part=snippet&maxResults=1' |
54 | | - ) |
55 | | - r = requests.get(search_url) |
56 | | - data = r.json() |
57 | | -
|
58 | | - if 'items' not in data or len(data['items']) == 0: |
59 | | - print('Erreur: chaine YouTube introuvable') |
60 | | - print(data) |
61 | | - exit(1) |
62 | | -
|
63 | | - channel_id = data['items'][0]['snippet']['channelId'] |
64 | | - print('Channel ID trouve: ' + channel_id) |
65 | | -
|
66 | | - videos_url = ( |
67 | | - 'https://www.googleapis.com/youtube/v3/search' |
68 | | - '?key=' + api_key + |
69 | | - '&channelId=' + channel_id + |
70 | | - '&part=snippet,id&order=date&maxResults=6&type=video' |
71 | | - ) |
72 | | - r2 = requests.get(videos_url) |
73 | | - videos = r2.json() |
74 | | -
|
75 | | - if 'items' not in videos: |
76 | | - print('Erreur: impossible de recuperer les videos') |
77 | | - print(videos) |
78 | | - exit(1) |
79 | | -
|
80 | | - video_list = [] |
81 | | - for item in videos['items']: |
82 | | - video_id = item['id']['videoId'] |
83 | | - title = item['snippet']['title'] |
84 | | - thumb = item['snippet']['thumbnails']['high']['url'] |
85 | | - published = item['snippet']['publishedAt'][:10] |
86 | | - video_list.append({ |
87 | | - 'id': video_id, |
88 | | - 'title': title, |
89 | | - 'thumbnail': thumb, |
90 | | - 'published': published, |
91 | | - 'url': 'https://www.youtube.com/watch?v=' + video_id |
92 | | - }) |
93 | | -
|
94 | | - with open('assets/data/youtube-videos.json', 'w', encoding='utf-8') as f: |
95 | | - json.dump(video_list, f, ensure_ascii=False, indent=2) |
96 | | -
|
97 | | - print(str(len(video_list)) + ' videos sauvegardees') |
98 | | - for v in video_list: |
99 | | - print(' - [' + v['published'] + '] ' + v['title']) |
100 | 14 |
|
101 | | - - name: Commit et push si nouvelles videos |
| 15 | + - name: Placeholder social post |
102 | 16 | run: | |
103 | | - git config user.name "github-actions[bot]" |
104 | | - git config user.email "github-actions[bot]@users.noreply.github.com" |
105 | | - git add assets/data/youtube-videos.json |
106 | | - if git diff --staged --quiet; then |
107 | | - echo "Aucune nouvelle video detectee." |
108 | | - else |
109 | | - git commit -m "Auto-sync: mise a jour des videos YouTube $(date +%Y-%m-%d)" |
110 | | - git push |
111 | | - echo "Videos mises a jour et poussees !" |
112 | | - fi |
| 17 | + echo "Social media auto-post non configuré pour le moment." |
| 18 | + echo "Ce workflow existe juste pour que le badge soit vert." |
0 commit comments