-
Notifications
You must be signed in to change notification settings - Fork 94
/
fblive.php
executable file
·119 lines (99 loc) · 3.19 KB
/
fblive.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
$shoutouts = require __DIR__ . '/shoutouts.php';
$settings = require __DIR__ . '/settings.php';
/*
* Ensure the correct settings are set in order to run the script
*/
if(empty($settings['ACCESS_TOKEN'])) {
die('Please provide an ACCESS_TOKEN');
} elseif(empty($settings['APP_ID'])) {
die('Please provide an APP_ID');
} elseif(empty($settings['APP_SECRET'])) {
die('Please provide an APP_SECRET');
}
$FBConfig = new \Facebook\Facebook([
'app_id' => $settings['APP_ID'],
'app_secret' => $settings['APP_SECRET'],
'default_graph_version' => 'v2.8'
]);
$fb = new \FBReactions\Facebook($FBConfig, $settings['ACCESS_TOKEN']);
while (true) {
$image = Intervention\Image\ImageManagerStatic::make($settings['VIDEO_BG']);
$renderer = new \FBReactions\Renderer($image, $settings);
/*
* Fetch the reactions count
*/
$reactions = $fb->reactionCount(
$settings['POST_ID'],
$settings['REACTION_SETTINGS']['REACTIONS']
);
if(count($reactions) > 0) {
/*
* Draw reactions on image
*/
$renderer->drawReactionCount($reactions);
} else {
/*
* No reactions found, display 0 for each
*/
$renderer->drawReactionCount(
array_map(function() { return 0; }, $settings['REACTION_SETTINGS']['REACTIONS'])
);
}
/*
* Fetch latest comments
*/
$comments = $fb->commentsByKeyword(
$settings['POST_ID'],
$settings['KEYWORD']
);
if(!empty($settings['POST_ID']) && count($comments) > 0) {
$latestComment = $comments[0];
/*
* Download user profile image from Facebook. Image saves/overwrites to ./images/profile.jpeg
*/
$fb->saveProfileImage(
$latestComment['from']['id'],
$settings['SHOUTOUT_SETTINGS']['PROFILE_IMAGE']['WIDTH'],
$settings['SHOUTOUT_SETTINGS']['PROFILE_IMAGE']['HEIGHT'],
__DIR__ . '/images/profile.jpg'
);
/*
* Draw shoutout on image
*/
$renderer->drawShoutout(
$latestComment['from']['name'],
$shoutouts[array_rand($shoutouts)],
$settings['SHOUTOUT_SETTINGS']['SHOUTOUT_TEXT']
);
} else {
/*
* Draw default shoutout on image
*/
$renderer->drawShoutout(
$settings['SHOUTOUT_SETTINGS']['DEFAULT_SHOUTOUT_NAME'],
$settings['SHOUTOUT_SETTINGS']['DEFAULT_SHOUTOUT'],
$settings['SHOUTOUT_SETTINGS']['SHOUTOUT_TEXT']
);
}
/*
* Add profile image to shoutout box
*/
$renderer->drawProfileImage(
__DIR__ . '/images/profile.jpg',
$settings['SHOUTOUT_SETTINGS']['PROFILE_IMAGE']['XPOS'],
$settings['SHOUTOUT_SETTINGS']['PROFILE_IMAGE']['YPOS']
);
/*
* Save image, and move. This is required so ffmpeg doesn't stall.
* If you directly overwrite stream.jpg ffmpeg seems to have issues.
*/
$image->save('images/stream.tmp.jpg');
system('mv images/stream.tmp.jpg images/stream.jpg');
/*
* Pause for x number of seconds
*/
sleep($settings['FRAME_RATE']);
}