add get mp cookie

refactor form
This commit is contained in:
quenousimporte 2024-07-07 15:01:30 +02:00
parent f2a8bf8c8d
commit 3133a4dd24
2 changed files with 55 additions and 14 deletions

View File

@ -17,6 +17,37 @@
require 'settings.php';
require 'TPEpubCreator.php';
function get_mp_cookie()
{
global $mp_user;
global $mp_password;
$url = 'https://www.mediapart.fr/login_check';
$postfields = 'email=' . $mp_user . '&password=' . $mp_password . '&submitButton=&_target_path=https%3A%2F%2Fwww.mediapart.fr%2F';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($ch);
$sessid = '';
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
foreach($matches[1] as $item)
{
if (str_starts_with($item, 'MPSESSID='))
{
$sessid = str_replace('MPSESSID=', '', $item);
}
}
return $sessid;
}
function write_epub($epub)
{
if (file_exists($epub->epub_file))
@ -180,6 +211,12 @@
// Mediapart
if (isset($_POST['mediapart']) && $_POST['mediapart'])
{
if (isset($_POST['forcempcookies']) && $_POST['forcempcookies'])
{
$mp_sessionid = get_mp_cookie();
// todo save in settings
}
$feedurl = 'https://www.mediapart.fr/articles/feed';
$opts = [
'http' => [
@ -422,31 +459,33 @@
<h3>Generate epub</h3>
<div>
<form method="post">
Parameters:
<b>Le Monde</b>
<br>
GetPublicationContentItems url: <input name="lmurl"><br>
<input id="lemonde" name="lemonde" type="checkbox">
<label for="lemonde">From json url: </label>
<input name="lmurl"><br>
<!--Update MPSESSID: <input name="mpsessid"><br>
Update NYT-S: <input name="nyts"><br>-->
<br>
Newspapers:
<b>Mediapart</b>
<br>
<input id="lemonde" name="lemonde" type="checkbox">
<label for="lemonde">Le Monde</label>
<br>
<input id="mediapart" name="mediapart" type="checkbox">
<label for="mediapart">Mediapart (RSS)</label>
<label for="mediapart">From RSS</label>
<br>
<input disabled id="forcempcookies" name="forcempcookies" type="checkbox">
<label for="forcempcookies">Force cookies</label>
<br><br>
<b>The New York Times</b>
<br>
<input id="nyt" name="nyt" type="checkbox">
<label for="nyt">The New York Times (RSS)</label>
<label for="nyt">From RSS</label>
<br>
<input id="nyttoday" name="nyttoday" type="checkbox">
<label for="nyttoday">The New York Times (today's paper)</label>
<br>
<label for="nyttoday">From today's paper embeded script</label>
<br><br>
<input type="submit">
</form>

View File

@ -1,4 +1,6 @@
<?php
$mp_sessionid = '';
$nyt_sessionid = ''
$mp_user = '';
$mp_password = '';
$nyt_sessionid = '';
?>