Skip to content

Commit

Permalink
refactor player init check
Browse files Browse the repository at this point in the history
 * only check date for releases
 * adjust cron tz
  • Loading branch information
a-sync committed Dec 22, 2023
1 parent a1e1792 commit 760a82a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cron-backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: cron/backup
on:
workflow_dispatch:
schedule:
- cron: '30 8 * * 5'
- cron: '30 7 * * 5'

jobs:
cronjob:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-csv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: cron/csv
on:
workflow_dispatch:
schedule:
- cron: '20 8 * * *'
- cron: '20 7 * * *'

jobs:
cronjob:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-daily.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: cron/daily
on:
workflow_dispatch:
schedule:
- cron: '0 */12 * * *'
- cron: '0 7,19 * * *'

jobs:
cronjob:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron-weekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: cron/weekly
on:
workflow_dispatch:
schedule:
- cron: '10 8 * * *'
- cron: '10 7 * * *'

jobs:
cronjob:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Az alábbi mezőket exportálja a **/public/m3-db.csv.gz** tömörített fájlba
* year
* duration
* short_description
* released

#### Műsor hozzáadása azonosító segítségével
Útvonal: **/cron/add?id=**
Expand Down
49 changes: 3 additions & 46 deletions application/views/foot.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,57 +58,14 @@ function initPlayer(el) {
});
}

async function getReleaseDate(programid) {
const infoRes = await fetch(String('\x68\x74\x74\x70\x73\x3a\x2f\x2f\x6e\x65\x6d\x7a\x65\x74\x69\x61\x72\x63\x68\x69\x76\x75\x6d\x2e\x68\x75\x2f\x61\x70\x69\x2f\x6d\x33\x2f\x76\x33\x2f\x69\x74\x65\x6d\x3f\x69\x64\x3d')+programid);
const infoResJson = await infoRes.json();

let releaseDate = null;
for (const key of ['start_playable_dts', 'start_startTime_dts']) {
if (key in infoResJson && Array.isArray(infoResJson[key]) && infoResJson[key].length > 0) {
for (const dts of infoResJson[key]) {
const dtsDate = new Date(dts);
if (releaseDate === null || dtsDate < releaseDate) {
releaseDate = dtsDate;
}
}
}
}

return releaseDate;
}

const domLoaded = () => {
console.log('DOM loaded');
const videoElements = document.querySelectorAll('.video-js');

for (const el of videoElements) {
getReleaseDate(el.dataset.programid).then(releaseDate => {
let playableDate = null;
if (releaseDate) {
playableDate = new Date(releaseDate);
playableDate.setHours(playableDate.getHours() - 2);
}

if (playableDate && playableDate <= new Date()) {
// el.style.border = 'solid 2px green';}if(true){//debug
initPlayer(el);
} else {
if (releaseDate) {
const overlay = document.createElement('div');
overlay.className = 'm3player-overlay';
overlay.textContent = '📅 ' + releaseDate.toLocaleString('hu-HU');
overlay.title = 'Közzététel időpontja';
el.parentNode.appendChild(overlay);
}
//debug
el.addEventListener('dblclick', ev => {
ev.preventDefault();
const overlay = el.parentNode.querySelector('.m3player-overlay');
if (overlay) overlay.remove();
initPlayer(el);
}, {'once':true});
}
});
const overlay = el.parentNode.querySelector('.m3player-overlay');
if (!overlay) initPlayer(el);
else el.addEventListener('dblclick',ev=>{ev.preventDefault();if(overlay){overlay.remove()};initPlayer(el);},{'once':true});// DEBUG
}
};

Expand Down
2 changes: 1 addition & 1 deletion application/views/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<link href="https://unpkg.com/@mdi/font@latest/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://unpkg.com/video.js@latest/dist/video-js.min.css" rel="stylesheet">
<link href="<?php echo base_url('public/m3.min.css'); ?>" rel="stylesheet">
<link href="<?php echo base_url('public/app.css'); ?>" rel="stylesheet">
<link href="<?php echo base_url('public/app.css'); ?>?v=2" rel="stylesheet">
</head>
<body class="mdc-typography">
<header>
Expand Down
61 changes: 37 additions & 24 deletions application/views/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
echo '<div class="mdc-typography--caption list__total">'.$total.' találat</div>';

echo $links;
$today_mid = new DateTime();
$today_mid->setTime(12, 0, 0);
?>
<div class="mdc-data-table mdc-elevation--z2 list__table">
<table class="mdc-data-table__table">
Expand Down Expand Up @@ -38,6 +40,15 @@ class="video-js"
preload="none"
poster="https://nemzetiarchivum.hu/images/m3/<?php echo html_escape($i['program_id']); ?>"
></video>
<?php
$released_mid = new DateTime($i['released']);
$released_mid->modify('-1 hour')->setTime(12, 0, 0);
$prerender = (floor($released_mid->getTimestamp() / 60 / 60 / 24) % 3);
if ($prerender > 0) $released_mid->modify('-'.$prerender.' day');//🧀
if ($released_mid > $today_mid):
?>
<div class="m3player-overlay" title="Közzététel időpontja">📅 <?php echo date('Y.m.d. H:i:s', strtotime($i['released'])); ?></div>
<?php endif; ?>
</div>
</td>
<td class="mdc-data-table__cell cell__title">
Expand All @@ -51,30 +62,32 @@ class="video-js"
<?php endif; ?>
<details>
<summary class="mdc-typography--caption"><?php echo trim($i['short_description']) ? html_escape($i['short_description']) : '🎬'; ?></summary>
<table class="mdc-data-table__table">
<tbody class="mdc-data-table__content">
<?php
foreach ($i as $ii => $val):
if(trim($val)):
?>
<tr class="mdc-data-table__row">
<th class="mdc-data-table__cell mdc-data-table__cell--numeric mdc-typography--caption"><?php echo html_escape($ii); ?></th>
<td class="mdc-data-table__cell mdc-typography--caption">
<?php
$val = html_escape($val);
if ($ii === 'description' || $ii === 'short_description') {
$val = implode("; ", explode(';', $val));
}
echo nl2br($val);
?>
</td>
</tr>
<?php
endif;
endforeach;
?>
</tbody>
</table>
<div class="mdc-data-table mdc-elevation--z4 details__table">
<table class="mdc-data-table__table">
<tbody class="mdc-data-table__content">
<?php
foreach ($i as $ii => $val):
if(trim($val)):
?>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell mdc-data-table__cell--numeric mdc-typography--caption"><?php echo html_escape($ii); ?></td>
<td class="mdc-data-table__cell mdc-typography--caption">
<?php
$val = html_escape($val);
if ($ii === 'description' || $ii === 'short_description') {
$val = implode("; ", explode(';', $val));
}
echo nl2br($val);
?>
</td>
</tr>
<?php
endif;
endforeach;
?>
</tbody>
</table>
</div>
</details>
</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric"><?php echo html_escape($h.$m); ?></td>
Expand Down
7 changes: 6 additions & 1 deletion public/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ h1 {
font-style: italic;
}

.list__table td, .list__table th {
.list__table td {
vertical-align: top;
}

.details__table tbody tr td {
white-space: normal;
word-wrap: break-word;
}

.list__no_items {
text-align: center;
margin-top: 20px;
Expand Down

0 comments on commit 760a82a

Please sign in to comment.