forked from xtoolkit/TVC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannelsAssets.php
41 lines (33 loc) · 1.53 KB
/
channelsAssets.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
<?php
// Enable error reporting
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
error_reporting(E_ERROR | E_PARSE);
// Include the functions file
require "functions.php";
// Fetch the JSON data from the API and decode it into an associative array
$sourcesArray = json_decode(
file_get_contents("channels.json"),
true
);
deleteFolder("channelsData/logos");
deleteFolder("channelsData");
mkdir("channelsData");
mkdir("channelsData/logos");
foreach ($sourcesArray as $source => $types) {
// Fetch the HTML content of the Telegram channel page
$tempData = file_get_contents("https://t.me/s/" . $source);
// Extract the title and image URL using regular expressions
$title_pattern = '#<meta property="twitter:title" content="(.*?)">#';
$image_pattern = '#<meta property="twitter:image" content="(.*?)">#';
preg_match($image_pattern, $tempData , $image_match);
preg_match($title_pattern, $tempData , $title_match);
// Save the image file to local storage
file_put_contents("channelsData/logos/" . $source . ".jpg", file_get_contents($image_match[1]));
// Build the channel data array
$channelArray[$source]['types'] = $types;
$channelArray[$source]['title'] = $title_match[1];
$channelArray[$source]['logo'] = "https://raw.githubusercontent.com/yebekhe/TVC/main/channelsData/logos/" . $source . ".jpg";
}
// Save the channel data array as JSON
file_put_contents("channelsData/channelsAssets.json", json_encode($channelArray , JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));