_binary From e958249dc73083e6ab8a2a5bb8d40c754c4062f1 Mon Sep 17 00:00:00 2001
From: pomishra13 <pooja192009@gmail.com>
Date: Fri, 24 Apr 2015 01:33:18 -0700
Subject: [PATCH] VideoUpdater Code Changes, a=pooja

---
 bin/media_updater.php               | 384 ++++++++++++++++++++++++++----------
 configs/config.php                  |  11 ++
 controllers/crawl_controller.php    |  62 +++++-
 controllers/resource_controller.php |  42 +++-
 models/group_model.php              |  18 +-
 models/source_model.php             |  15 ++
 views/machinestatus_view.php        |   4 -
 7 files changed, 419 insertions(+), 117 deletions(-)

diff --git a/bin/media_updater.php b/bin/media_updater.php
index 5595668..ae2137a 100644
--- a/bin/media_updater.php
+++ b/bin/media_updater.php
@@ -148,7 +148,7 @@ class MediaUpdater implements CrawlConstants
             $start_time = microtime();
             crawlLog("Checking if news feeds should be updated...");
             $this->newsUpdate();
-            $this->mediaConversion();
+            $this->videoUpdater();
             $sleep_time = max(0, ceil(
                 MINIMUM_UPDATE_LOOP_TIME - changeInMicrotime($start_time)));
             if ($sleep_time > 0) {
@@ -191,115 +191,23 @@ class MediaUpdater implements CrawlConstants
             crawlLog("No updates needed.");
         }
     }
-    /**
-     *  Checks for schedules of media to convert in the media_convert
-     *  schedules folder. If it find a schedules, it reads it and tries to
-     *  do the conversions. For now the conversions are limited to creating
-     *  webm and mp4 files corresponding to a video file listed in a schedule.
-     *  For this method to run, ffmpeg must be installed and the constant
-     *  FFMPEG must be set to the path to ffmpeg.
+     /**
+     * This function calls the video updater functionality.
+     * It calls the all the required functions based on single or multiple.
+     * machine setting.
      */
-    function mediaConversion()
+    function videoUpdater()
     {
-        static $to_convert_mp4 = "";
-        static $to_convert_mp4_thumb = "";
-        static $to_convert_webm = "";
-        static $to_convert_webm_thumb = "";
-        static $group_id, $page_id, $locale_tag, $page, $page_name;
-        $convert_folder = WORK_DIRECTORY. "/schedules/media_convert";
-        if (!defined('FFMPEG') || !file_exists($convert_folder)) { return; }
-        crawlLog("Entering media files to convert code...");
-        if ($to_convert_mp4 == "" && $to_convert_webm == "" ) {
-            $to_convert = glob($convert_folder. "/*.txt");
-            if (!isset($to_convert[0])) {
-                crawlLog("...No media files found.");
-                return;
-            }
-            $convert_file_struct = file($to_convert[0]);
-            unlink($to_convert[0]);
-            if (!isset($convert_file_struct[2])) {
-                crawlLog("...Media conversion file mis-formatted... skipping");
-                return;
-            }
-            $group_model = $this->groupModel;
-            list($page_id, $media_path, $thumb_path, $media_file_name) =
-                $convert_file_struct;
-            $page_id = trim($page_id);
-            $info = $group_model->getPageInfoByPageId($page_id);
-            if (!$info) {
-                crawlLog("...Media page lookup failed ... skipping");
-                return;
-            }
-            $group_id = $info['GROUP_ID'];
-            $locale_tag = $info['LOCALE_TAG'];
-            $page_name = $info['PAGE_NAME'];
-            $full_info = $group_model->getPageInfoByName($group_id, $page_name,
-                $locale_tag, 'edit');
-            if (!$full_info) {
-                crawlLog("...Full Media page lookup failed ... skipping");
-                return;
-            }
-            $page = $full_info["PAGE"];
-            $media_base_name = $media_file_name;
-            $media_path = trim($media_path);
-            $thumb_path = trim($thumb_path);
-            if (($pos = strrpos($media_file_name, ".")) !== false) {
-                $media_base_name = substr($media_file_name, 0, $pos);
-            }
-            $input_media_file = "$media_path/$media_file_name";
-            $mp4_file = "$media_path/$media_base_name.mp4";
-            $webm_file = "$media_path/$media_base_name.webm";
-            if ($input_media_file != $mp4_file) {
-                $ffmpeg = FFMPEG . " -i \"$input_media_file\" -y".
-                    " -codec:v h264 -acodec aac -preset veryfast -crf 28 ".
-                    "-strict -2 \"$mp4_file\" 2>&1";
-                crawlLog("Starting job to convert " . $media_file_name .
-                    " to mp4");
-                CrawlDaemon::execInOwnProcess($ffmpeg);
-                $to_convert_mp4 = $mp4_file;
-                $to_convert_mp4_thumb =
-                    "$thumb_path/$media_base_name.mp4.jpg";
-            }
-            if ($input_media_file != $webm_file) {
-                $ffmpeg = FFMPEG . " -i \"$input_media_file\" ".
-                    " -vcodec libvpx \"$webm_file\" -cpu-used -5 -b:v 300k".
-                    " -deadline realtime -threads 2 ";
-                crawlLog("Starting job to convert " . $media_file_name .
-                    " to webm");
-                CrawlDaemon::execInOwnProcess($ffmpeg);
-                $to_convert_webm = $webm_file;
-                $to_convert_webm_thumb =
-                    "$thumb_path/$media_base_name.webm.jpg";
-            }
-            crawlLog("...media file conversions have been started...");
-            return;
-        }
-        if ($to_convert_mp4 && $this->isNoLongerModified($to_convert_mp4)) {
-                $this->thumbFileFromVideo($to_convert_mp4,
-                    $to_convert_mp4_thumb);
-                crawlLog(".. $to_convert_mp4 converted and thumb made.");
-                $to_convert_mp4 = "";
-                $to_convert_mp4_thumb = "";
-        }
-        if ($to_convert_webm && $this->isNoLongerModified($to_convert_webm)) {
-            $this->thumbFileFromVideo($to_convert_webm,
-                $to_convert_webm_thumb);
-            crawlLog(".. $to_convert_webm converted and thumb made.");
-            $to_convert_webm = "";
-            $to_convert_webm_thumb = "";
-        }
-        if ($to_convert_mp4 == "" && $to_convert_webm == "" ) {
-            $parser = new WikiParser();
-            $parsed_page = $parser->parse($page);
-            if ($parsed_page) {
-                crawlLog("... re-parsing media page $page_name...");
-                $parsed_page = $group_model->insertResourcesParsePage($group_id,
-                    $page_id, $locale_tag, $parsed_page);
-                $sql = "UPDATE GROUP_PAGE SET PAGE=? WHERE ID = ?";
-                $this->group_model->db->execute(
-                    $sql, array($parsed_page, $page_id));
-            }
+        crawlLog("In video Updater Loop...");
+        if(MULTIPLE_NEWS_UPDATER){
+            $this->mediaConvert();
+        }else{
+           $this->mediaSplitVideo();
+           $this->moveFoldersToConverted();
+           $this->generateAssembleFile();
+           $this->mediaMerge();
         }
+        crawlLog("Video updates done!...");
     }
     /**
      * Checks if it has been more than two minutes since the last time
@@ -335,6 +243,268 @@ class MediaUpdater implements CrawlConstants
         exec($make_thumb_string);
         clearstatcache($thumb_name);
     }
+    /**
+     * Splits a video into small chunks of 5 minutes
+     *
+     * @param string.$file_path full path of video file to be split
+     * @param string file_name.name of video file along with extension
+     * @param.string.$destination_directory.destination directory.name
+     *      where split files would be produced
+     */
+    function splitVideo($file_path,$file_name,$destination_directory)
+    {
+        crawlLog("converting $filepath/$name......");
+        $new_name = substr($file_name, 0, -4);
+        $extension= substr($file_name,-4);
+        $ffmpeg = FFMPEG." -i \"$file_path/$file_name\" ".
+            " -acodec copy -f segment -segment_time 300 ".
+            "-vcodec copy -reset_timestamps 1 -map 0 ".
+            "\"$destination_directory/%d$new_name$extension\"";
+        echo $ffmpeg;
+        exec($ffmpeg);
+    }
+    /**
+     * Function to look through all the video directories present in media.
+     * convert folder generated by group model.and split the eligible.files.
+     *
+     */
+    function mediaSplitVideo()
+    {
+        crawlLog("inside mediaSplitVideo function...");
+        $convert_folder = WORK_DIRECTORY."/schedules/media_convert";
+        if(!defined('FFMPEG') || !file_exists($convert_folder)) { return; }
+        crawlLog("Entering media files to split video...");
+        foreach (glob($convert_folder."/*") as $videodir) {
+            if (is_dir($videodir)){
+                if (!file_exists($videodir."/split.txt")){return;}
+                if (file_exists($videodir."/split.txt")){
+                    crawlLog("splitting the video $videodir");
+                    $lines = file($videodir."/file_info.txt");
+                    $folder_name = $lines[1];
+                    $file_name = $lines[3];
+                    echo "$folder : $file_name";
+                    if ($folder_name && $file_name){
+                        $this->splitVideo(WORK_DIRECTORY."/".$folder_name,
+                           $file_name,$videodir);
+                        unlink($videodir."/split.txt");
+                        file_put_contents($videodir."/count.txt",
+                            count(glob($videodir."/*.{mov,avi}",GLOB_BRACE)));
+                    }
+                }
+            }
+        }
+    }
+    /**
+     * Function to look through all the video directories present in media.
+     * convert folder and move them to converted folders if all the split files.
+     * are convrted and are present in video.directory.under.converted.
+     */
+    function moveFoldersToConverted()
+    {
+        crawlLog("Moving folders from media_convert to converted...");
+        $convert_folder = WORK_DIRECTORY. "/schedules/media_convert";
+        $converted_folder = WORK_DIRECTORY. "/schedules/converted";
+        foreach(glob($convert_folder."/*") as $videodir) {
+            echo "videodir : $videodir",PHP_EOL;
+            $actual_count = file_get_contents($videodir."/count.txt");
+            echo "actual_count : $actual_count",PHP_EOL;
+            $taken_count = 0;
+            foreach(glob($videodir."/*.{avi,mov}",GLOB_BRACE) as $file){
+                if (strpos($file,'taken') !== false) {
+                    $taken_count++;
+                }
+            }
+            echo "taken_count : $taken_count",PHP_EOL;
+            if($actual_count! = $taken_count){
+                echo "in here";
+                continue;
+            }else{
+                $videodir=str_replace($convert_folder."/","",$videodir);
+                if (!file_exists($converted_folder."/".$videodir)){
+                    continue;
+                }
+                else{
+
+                    $converted_count =
+                        count(glob($converted_folder."/".$videodir."/*.{mp4}",
+                            GLOB_BRACE));
+
+                    if($converted_count == $taken_count){
+                        rename($convert_folder."/".$videodir."/count.txt",
+                                $converted_folder."/".$videodir."/count.txt");
+                        rename($convert_folder."/".$videodir."/file_info.txt",
+                              $converted_folder."/".$videodir."/file_info.txt");
+                        $this->deleteDirectory($convert_folder."/".$videodir);
+                    }
+                }
+            }
+        }
+    }
+    /**
+     * Function to look through all the converted.video directories present in
+     * media and generate.the.assemble.files.needed.for concatenating the.
+     * converted.split.files.
+     *
+     */
+    function generateAssembleFile()
+    {
+        crawlLog("-------------inside generateConcatFile function...");
+        $converted_folder = WORK_DIRECTORY. "/schedules/converted";
+        foreach(glob($converted_folder."/*") as $videodir) {
+            if(file_exists($videodir."/concatenated.txt")){continue;}
+            if(file_exists($videodir."/ready_to_assemble.txt")){continue;}
+            $actual_count = file_get_contents($videodir."/count.txt");
+            $files = glob($videodir."/*.{mp4}",GLOB_BRACE);
+            $converted_count = count($files);
+            if ($actual_count == $converted_count){
+                foreach($files as $file){
+                    file_put_contents($videodir."/ready_to_assemble.txt",
+                        "file "."'".(str_replace($videodir."/","",$file))."'",
+                         FILE_APPEND);
+                    file_put_contents($videodir."/ready_to_assemble.txt",
+                        PHP_EOL,FILE_APPEND);
+                }
+            }
+        }
+    }
+     /**
+     * concatenates split video files to generate one video file
+     *
+     * @param string.$text_file_name.file.path.containing.the relative file.
+     *      paths of the files to be concatenated
+     * @param string file_name.name of video file to.be.given.to.output.file.
+     * @param.string.$destination_directory.destination directory.name
+     *      where concatenated file would be produced
+     */
+    function mergeVideo($text_file_name,$file_name,$destination_directory)
+    {
+        $extension = substr($file_name,-4);
+        $name = substr($file_name,0,-4);
+        if (!file_exists("$name.txt")) {return; }
+        $generate_output=$destination_directory."/$name.mp4";
+        $ffmpeg = FFMPEG."-f concat -i \"$text_file_name\" -c copy
+                        \"$generate_output\"";
+        echo $ffmpeg."\n";
+        exec($ffmpeg);
+    }
+     /**
+     * Function to look.through each video directory.and.call.the.function.to
+     * concatenate split files.
+     *
+     */
+    function mediaMerge()
+    {
+        crawlLog("Concatenating videos...");
+        $converted_folder = WORK_DIRECTORY. "/schedules/converted";
+        foreach(glob($converted_folder."/*") as $videodir) {
+            echo "videodir is ".$videodir;
+            if (is_dir($videodir)){
+                if(!file_exists($videodir."/ready_to_assemble.txt")){continue;}
+                $filename = $videodir."/ready_to_assemble.txt";
+                $lines = file($videodir."/file_info.txt");
+                $folder_name = $lines[1];
+                $file_name = $lines[3];
+                $this->mergeVideo($filename,$file_name,$folder_name);
+                file_put_contents($videodir."/concatenated.txt","done!");
+                echo "videodir is ------".$videodir;
+                $this->deleteDirectory($videodir);
+            }
+        }
+    }
+    /**
+     * Function to delete directory.
+     *
+     * @param string $directory full path of the directory.
+     */
+    function deleteDirectory($directory)
+    {
+        if(!file_exists($directory)) {return;}
+        foreach(glob($directory."/*") as $file){
+            unlink($file);
+        }
+        rmdir($directory);
+    }
+     /**
+     * Function to convert avi or mov file to mp4 format.
+     *
+     * @param string $file_name full path of the file.
+     */
+    function Convert($file_name)
+    {
+        $new_name = substr($file_name, 0, -4);
+        $extension = substr($file_name, -4);
+
+        //if(file_exists($name."mov")) {continue; }
+        if($extension == '.mov'){
+            $ffmpeg = "ffmpeg -i \"$name\" ".
+                " -vcodec h264 -acodec aac -preset veryfast -crf 28 ".
+                "-strict -2 \"$new_name.mp4\"";
+        }
+        if($extension = '.avi'){
+            $ffmpeg = FFMPEG." -i \"$name\" ".
+                " -vcodec libx264  -preset slow -acodec aac -crf 28 ".
+                "-strict experimental -b:a 192k -ac 2 \"$new_name.mp4\"";
+        }
+    echo $ffmpeg."\n";
+    exec($ffmpeg);
+    }
+    /**
+     * Function to convert a mov or avi video file to mp4 file
+     * This function would only be called by slave media updaters.
+     *
+     */
+    function mediaConvert()
+    {
+        crawlLog("inside mediaConvert function");
+        $convert_folder=WORK_DIRECTORY."/schedules/media_convert";
+        $time = time();
+        $session = md5($time . AUTH_KEY);
+        $server = NAME_SERVER;
+        $folder_file = $this->sourceModel->requestFileForConversion();
+        if (!$folder_file)
+            crawlLog("Did not get any file from server to convert!");
+        if($folder_file)
+        {
+            $info = explode(":",$folder_file);
+            $folder_name = $info[0];
+            $file_name = $info[1];
+            /* This code is written to download the file from the server
+                */
+            $request = "$server?c=resource&a=get&time=$time&session=$session".
+            "&f=schedules&n=". urlencode($file_name)."&sf=$folder_name";
+            $data = FetchUrl::getPage($request, NULL, true);
+            if(file_exists($convert_folder."/".$folder_name))
+            $this->deleteDirectory($convert_folder."/".$folder_name);
+            mkdir($convert_folder."/".$folder_name);
+            $downloaded_file = $convert_folder."/".$folder_name."/".$file_name;
+            file_put_contents($downloaded_file,$data);
+           /* This code is written to download the file from the server
+                */
+            $this->convert($downloaded_file);
+            $files = glob($convert_folder."/".$folder_name."/*.{mp4}",
+                GLOB_BRACE);
+            if(!$files[0])
+                crawlLog("Would try converting the same file after some time");
+            else{
+                $converted_file_path = $files[0];
+                $converted_file_name = 
+                    str_replace($convert_folder."/".$folder_name."/","",
+                        $converted_file_path);
+            }
+            /* This code is written to upload the file to the server
+                */
+            $file = $convert_folder."/".$folder_name."/".$converted_file_name;
+            $filedata=file_get_contents($file);
+            $post_data['c'] = "resource";
+            $post_data['a'] = "getUploadedFile";
+            $post_data['time'] = $time;
+            $post_data['session'] = $session;
+            $post_data['data'] = webencode($filedata);
+            $post_data['filename'] = webencode($converted_file_name);
+            $post_data['foldername'] = webencode($folder_name);
+            $response = FetchUrl::getPage($server, $post_data ,true);
+        }
+    }
 }
 /*
  * Instantiate and runs the MediaUpdater program
diff --git a/configs/config.php b/configs/config.php
index c028a06..5d44cfe 100755
--- a/configs/config.php
+++ b/configs/config.php
@@ -491,6 +491,17 @@ if (!defined("MAX_VIDEO_CONVERT_SIZE")) {
     define("MAX_VIDEO_CONVERT_SIZE", 20000000);
 }
 /**
+ * the maximum time limit in seconds where if a file is not converted by the
+ * time it will be picked up again by the slave media updater
+ * This value largely depends on the no of slave media updaters that we have
+ * and also the maximum video size that would be uploaded to yioop.
+ * This value should be kept more than the sleeping time of media updater
+ * loop to avoid conversion of same file multiple times.
+ */
+if(!defined("MAX_FILE_TIMESTAMP_LIMIT")) {
+    define('MAX_FILE_TIMESTAMP_LIMIT', 600);
+}
+/**
  * @global array file extensions which can be handled by the search engine,
  * other extensions will be ignored. This array is populated in the individual
  * lib/processors page processors
diff --git a/controllers/crawl_controller.php b/controllers/crawl_controller.php
index 2130a35..dbf5c77 100644
--- a/controllers/crawl_controller.php
+++ b/controllers/crawl_controller.php
@@ -56,7 +56,7 @@ class CrawlController extends Controller implements CrawlConstants
     var $activities = array("countWords","clearQuerySavePoint",
         "crawlStalled", "crawlStatus", "deleteCrawl", "injectUrlsCurrentCrawl",
         "combinedCrawlInfo", "getInfoTimestamp", "getCrawlItems",
-        "getCrawlList", "getCrawlSeedInfo", "getNewsSources",
+        "getCrawlList", "getCrawlSeedInfo", "getNewsSources","getFolderFile",
         "sendStartCrawlMessage", "sendStopCrawlMessage", "setCrawlSeedInfo",);
     /**
      * Checks that the request seems to be coming from a legitimate fetcher then
@@ -359,4 +359,64 @@ class CrawlController extends Controller implements CrawlConstants
         }
         echo webencode(serialize($feeds));
     }
+    /**
+     * Handles the request to get the video file from the video directory for
+     * conversion. This selection is based upon if the file was taken
+     * previously or not. If it was then its timestamp is checked.
+     * Otherwise new file is sent for conversion along with its folder name.
+     */
+    function getFolderFile()
+    {
+        if (!isset($_REQUEST["arg"])) {
+            return;
+        }
+        $current_machine = $this->clean(webdecode($_REQUEST["arg"]), "string");
+        $convert_folder = WORK_DIRECTORY. "/schedules/media_convert";
+        foreach (glob($convert_folder."/*") as $folder){
+            foreach (glob($folder."/*.{mov,avi}",GLOB_BRACE) as $file){
+                $folder_name =
+                    str_replace(WORK_DIRECTORY."/schedules/media_convert/","",
+                        $folder);
+                $file_name = str_replace($convert_folder."/".$folder_name."/",
+                    "",$file);
+                if (strpos($file_name,"taken")! = false){
+                    $file_time = strstr($file_name, '-', true);
+                    $current_time = time();
+                    $diff = ($current_time-$file_time);
+                    if ($diff>MAX_FILE_TIMESTAMP_LIMIT){
+                        $original_file_stamp = strstr($file_name, '-',true);
+                        $new_file_name = str_replace($original_file_stamp,
+                            time(),$file_name);
+                        rename($convert_folder."/".$folder_name."/".$file_name,
+                          $convert_folder."/".$folder_name."/".$new_file_name);
+                        $folder_file = $folder_name.":".$new_file_name;
+
+                    }else {
+                        continue;
+                    }
+                }else{
+                    $new_file_name = time()."-taken".$file_name;
+                    rename($convert_folder."/".$folder_name."/".$file_name,
+                        $convert_folder."/".$folder_name."/".$new_file_name);
+                    $folder_file = $folder_name.":".$new_file_name;
+                }
+                if (!empty($folder_file)){
+                    break;
+                }else{
+                    continue;
+                }
+            }
+            if (!empty($folder_file)){
+                break;
+            }else{
+                continue;
+            }
+        }
+        file_put_contents(WORK_DIRECTORY."/schedules/global_info.txt",
+            $current_machine."is working on file_name[".$new_file_name."]
+            from folder[".$folder_name."]...",FILE_APPEND);
+        file_put_contents(WORK_DIRECTORY."/schedules/global_info.txt",PHP_EOL,
+            FILE_APPEND);
+        echo webencode($folder_file);
+    }
 }
diff --git a/controllers/resource_controller.php b/controllers/resource_controller.php
index 361009d..a9d6503 100644
--- a/controllers/resource_controller.php
+++ b/controllers/resource_controller.php
@@ -47,7 +47,8 @@ class ResourceController extends Controller implements CrawlConstants
      * These are the activities supported by this controller
      * @var array
      */
-    var $activities = array("get", "syncList", "syncNotify", "suggest");
+    var $activities = array("get", "syncList", "syncNotify", 
+        "suggest","getUploadedFile");
     /**
      * Checks that the request seems to be coming from a legitimate fetcher
      * or mirror server then determines which activity  is being requested
@@ -102,6 +103,13 @@ class ResourceController extends Controller implements CrawlConstants
             }
             $folder = $_REQUEST['f'];
             $base_dir = CRAWL_DIR."/$folder";
+        } else if(in_array($_REQUEST['f'], array("schedules"))) {
+
+            if(!$this->checkRequest()) {
+                return;
+            }
+            $folder = $_REQUEST['sf'];
+            $base_dir = CRAWL_DIR."/schedules/media_convert/$folder";
         } else {
             return;
         }
@@ -302,4 +310,36 @@ class ResourceController extends Controller implements CrawlConstants
         }
         echo base64_encode(gzcompress(serialize($info)));
     }
+    /**
+     * Handles request to upload the posted data (video file data)
+     * in correct location as per the request attributes such as
+     * folder name and file name.
+     */
+
+    function getUploadedFile()
+    {
+        if (!isset($_REQUEST['data']) || !isset($_REQUEST['foldername'])||
+            !isset($_REQUEST['filename'])) { return; }
+        $converted_folder = WORK_DIRECTORY."/schedules/converted";
+        $data = $_REQUEST['data'];
+        $folder_name = webdecode($_REQUEST['foldername']);
+        $file_name = webdecode($_REQUEST['filename']);
+        $uploaded_file = $converted_folder."/".$folder_name."/".$file_name;
+        if (!$data){
+            crawlLog("data not present!");
+            return;
+        }
+        if (file_exists($converted_folder."/".$folder_name)){
+            if(file_exists($uploaded_file)){
+                crawlLog("Already present!");
+                return;
+            }else{
+                file_put_contents($uploaded_file,webdecode($data));
+            }
+        }else{
+            mkdir($converted_folder."/".$folder_name);
+            file_put_contents($uploaded_file,webdecode($data));
+            return "uploaded succesfully!";
+        }
+    }
 }
diff --git a/models/group_model.php b/models/group_model.php
index 128753b..8d15720 100644
--- a/models/group_model.php
+++ b/models/group_model.php
@@ -1404,14 +1404,24 @@ class GroupModel extends Model
             clearstatcache("$thumb_folder/$file_name.jpg");
             if ($file_size < MAX_VIDEO_CONVERT_SIZE) {
                 $convert_folder = WORK_DIRECTORY. "/schedules/media_convert";
-                if (!file_exists($convert_folder) && !mkdir($convert_folder)) {
+                if(!file_exists($convert_folder) && !mkdir($convert_folder)) {
                     return;
                 }
                 $num_convert_files = count(glob($convert_folder. "/*.txt"));
-                $convert_file = $convert_folder. "/" .time().
-                    crawlHash($file_name) . ".txt";
-                file_put_contents($convert_file,
+                $video_directory =
+                    $convert_folder."/". crawlHash($file_name).time();
+                mkdir($video_directory);
+                if(!file_exists($video_directory) && !mkdir($video_directory)) {
+                    return;
+                }
+                if(file_exists($video_directory))
+                {
+                    $split_file = $video_directory."/split.txt";
+                    file_put_contents($split_file,"split this!");
+                    $file_info = $video_directory. "/file_info.txt";
+                    file_put_contents($file_info,
                     "$page_id\n$folder\n$thumb_folder\n$file_name");
+                }
             }
         }
     }
diff --git a/models/source_model.php b/models/source_model.php
index c792b0a..5faa42c 100644
--- a/models/source_model.php
+++ b/models/source_model.php
@@ -754,5 +754,20 @@ class SourceModel extends ParallelModel
         }
         return $meta_ids;
     }
+     /**
+     * Used to make an exec call to the crawl controller
+     * to get the next available file for conversion
+     *
+     * @return folder and file name
+     */
+    function requestFileForConversion()
+    {
+        $current_machine = file_get_contents(WORK_DIRECTORY.
+                "/schedules/current_machine_info.txt");
+        $folder_file=$this->execMachines("getFolderFile",array(NAME_SERVER),
+                $current_machine);
+        $value=webdecode($folder_file[0][CrawlConstants::PAGE]);
+        return $value;
+    }
 }
  ?>
\ No newline at end of file
diff --git a/views/machinestatus_view.php b/views/machinestatus_view.php
index c95c437..5537647 100644
--- a/views/machinestatus_view.php
+++ b/views/machinestatus_view.php
@@ -79,9 +79,6 @@ class MachinestatusView extends View
         <h3 class="nomargin"><?php
             e(tl('machinestatus_name_server'));
         ?></h3>
-        <?php
-        if ($name_server_update) {
-            ?>
             <form id="mediaModeForm" method="post">
             <input type="hidden" name="c" value="admin" />
             <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
@@ -99,7 +96,6 @@ class MachinestatusView extends View
             </tr></table>
             </form>
             <?php
-        }
         if (count($data['MACHINES']) > 1) {
             $data['TABLE_TITLE'] = "";
             $data['ACTIVITY'] = 'manageMachines';
-- 
1.9.4.msysgit.1

