Commit d4cfb992 authored by Mindiell's avatar Mindiell

Conversion to freefat framework.

parent 51f225da
Pipeline #34 skipped
tmp/
repositories/files/
repositories/formats/
repositories/ftp/
Fonctionnement supposé du mediakit
==================================
Le mediakit sert à stocker et utiliser un ensemble de médias (audio, vidéos, images).
Les différents médias doivent être ré-utilisables depuis n'importe quel site et le mediakit fournit
donc un système d'embarquement du média (embed).
Pour ajouter un média, celui-ci est uploadé sur le serveur, via ftp, dans un répertoire précis. Le
mediakit surveille régulièrement ce répertoire afin d'ajouter les médias trouvés dans sa base.
Le fichier du média est donc copié, puis analyser et préparer. Le média est ré-encodé dans
différents formats et dans différentes tailles afin d'être plus facilement utilisable par la suite.
Chaque média peut se voir attribuer des tags afin de pouvoir filtrer la liste des médias.
Chaque média peut aussi se voir attribuer des sous-titres qui seront exploités lors du rendu du
média.
Chaque média peut aussi se voir ajouter des TimeCode pour permettre d'autres actions non encore
cernées exactement pour le moment.
Un flux RSS des médias est mis à disposition par le site. Il s'agit d'un flux RSS qui conserve le
filtre des médias lors d'une recherche. C'est intéressant dans le sens où chacun peut se créer son
propre flux RSS.
Chaque média est téléchargeable dans certains formats, suivant ce qui a été demandé lors de l'ajout
du média dans le mediakit.
Le mediakit a donc forcément besoin de librairies et/ou de programmes de conversion de formats afin
de pouvoir fonctionner au mieux.
Ajout d'un média
~~~~~~~~~~~~~~~~
L'ajout d'un média se fait par FTP. Lors du scan du répertoire, le mediakit ajoute le média à sa
bibliothèque, puis l'analyze. Enfin, il donne au média un tag par défaut, celui de l'utilisateur
ayant déposé le média.
Types de médias
~~~~~~~~~~~~~~~
Il existe 4 types de médias : Vidéo, Audio, Image, Inconnu.
Pour définir le type de média, certains logiciels peuvent être utilisés:
- ffmpeg est utilisé dans le mediakit
- s'il n'y a aucun flux, il s'agit d'un média de type Inconnu
- si seul un flux audio est trouvé, il s'agit d'un média de type Audio
- si seul un flux video est trouvé, il s'agit probablement d'un média de type Image, mais pas obligatoirement
- si deux flux sont trouvés, il s'agit d'un média de type Vidéo
PAR/SAR : Pixel/Sample Aspect Ratio
DAR : Display Aspect Ratio
DAR = HORIZONTAL_RESOLUTION / VERTICAL_RESOLUTION * SAR
tbn : Time Base in AVStream from the container
tbc : Time Base in AVCodecContext for a particular stream
tbr : Time Base guessed from video stream, video frame rate
This diff is collapsed.
<?php
require_once('Helper.php');
class Controller {
// Function called before routing
function beforeRoute($f3, $args) {
// Include configuration
require_once('config.php');
$f3->set('amedia', $amedia);
$f3->set('ashow', $ashow);
$f3->set('acount', $acount);
$f3->set('amime', $amime);
$f3->set('alang2fr', $alang2fr);
$f3->set('asubetat', $asubetat);
$f3->set('alang2frsel', $alang2frsel);
$this->template = 'base.html';
// Database connexion
$this->db = new DB\SQL(DB_CONNECTOR, DB_USER, DB_PASSWORD);
}
// Function called after routing
function afterRoute($f3, $args) {
// Rendu HTML de la page
if ($this->template!='') {
echo Template::instance()->render($this->template);
}
}
};
<?php
class Helper extends Prefab {
const monthes = array(
'fr'=> array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre"),
'en'=> array("January","February","March","April","May","June","July","August","September","October","November","December"),
);
function crop($string, $length=30) {
if (strlen($string)>$length) {
return substr($string, 0, $length) . ' ...';
}
return $string;
}
function file_size($size) {
$size = intval($size);
$units = array('o', 'Ko', 'Mo', 'Go', 'To');
$unit = 0;
while ($size>1024) {
$size /= 1024;
$unit ++;
if ($unit==4) break;
}
return round($size,1) . ' ' . $units[$unit];
}
function seconds_to_hours($seconds) {
$seconds = intval($seconds);
$minutes = 0;
$hours = 0;
if ($seconds>60) {
$minutes = intval($seconds/60);
$seconds = $seconds - 60*$minutes;
}
if ($minutes>60) {
$hours = intval($minutes/60);
$minutes = $minutes - 60*$hours;
}
if ($hours>0) {
return sprintf('%dh %dm %ds', $hours, $minutes, $seconds);
} elseif ($minutes>0) {
return sprintf('%dm %ds', $minutes, $seconds);
} else {
return sprintf('%ds', $seconds);
}
}
function date_i18n($date, $lang='fr') {
if (!array_key_exists($lang, self::monthes)) {
$lang = 'fr';
}
return substr($date,8,2) . ' ' . self::monthes[$lang][substr($date,5,2)-1] . ' ' . substr($date,0,4);
}
function date_mysql_i18n($date, $long=0, $lang='fr') {
if (!array_key_exists($lang, self::monthes)) {
$lang = 'fr';
}
if ($long==2 && $date) {
return substr($my,8,2)." ".self::monthes[$lang][substr($date,5,2)-1]." ".substr($date,0,4);
} elseif ($long==1 && $date) {
return substr($date,8,2)."/".substr($date,5,2)."/".substr($date,0,4)." ".substr($date,11,5);
}
if ($date!=0) {
return substr($date,8,2)."/".substr($date,5,2)."/".substr($date,2,2);
} else {
return "";
}
}
function timeshort($time) {
if ($time=="00:00:00") return "";
if (substr($time,0,3)=="00:") return substr($time,3);
if (substr($time,0,1)=="0") return substr($time,1);
return $time;
}
};
\Template::instance()->filter('crop','\Helper::instance()->crop');
\Template::instance()->filter('file_size','\Helper::instance()->file_size');
\Template::instance()->filter('seconds_to_hours','\Helper::instance()->seconds_to_hours');
\Template::instance()->filter('date_i18n','\Helper::instance()->date_i18n');
\Template::instance()->filter('date_mysql_i18n','\Helper::instance()->date_mysql_i18n');
\Template::instance()->filter('timeshort','\Helper::instance()->timeshort');
This diff is collapsed.
[globals]
; Folder containing classes
AUTOLOAD=../app/
; Folder containing templates
UI=../templates/
; Folder containing temporary files
TEMP=../tmp/
; Cache
CACHE = true
; Debug level
DEBUG=3
; Default language
LANGUAGE='fr'
; Global variables of website
<?php
/* Configuration file */
define("VERSION","2.5");
define("DB_HOST","localhost");
define("DB_NAME","mediakit");
define("DB_USER","root");
define("DB_PASSWORD","root");
define("DB_CONNECTOR","mysql:host=".DB_HOST.";port=3306;dbname=".DB_NAME);
// Log Levels
define("ERROR",0);
define("WARNING",1);
define("INFO",2);
define("DEBUG",3);
// Logging what
define("LOGLEVEL",DEBUG);
// Paths for file functions
define("FTP_PATH", "/home/thomas/projets/lqdn/mediakit/dev/repositories/ftp/");
define("FILES_PATH", "/home/thomas/projets/lqdn/mediakit/dev/repositories/files/");
define("FORMATS_PATH", "/home/thomas/projets/lqdn/mediakit/dev/repositories/formats/");
define("SUBTITLES_PATH", "/home/thomas/projets/lqdn/mediakit/dev/repositories/srt/");
// Folders
define("FILES_FOLDER", "/repositories/files/");
define("FORMATS_FOLDER", "/repositories/formats/");
// Medias
define("MEDIA_UNKNOWN",0);
define("MEDIA_AUDIO",1);
define("MEDIA_VIDEO",2);
define("MEDIA_IMAGE",3);
// Filters
$amedia = array(
-1 => "Tous les types",
MEDIA_UNKNOWN => "Inconnu",
MEDIA_AUDIO => "Audio",
MEDIA_VIDEO => "Vidéo",
MEDIA_IMAGE => "Image",
);
$ashow = array(
0 => "Nom de fichiers seuls",
1 => "Nom, description",
2 => "Nom, description, tags",
);
$acount = array(
10 => 10,
20 => 20,
50 => 50,
100 => 100,
200 => 200,
500 => 500,
1000 => 1000,
);
// Languages
$alang2fr = array(
"fr_FR" => "Français",
"en_US" => "English",
"de_DE" => "Deutsch",
"nl_NL" => "Nederlands",
"es_ES" => "Español",
"ca_ES" => "Català",
"cs_CS" => "Čeština",
"gr_HE" => "Ελληνικά",
"it_IT" => "Italiano",
"da_DA" => "Dansk",
"ru_RU" => "Русский",
"pt_PT" => "Português",
"ja_JP" => "日本語",
"zh_ZH" => "中文",
"pl_PL" => "Polski",
"ar_DZ" => "عربي",
"bg_BG" => "Български",
"fi_FI" => "Suomi",
"sv_SV" => "Svenska",
"ro_RO" => "Română",
"tr_TR" => "Türkçe",
"hu_HU" => "Magyar",
"hr_HR" => "Hrvatski",
"lv_LV" => "Latviešu",
);
// Encoding subtitles status
$asubetat = array(
0 => "Non Encodée",
1 => "Encodage en cours",
2 => "Encodée",
3 => "Erreurs à l'encodage"
);
// Mime types
$amime = array(
"flv" => "video/flv",
"mpg" => "video/mpeg",
"jpg" => "image/jpeg",
"png" => "image/png",
"gif" => "image/gif",
"wmv" => "video/asf",
"mp3" => "audio/mpeg",
"mp4" => "video/mp4",
"ogv" => "video/ogg",
"ogm" => "video/ogg",
"wav" => "audio/x-wav",
"avi" => "video/x-msvideo",
"webm" => "video/webm",
);
// Language selection
$alang2frsel = array(
"fr_FR" => "Français (French)",
"en_US" => "English (English)",
"de_DE" => "Deutsch (German)",
"nl_NL" => "Nederlands (Dutch)",
"es_ES" => "Español (Spanish)",
"ca_ES" => "Català (Catalan)",
"cs_CS" => "Čeština (Czeck)",
"gr_HE" => "Ελληνικά (Greek)",
"it_IT" => "Italiano (Italian)",
"da_DA" => "Dansk (Danish)",
"ru_RU" => "Русский (Russian)",
"pt_PT" => "Português (Portuguese)",
"ja_JP" => "日本語 (Japanese)",
"zh_ZH" => "中文 (Chinese)",
"pl_PL" => "Polski (Polish)",
"ar_DZ" => "عربي (Arabic)",
"bg_BG" => "Български (Bulgarian)",
"fi_FI" => "Suomi (Finish)",
"sv_SV" => "Svenska (Swedish)",
"ro_RO" => "Română (Romanian)",
"tr_TR" => "Türkçe (Turkish)",
"hu_HU" => "Magyar (Hungarian)",
"hr_HR" => "Hrvatski (Croatian)",
"lv_LV" => "Latviešu (Latvian)",
);
/* TODO : remove this in production ;) */
error_reporting(E_ALL|E_WARNING);
ini_set("display_errors", true);
?>
[routes]
; Main site
GET|POST @index:/=Mediakit->index
GET @view:/view=Mediakit->view
GET /embed=Mediakit->embed
GET @embed:/embed/@id=Mediakit->embed
GET @get:/get=Mediakit->get
; Admin pages
GET|POST @edit:/edit=Mediakit->edit
GET|POST @edittc:/edittc=Mediakit->edittc
GET|POST @edittc_form:/edittc_form=Mediakit->edittc_form
GET|POST @edittc_list:/edittc_list=Mediakit->edittc_list
GET @edittc_del:/edittc_del=Mediakit->edittc_del
GET|POST @subtitles:/subtitles=Mediakit->subtitles
This diff is collapsed.
<?php
// mysql_connect("localhost","mk2","oy7Ealee");
// mysql_select_db("mk2");
mysql_connect("localhost","root","root");
mysql_select_db("mediakit");
<?php
/* Affiche les éléments de div à poser DANS le div principal
pour afficher les valeurs présélectionées de la liste.
@param array $ar Tableau de clés=>valeurs les clés sont les numéros et les valeurs les textes de ces numéros
@param string $name Le nom du jeu de composant
*/
function ms_divFromArray($ar,$name) {
if (is_array($ar)) {
foreach($ar as $k=>$v) {
echo '<div id="'.$name.'v_'.$k.'"><input type="hidden" name="'.$name.'v[]" id="" value="'.$k.'"/><a href="javascript:ms_del(\''.$name.'\','.$k.')"><img src="del.gif"></a>&nbsp;'.$v.' &nbsp; </div>';
}
}
}
?>
\ No newline at end of file
<?php
if (file_exists("bdd.php")) {
require_once("bdd.php");
} else {
mysql_connect("localhost","mk2_dev","poipoi");
mysql_select_db("mk2_dev");
}
mysql_query("SET NAMES UTF8;");
require_once("functions.php");
$image_formats=array("png","gif","jpg","bmp","xcf","mjpeg");
define("MEDIA_UNKNOWN",0);
define("MEDIA_AUDIO",1);
define("MEDIA_VIDEO",2);
define("MEDIA_IMAGE",3);
$amedia=array(MEDIA_UNKNOWN=>"Inconnu",
MEDIA_AUDIO=>"Audio",
MEDIA_VIDEO=>"Vidéo",
MEDIA_IMAGE=>"Image",
);
$asubetat=array( 0=>"Non Encodée", 1=>"Encodage en cours", 2=>"Encodée", 3=>"Erreurs à l'encodage");
$alang2fr=array(
"fr_FR" => "Français",
"en_US" => "English",
"de_DE" => "Deutsch",
"nl_NL" => "Nederlands",
"es_ES" => "Español",
"ca_ES" => "Català",
"cs_CS" => "Čeština",
"gr_HE" => "Ελληνικά",
"it_IT" => "Italiano",
"da_DA" => "Dansk",
"ru_RU" => "Русский",
"pt_PT" => "Português",
"ja_JP" => "日本語",
"zh_ZH" => "中文",
"pl_PL" => "Polski",
"ar_DZ" => "عربي",
"bg_BG" => "Български",
"fi_FI" => "Suomi",
"sv_SV" => "Svenska",
"ro_RO" => "Română",
"tr_TR" => "Türkçe",
"hu_HU" => "Magyar",
"hr_HR" => "Hrvatski",
"lv_LV" => "Latviešu",
);
$alang2frsel=array(
"fr_FR" => "Français (French)",
"en_US" => "English (English)",
"de_DE" => "Deutsch (German)",
"nl_NL" => "Nederlands (Dutch)",
"es_ES" => "Español (Spanish)",
"ca_ES" => "Català (Catalan)",
"cs_CS" => "Čeština (Czeck)",
"gr_HE" => "Ελληνικά (Greek)",
"it_IT" => "Italiano (Italian)",
"da_DA" => "Dansk (Danish)",
"ru_RU" => "Русский (Russian)",
"pt_PT" => "Português (Portuguese)",
"ja_JP" => "日本語 (Japanese)",
"zh_ZH" => "中文 (Chinese)",
"pl_PL" => "Polski (Polish)",
"ar_DZ" => "عربي (Arabic)",
"bg_BG" => "Български (Bulgarian)",
"fi_FI" => "Suomi (Finish)",
"sv_SV" => "Svenska (Swedish)",
"ro_RO" => "Română (Romanian)",
"tr_TR" => "Türkçe (Turkish)",
"hu_HU" => "Magyar (Hungarian)",
"hr_HR" => "Hrvatski (Croatian)",
"lv_LV" => "Latviešu (Latvian)",
);
$privatetags=array(98,83);
?>
\ No newline at end of file
while true ; do php newfiles.php ; sleep 60 ; done
while true ; do php prepareformat.php ; sleep 60 ; done
This diff is collapsed.
<?php
// Putting myself in the good directory
chdir(dirname(__FILE__));
require_once("../app/config.php");
mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME);
require_once("functions.php");
$users = scandir(FTP_PATH);
echo "NEWFILES starting scan ".date("d/m/Y H:i:s")."\n"; flush();
foreach($users as $user) {
if (substr($user,0,1)==".") {
continue;
}
echo "USER $user\n"; flush();
$d=opendir(FTP_PATH . "$user");
while ($c=readdir($d)) {
if (substr($c,0,1)=="." || !is_file(FTP_PATH . "$user/$c") || filemtime(FTP_PATH . "$user/$c")+180>time() ) {
continue;
}
// Ok, this file is not hidden, is a file, and has a modification time far away.
// let's add it to the mediakit.
echo "FILE $c\n"; flush();
$newname = $c;
if (file_exists(FILES_PATH . "$c")) {
// Already exists, let's find a newname.
$base = substr($c,0,strrpos($c,"."));
$ext = substr($c,strrpos($c,"."));
$i = 1;
while (file_exists(FILES_PATH.$base."_".$i.$ext)) {
$i++;
}
$newname = $base."_".$i.$ext;
echo "RENAMED TO $newname\n";
}
// let's rename it and insert it in the mediakit :
rename(FTP_PATH . "$user/$c", FILES_PATH . "$newname");
$val = getVideoFormat(FILES_PATH.$newname, 1);
$title=str_replace("_"," ",substr($newname,0,strrpos($newname,".")));
if ($val["vcodec"]=="") {
if ($val["acodec"]=="") {
$mode=MEDIA_UNKNOWN;
} else {
$mode=MEDIA_AUDIO;
}
} else {
if ($val["acodec"]=="" && in_array($val["vcodec"],$image_formats)) {
$mode=MEDIA_IMAGE;
} else {
$mode=MEDIA_VIDEO;
}
}
$sql = "INSERT INTO media SET filename='".addslashes($newname)."', title='".addslashes($title)."', datec=NOW(), datem=NOW(), type='$mode' ";
unset($val["filename"]);
foreach($val as $k=>$v) {
$sql.=", `$k`='".addslashes($v)."' ";
}
mq($sql);
echo mysql_error();
echo "SQL:$sql\n"; flush();
$id=mysql_insert_id();
$tid=mqonefield("SELECT id FROM tag WHERE groupid='1' AND name='".addslashes($user)."';");
if ($tid) {
mq("INSERT INTO tagmedia SET media='$id', tag='$tid';");
}
} // while ($c=readdir($d)) {
closedir($d);
} // foreach $users as $user
echo "NEWFILES ending scan ".date("d/m/Y H:i:s")."\n\n"; flush();
?>
<?php
// Putting myself in the good directory
chdir(dirname(__FILE__));
if (isset($argv[1])) {
$only=intval($argv[1]);
......@@ -7,7 +8,11 @@ if (isset($argv[1])) {
$only=-1;
}
require_once("config.php");
require_once("../app/config.php");
mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME);
require_once("formats.php");
$sql=" AND m.id >444 ";
......@@ -79,4 +84,4 @@ echo "Fin de taitement des MEDIA_IMAGE\n";