# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor
from ..utils import ExtractorError


class SlidesLiveIE(InfoExtractor):
    _VALID_URL = r'https?://slideslive\.com/(?P<id>[0-9]+)'
    _TESTS = [{
        # video_service_name = YOUTUBE
        'url': 'https://slideslive.com/38902413/gcc-ia16-backend',
        'md5': 'b29fcd6c6952d0c79c5079b0e7a07e6f',
        'info_dict': {
            'id': 'LMtgR8ba0b0',
            'ext': 'mp4',
            'title': 'GCC IA16 backend',
            'description': 'Watch full version of this video at https://slideslive.com/38902413.',
            'uploader': 'SlidesLive Videos - A',
            'uploader_id': 'UC62SdArr41t_-_fX40QCLRw',
            'upload_date': '20170925',
        }
    }, {
        # video_service_name = youtube
        'url': 'https://slideslive.com/38903721/magic-a-scientific-resurrection-of-an-esoteric-legend',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_data = self._download_json(
            'https://ben.slideslive.com/player/' + video_id, video_id)
        service_name = video_data['video_service_name'].lower()
        if service_name == 'youtube':
            yt_video_id = video_data['video_service_id']
            return {
                '_type': 'url_transparent',
                'ie_key': 'Youtube',
                'id': yt_video_id,
                'thumbnail': video_data.get('thumbnail'),
                'title': video_data.get('title'),
                'url': yt_video_id,
            }
        else:
            raise ExtractorError(
                'Unsupported service name: {0}'.format(service_name), expected=True)

@@ -104,30 +104,27 @@
  import 
-ExtractorError
+smuggle_url
 %0A%0A%0Aclass
@@ -944,16 +944,358 @@
 : True,%0A
+    %7D, %7B%0A        # video_service_name = url%0A        'url': 'https://slideslive.com/38922070/learning-transferable-skills-1',%0A        'only_matching': True,%0A    %7D, %7B%0A        # video_service_name = vimeo%0A        'url': 'https://slideslive.com/38921896/retrospectives-a-venue-for-selfreflection-in-ml-research-3',%0A        'only_matching': True,%0A
     %7D%5D%0A%0A
@@ -1552,18 +1552,22 @@
         
-if
+assert
  service
@@ -1576,10 +1576,27 @@
 ame 
-==
+in ('url', 'vimeo',
  'yo
@@ -1601,27 +1601,26 @@
 youtube'
-:%0A 
+)%0A
         
    yt_vi
@@ -1615,19 +1615,15 @@
     
-   yt_video
+service
 _id 
@@ -1667,63 +1667,128 @@
     
-    return %7B%0A                '_type': 'url_transparent'
+info = %7B%0A            'id': video_id,%0A            'thumbnail': video_data.get('thumbnail'),%0A            'url': service_id
 ,%0A  
@@ -1793,24 +1793,26 @@
         
+%7D%0A
         
 'ie_key'
@@ -1807,119 +1807,216 @@
     
-'ie_key': 'Youtube',%0A                'id': yt_video_id,%0A                'thumbnail': video_data.get('thumbnail'
+if service_name == 'url':%0A            info%5B'title'%5D = video_data%5B'title'%5D%0A        else:%0A            info.update(%7B%0A                '_type': 'url_transparent',%0A                'ie_key': service_name.capitalize(
 ),%0A 
@@ -2080,31 +2080,50 @@
     
+%7D)%0A
     
-'url': yt_video_id,
+        if service_name == 'vimeo':
 %0A   
@@ -2123,33 +2123,62 @@
 o':%0A            
-%7D
+    info%5B'url'%5D = smuggle_url(
 %0A        else:%0A 
@@ -2162,38 +2162,32 @@
 le_url(%0A        
-else:%0A
             rais
@@ -2186,111 +2186,128 @@
     
-raise ExtractorError(%0A                'Unsupported service name: %7B0%7D'.format(service_name), expected=True)
+'https://player.vimeo.com/video/' + service_id,%0A                    %7B'http_headers': %7B'Referer': url%7D%7D)%0A        return info
 %0A

add support for url and vimeo service names(closes #23414)