# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
from __future__ import absolute_import

from svtplay_dl.service.aftonbladet import Aftonbladet
from svtplay_dl.service.dr import Dr
from svtplay_dl.service.expressen import Expressen
from svtplay_dl.service.hbo import Hbo
from svtplay_dl.service.justin import Justin
from svtplay_dl.service.kanal5 import Kanal5
from svtplay_dl.service.nrk import Nrk
from svtplay_dl.service.qbrick import Qbrick
from svtplay_dl.service.ruv import Ruv
from svtplay_dl.service.radioplay import Radioplay
from svtplay_dl.service.sr import Sr
from svtplay_dl.service.svtplay import Svtplay
from svtplay_dl.service.tv4play import Tv4play
from svtplay_dl.service.urplay import Urplay
from svtplay_dl.service.viaplay import Viaplay
from svtplay_dl.service.vimeo import Vimeo

class Service(object):
    pass

class Generic(object):
    ''' Videos embed in sites '''
    def get(self, sites, url):
        data = get_http_data(url)
        match = re.search("src=\"(http://www.svt.se/wd.*)\" frameborder", data)
        stream = None
        if match:
            url = match.group(1)
            for i in sites:
                if i.handle(url):
                    return url, i

        match = re.search("src=\"(http://player.vimeo.com/video/[0-9]+)\" ", data)
        if match:
            for i in sites:
                if i.handle(match.group(1)):
                    return match.group(1), i
        return url, stream

def service_handler(url):
    sites = [
        Aftonbladet(),
        Dr(),
        Expressen(),
        Hbo(),
        Justin(),
        Kanal5(),
        Nrk(),
        Qbrick(),
        Ruv(),
        Radioplay(),
        Sr(),
        Svtplay(),
        Tv4play(),
        Urplay(),
        Viaplay(),
        Vimeo()]

    handler = None

    for i in sites:
        if i.handle(url):
            handler = i
            break

    return handler

@@ -835,16 +835,247 @@
  Vimeo%0A%0A
+sites = %5B%0A    Aftonbladet(),%0A    Dr(),%0A    Expressen(),%0A    Hbo(),%0A    Justin(),%0A    Kanal5(),%0A    Nrk(),%0A    Qbrick(),%0A    Ruv(),%0A    Radioplay(),%0A    Sr(),%0A    Svtplay(),%0A    Tv4play(),%0A    Urplay(),%0A    Viaplay(),%0A    Vimeo()%5D%0A%0A
 class Se
@@ -1748,307 +1748,8 @@
 l):%0A
-    sites = %5B%0A        Aftonbladet(),%0A        Dr(),%0A        Expressen(),%0A        Hbo(),%0A        Justin(),%0A        Kanal5(),%0A        Nrk(),%0A        Qbrick(),%0A        Ruv(),%0A        Radioplay(),%0A        Sr(),%0A        Svtplay(),%0A        Tv4play(),%0A        Urplay(),%0A        Viaplay(),%0A        Vimeo()%5D%0A%0A
     
@@ -1871,9 +1871,8 @@
  handler
-%0A

move sites variable out from handler