-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexport.php
67 lines (63 loc) · 1.86 KB
/
export.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
<?php
use Doctrine\DBAL;
require 'vendor/autoload.php';
include './common.inc.php';
$connectionParams = [
'url' => $dbDSN,
];
$conn = DBAL\DriverManager::getConnection($connectionParams);
$args = [];
parse_str($argv[1] ?? '', $args);
$udpxy = $args['udpxy'] ?? null;
$epgKey = $args['epg'] ?? null;
$epgKey = ($epgKey ?: 'rytec') . '_epg_id';
$queryBuilder = $conn->createQueryBuilder();
$lists = $queryBuilder->select('*')->from('iptv')->orderBy('sort', 'ASC')->fetchAllAssociative();
$data = new \M3uParser\M3uData();
$data->setAttribute('name', '上海电信IPTV组播节目单');
foreach ($lists as $item) {
$uri = null;
$quality = null;
foreach (QUALITY_NAME_MAP as $Q => $q) {
$key = 'uri_' . $q;
if (!empty($item[$key])) {
$uri = $item[$key];
$quality = '「' . $Q . '」';
break;
}
}
if (empty($uri) && !empty($item['uri'])) {
$uri = $item['uri'];
}
if (empty($uri)) {
continue;
}
if (!empty($udpxy) && stripos($uri, 'rtp://') === 0) {
$uri = rtrim($udpxy, ' \t\n\r') . '/' . str_replace('://', '/', $uri);
}
$title = $item['display_title'] ?? $item['name'];
if ($quality) {
$title .= $quality;
}
$entry = new M3uParser\M3uEntry();
$entry->setPath($uri);
$extInf = (new M3uParser\Tag\ExtInf())
->setDuration(-1)
->setTitle($title);
$attributes = [];
if (!empty($item[$epgKey])) {
$attributes['tvg-id'] = $item[$epgKey];
}
$attributes = array_replace($attributes, [
'tvg-name' => $item['name'],
'group-title' => $item['group'],
]);
$extInf->setAttributes($attributes);
$entry->addExtTag($extInf);
$data->append($entry);
}
if (!SERVER_MODE) {
echo $data;
} else {
return $data;
}