我有一个脚本可以为歌曲更改事件添加日志文件。当发生这种情况时,Tweet会自动生成并发送到Twitter。问题是,我最近更新了我的脚本,因此它还包含了Tweet的专辑封面。我正在使用curl下载图像,发布媒体,然后删除下一条推文的文件。什么让我失望的是,当推文中显示的图像是播放上一首歌而不是当前播放的歌时。我想知道如果我使用curl下载文件,然后使用php unlink命令,是否会再次下载相同的图像?以下是我的代码。
// Analyze prepared tweet for issues with length
$tweeted = ($front . $fixedArtistNow . $hyphen . " " . $fixedTitleNow . $tag);
if (strlen($tweeted) <= 140) {
try {
// $path = ("/home/soundcheck/public_html/images/artwork.png");
// if(unlink($path));
// Grab album art from the song that is currently playing
$fresh = date("y-m-d-G-i-s");
$ch = curl_init('http://soundcheck.xyz:8000/playingart? sid=1?'.$fresh);
var_dump($ch);
$fp = fopen('/home/soundcheck/public_html/images/artwork.png', 'wb');
curl_setopt($fp, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($fp, CURLOPT_FORBID_REUSE, TRUE);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
// copy("/home/soundcheck/public_html/images/artwork.png","/home/soundcheck/public_html/images/album.png");
// $twitter->send($front . $fixedArtistNow . $hyphen . " " . $fixedTitleNow . $tag);
$media1 = $twitter->upload('media/upload', ['media' => '/home/soundcheck/public_html/images/artwork.png']);
// $media2 = $connection->upload('media/upload', ['media' => '/path/to/file/kitten2.jpg']);
$parameters = [
'status' => $tweeted,
'media_ids' => implode(',', [$media1->media_id_string]),
];
$result = $twitter->post('statuses/update', $parameters);
// unlink("/home/soundcheck/public_html/images/artwork.png");
我从中获取图像的网址从不会发生变化,但如果图像有所不同,则图像会发生变化。如果有人知道更好的下载专辑封面的方式,请告诉我。谢谢!