diff --git a/formats/M3uFormat.php b/formats/M3uFormat.php
index be2895cf..3c580c49 100644
--- a/formats/M3uFormat.php
+++ b/formats/M3uFormat.php
@@ -15,10 +15,60 @@ class M3uFormat extends FormatAbstract
         foreach ($this->getItems() as $item) {
             $itemArray = $item->toArray();
 
-            if (isset($itemArray['itunes']) && isset($itemArray['enclosure'])) {
-                $contents .= $itemArray['enclosure']['url'] . "\n";
+            $m3uitem = new M3uItem();
+
+            if (isset($itemArray['enclosure'])) {
+                $m3uitem->url = $itemArray['enclosure']['url'];
+                $m3uitem->bytes = $itemArray['enclosure']['length'];
             }
+            if (isset($itemArray['itunes']) && isset($itemArray['itunes']['duration'])) {
+                $m3uitem->duration = parse_duration($itemArray['itunes']['duration']);
+            }
+            if (isset($itemArray['title'])) {
+                $m3uitem->title = $itemArray['title'];
+            }
+            $contents .= $m3uitem->render();
         }
         return mb_convert_encoding($contents, $this->getCharset(), 'UTF-8');
     }
 }
+
+function parse_duration($duration_string)
+{
+    $seconds = 0;
+    $parts = explode(':', $duration_string);
+    for ($i = 0; $i < count($parts); $i++) {
+        $seconds += intval($parts[count($parts) - $i - 1]) * pow(60, $i);
+    }
+    return $seconds;
+}
+
+class M3uItem
+{
+    public $duration = null;
+    public $title = null;
+    public $url = null;
+    public $bytes = null;
+
+    public function render()
+    {
+        if ($this->url === null) {
+            return '';
+        }
+        $text = '';
+        $commentParts = [];
+        if ($this->duration !== null && $this->duration > 0) {
+            $commentParts[] = $this->duration;
+        }
+        if ($this->title !== null) {
+            $commentParts[] = $this->title;
+        }
+
+        if (count($commentParts) !== 0) {
+            $text .= '#EXTINF:' . implode(',', $commentParts) . "\n";
+        }
+
+        $text .= $this->url . "\n";
+        return $text;
+    }
+}