Better management of external streamers. V01.46.03
authorcavaliet
Thu, 04 Apr 2013 12:25:21 +0200
changeset 1138 d0fdcae534a9
parent 1137 5398ca46d056
child 1139 663f30404042
Better management of external streamers.
src/ldt/ldt/__init__.py
src/ldt/ldt/ldt_utils/views/content.py
--- a/src/ldt/ldt/__init__.py	Wed Apr 03 10:49:32 2013 +0200
+++ b/src/ldt/ldt/__init__.py	Thu Apr 04 12:25:21 2013 +0200
@@ -1,4 +1,4 @@
-VERSION = (1, 46, 2, "final", 0)
+VERSION = (1, 46, 3, "final", 0)
 
 
 def get_version():
--- a/src/ldt/ldt/ldt_utils/views/content.py	Wed Apr 03 10:49:32 2013 +0200
+++ b/src/ldt/ldt/ldt_utils/views/content.py	Thu Apr 04 12:25:21 2013 +0200
@@ -44,9 +44,27 @@
         del cleaned_data["media_file"]
         if not cleaned_data['videopath']:
             cleaned_data['videopath'] = settings.STREAM_URL
-        # if the source is already http:// or rtmp:// we don't have to add STREAM_URL
-        if cleaned_data['src'].startswith("rtmp://") or cleaned_data['src'].startswith("http://") or cleaned_data['src'].startswith("https://"):
-            cleaned_data['videopath'] = ''    
+        # if the source is already http:// we don't have to add STREAM_URL
+        if cleaned_data['src'].startswith("http://") or cleaned_data['src'].startswith("https://"):
+            cleaned_data['videopath'] = ''
+        # if the source is rtmp:// we parse the url to add a correct rtmp provider as videopath
+        elif cleaned_data['src'].startswith("rtmp://"):
+            cleaned_data['videopath'] = ''
+            # If the url is kind of rtmp://site/flv:path/to/file.flv or rtmp://site/mp4:path/to/file.mp4, we parse it.
+            # If the url is kind of rtmp://site/path/to/file, we don't parse it because we can't get the right streamer.
+            a = cleaned_data['src'].split(":")
+            if len(a)==3 and (a[1].endswith("flv") or a[1].endswith("mp4") or a[1].endswith("mp3")):
+                # We update with the good streamer
+                cleaned_data['videopath'] = a[0] + ":" + a[1][:-3]
+                # We remove the "flv:" from the url because it's useless in the real url
+                if a[1].endswith("flv"):
+                    cleaned_data['src'] = a[2]
+                else:
+                    cleaned_data['src'] = a[1][-3:] + ":" + a[2]
+                # We remove the ".mp3" at the the end of the src if necessary
+                if a[1].endswith("mp3") and cleaned_data['src'].endswith(".mp3"):
+                    cleaned_data['src'] = cleaned_data['src'][:-4]
+        # We get or create the media with the correct datas
         media, created = Media.objects.get_or_create(src=cleaned_data['src'], defaults=cleaned_data) #@UndefinedVariable
     
     elif media_input_type == "url" or media_input_type == "upload" :