2DU 9 лет назад
Родитель
Сommit
8f890de407
1 измененных файлов с 22 добавлено и 14 удалено
  1. 22 14
      mark.py

+ 22 - 14
mark.py

@@ -480,25 +480,33 @@ def namumark(title, data):
     data = re.sub("\[br\]",'<br>', data)
     data = re.sub("\[br\]",'<br>', data)
     
     
     while(True):
     while(True):
-        com = re.compile("\[youtube\((?:https:\/\/www\.youtube\.com\/watch\?v=|https:\/\/youtu\.be\/)?((?:(?!,|\)\]).)*)(?:,(?:\s)?)?(?:width=((?:(?!,|\)\]).)*))?(?:,(?:\s)?)?(?:height=((?:(?!,|\)\]).)*))?\)\]")
+        com = re.compile("\[youtube\(([^, )]*)(,[^)]*)?\)\]")
         m = com.search(data)
         m = com.search(data)
         if(m):
         if(m):
+            src = ''
+            width = '560'
+            height = '315'
+            
             result = m.groups()
             result = m.groups()
+            if(result[0]):
+                yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9]*))$', result[0])
+                if(yudt.groups()[0]):
+                    src = yudt.groups()[0]
+                elif(yudt.groups()[1]):
+                    src = yudt.groups()[1]
+                elif(yudt.groups()[2]):
+                    src = yudt.groups()[2]
+                    
             if(result[1]):
             if(result[1]):
-                if(result[2]):
-                    width = result[1]
-                    height = result[2]
-                else:
-                    width = result[1]
-                    height = '315'
-            elif(result[2]):
-                height = result[2]
-                width = '560'
-            else:
-                width = '560'
-                height = '315'
+                mdata = re.search('width=([0-9]*)', result[1])
+                if(mdata):
+                    width = mdata.groups()[0]
+                
+                mdata = re.search('height=([0-9]*)', result[1])
+                if(mdata):
+                    height = mdata.groups()[0]
 
 
-            data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + result[0] + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
+            data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + src + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
         else:
         else:
             break
             break