Skip to content

Commit 0fccada

Browse files
committed
Moved job info storage from cookies to server side, browser only stores
job list. Added housekeeping 2 - erasing files past expirey date
1 parent 99e2f7e commit 0fccada

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

index.php

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static function SaveDownloader()
7171
$jobs=[];
7272
foreach(self::$DOWNLOADER as $jobinfo)
7373
{
74-
setcookie("job_".$jobinfo['jobid'],json_encode($jobinfo),time()+60*60*24*30);
74+
file_put_contents(self::$jobpath."/".$jobinfo['jobid'].".job",json_encode($jobinfo));
7575
$jobs[]=$jobinfo['jobid'];
7676
}
7777
setcookie("jobs",json_encode($jobs),time()+60*60*24*30);
@@ -82,18 +82,56 @@ static function LoadDownloader()
8282
if(!isset($_COOKIE['jobs']))
8383
{
8484
self::$DOWNLOADER=[];
85-
setcookie("jobs",json_encode(self::$DOWNLOADER),time()+60*60*24*30);
85+
setcookie("jobs",json_encode([]),time()+60*60*24*30);
8686
}
8787
$joblist=json_decode(stripslashes($_COOKIE['jobs']),true);
8888
foreach($joblist as $job)
8989
{
90-
if(isset($_COOKIE['job_'.$job]))
90+
if(file_exists(self::$jobpath."/".$job.".job"))
9191
{
92-
self::$DOWNLOADER[]=json_decode(stripslashes($_COOKIE['job_'.$job]),true);
92+
self::$DOWNLOADER[]=json_decode(file_get_contents(self::$jobpath."/".$job.".job"),true);
9393
}
9494
}
9595
}
9696

97+
static function FetchStaleJobs()
98+
{
99+
$worker=new FilesystemIterator(self::$jobpath);
100+
$cutoff=time()-(self::$job_ttl*60);
101+
foreach($worker as $job)
102+
{
103+
$fn=$job->getFilename();
104+
if(subst($fn,-4)!==".job")
105+
{
106+
if($job->getCTime()<$cutoff)
107+
{
108+
self::NukeJob($fn);
109+
}
110+
111+
}
112+
}
113+
}
114+
115+
static function NukeJob($jobid)
116+
{
117+
unlink(self::$jobpath . "/" . $jobid);
118+
unlink(self::$jobpath . "/" . $jobid.".job");
119+
120+
$remover=new FilesystemIterator(self::$dl_dir_common."/".$jobid);
121+
foreach($remover as $item)
122+
{
123+
unlink(self::$dl_dir_common."/".$jobid."/".$item->getFilename());
124+
}
125+
unlink(self::$dl_dir_common."/".$jobid);
126+
127+
$remover=new FilesystemIterator(self::$dl_dir_mp3."/".$jobid);
128+
foreach($remover as $item)
129+
{
130+
unlink(self::$dl_dir_mp3."/".$jobid."/".$item->getFilename());
131+
}
132+
unlink(self::$dl_dir_mp3."/".$jobid);
133+
}
134+
97135
static function SetupDir($dirname)
98136
{
99137
clearstatcache();
@@ -342,6 +380,7 @@ static function handleTag($tag, $rest)
342380
case "sponsorblock":
343381
case "fixupm3u8":
344382
case "metadata":
383+
case "metadataparser":
345384
case "embedsubtitle":
346385
case "hlsnative":
347386
{
@@ -1138,12 +1177,20 @@ function showInfo(info)
11381177
font-weight:bold;
11391178
content: attr(data-progress);
11401179
}
1180+
[data-provider]::before
1181+
{
1182+
content:"?";
1183+
}
11411184
[data-provider=youtube]::before
11421185
{
11431186
border-radius:3px;
11441187
content:'▶';
11451188
color:white;
11461189
background-color:red;
1190+
padding:3px;
1191+
padding-left:10px;
1192+
padding-right:10px;
1193+
11471194
}
11481195
[data-provider=xhamster]::before
11491196
{
@@ -1195,6 +1242,27 @@ function showInfo(info)
11951242
position:relative;
11961243
height:3em;
11971244
}
1245+
#infoheader
1246+
{
1247+
font-size:2em;
1248+
}
1249+
#vicount::before
1250+
{
1251+
content:"Videos: ";
1252+
}
1253+
#jobid::before
1254+
{
1255+
content:"Job ID: ";
1256+
}
1257+
#mode
1258+
{
1259+
font-variant: small-caps;
1260+
font-family: monospace;
1261+
}
1262+
#mode::before
1263+
{
1264+
content:"Mode: ";
1265+
}
11981266
</style>
11991267
</head>
12001268
<body><form id="controls">

0 commit comments

Comments
 (0)