Exemplo n.º 1
0
def get_media(url, options):

    stream = service_handler(url)
    if not stream:
        url, stream = Generic().get(url)
    if not stream:
        log.error("That site is not supported. Make a ticket or send a message")
        sys.exit(2)

    if options.all_episodes:
        if options.output and os.path.isfile(options.output):
            log.error("Output must be a directory if used with --all-episodes")
            sys.exit(2)
        elif options.output and not os.path.exists(options.output):
            try:
                os.makedirs(options.output)
            except OSError as e:
                log.error("%s: %s" % (e.strerror,  e.filename))
                return

        episodes = stream.find_all_episodes(options)

        for idx, o in enumerate(episodes):
            if o == url:
                substream = stream
            else:
                substream = service_handler(o)

            log.info("Episode %d of %d", idx + 1, len(episodes))

            # get_one_media overwrites options.output...
            get_one_media(substream, copy.copy(options))
    else:
        get_one_media(stream, options)
Exemplo n.º 2
0
def get_all_episodes(stream, url, options):
    name = os.path.dirname(formatname({"basedir": True}, stream.config))

    if name and os.path.isfile(name):
        logging.error("Output must be a directory if used with --all-episodes")
        sys.exit(2)
    elif name and not os.path.exists(name):
        try:
            os.makedirs(name)
        except OSError as e:
            logging.error("%s: %s", e.strerror, e.filename)
            return

    episodes = stream.find_all_episodes(stream.config)
    if episodes is None:
        return
    for idx, o in enumerate(episodes):
        if o == url:
            substream = stream
        else:
            substream = service_handler(sites, copy.copy(stream.config), o)

        logging.info("Episode %d of %d", idx + 1, len(episodes))
        logging.info("Url: %s", o)

        if not (options.get("get_url")
                and options.get("get_only_episode_url")):
            # get_one_media overwrites options.output...
            get_one_media(substream)
Exemplo n.º 3
0
def get_all_episodes(stream, options, url):
    if options.output and os.path.isfile(options.output):
        log.error("Output must be a directory if used with --all-episodes")
        sys.exit(2)
    elif options.output and not os.path.exists(options.output):
        try:
            os.makedirs(options.output)
        except OSError as e:
            log.error("%s: %s", e.strerror, e.filename)
            return

    episodes = stream.find_all_episodes(options)
    if episodes is None:
        return
    for idx, o in enumerate(episodes):
        if o == url:
            substream = stream
        else:
            substream = service_handler(sites, copy.copy(options), o)

        log.info("Episode %d of %d", idx + 1, len(episodes))
        log.info("Url: %s",o) 

        # get_one_media overwrites options.output...
        get_one_media(substream, copy.copy(options))
Exemplo n.º 4
0
def get_media(url, options):
    if "http" not in url[:4]:
        url = "http://%s" % url

    if options.silent_semi:
        options.silent = True
    if options.verbose:
        log.debug("version: {0}".format( __version__))
    stream = service_handler(sites, options, url)
    if not stream:
        generic = Generic(options, url)
        url, stream = generic.get(sites)
    if not stream:
        if url.find(".f4m") > 0 or url.find(".m3u8") > 0:
            stream = Raw(options, url)
        if not stream:
            log.error("That site is not supported. Make a ticket or send a message")
            sys.exit(2)

    if is_py2:
        url = ensure_unicode(url)

    if options.all_episodes:
        get_all_episodes(stream, copy.copy(options), url)
    else:
        get_one_media(stream, copy.copy(options))
Exemplo n.º 5
0
def get_all_episodes(stream, options, url):
    if options.output and os.path.isfile(options.output):
        log.error("Output must be a directory if used with --all-episodes")
        sys.exit(2)
    elif options.output and not os.path.exists(options.output):
        try:
            os.makedirs(options.output)
        except OSError as e:
            log.error("%s: %s", e.strerror, e.filename)
            return

    episodes = stream.find_all_episodes(options)
    if episodes is None:
        return
    for idx, o in enumerate(episodes):
        if o == url:
            substream = stream
        else:
            substream = service_handler(sites, copy.copy(options), o)

        log.info("Episode %d of %d", idx + 1, len(episodes))
        log.info("Url: %s", o)

        # get_one_media overwrites options.output...
        get_one_media(substream, copy.copy(options))
Exemplo n.º 6
0
def get_media(url, options):
    if "http" not in url[:4]:
        url = "http://%s" % url

    if options.silent_semi:
        options.silent = True
    if options.verbose:
        log.debug("version: {0}".format(__version__))
    stream = service_handler(sites, options, url)
    if not stream:
        generic = Generic(options, url)
        url, stream = generic.get(sites)
    if not stream:
        if re.search(".f4m", url) or re.search(".m3u8", url) or re.search(
                ".mpd", url):
            stream = Raw(options, url)
        if not stream:
            log.error(
                "That site is not supported. Make a ticket or send a message")
            sys.exit(2)

    if is_py2:
        url = ensure_unicode(url)

    if options.all_episodes:
        get_all_episodes(stream, copy.copy(options), url)
    else:
        get_one_media(stream, copy.copy(options))
Exemplo n.º 7
0
def get_media(url, options):
    stream = service_handler(url)
    if not stream:
        url, stream = Generic().get(url)
        url = url.replace("&", "&")
    if not stream:
        log.error("That site is not supported. Make a ticket or send a message")
        sys.exit(2)

    if not options.output or os.path.isdir(options.output):
        data = get_http_data(url)
        match = re.search("(?i)<title.*>\s*(.*?)\s*</title>", data)
        if match:
            if sys.version_info > (3, 0):
                title = re.sub('[^\w\s-]', '', match.group(1)).strip().lower()
                if options.output:
                    options.output = options.output + re.sub('[-\s]+', '-', title)
                else:
                    options.output = re.sub('[-\s]+', '-', title)
            else:
                title = unicode(re.sub('[^\w\s-]', '', match.group(1)).strip().lower())
                if options.output:
                    options.output = unicode(options.output + re.sub('[-\s]+', '-', title))
                else:
                    options.output = unicode(re.sub('[-\s]+', '-', title))

    stream.get(options, url)
Exemplo n.º 8
0
def get_media(url, options):
    if "http" not in url[:4]:
        url = "http://%s" % url

    if options.silent_semi:
        options.silent = True
    stream = service_handler(sites, options, url)
    if not stream:
        generic = Generic(options, url)
        url, stream = generic.get(sites)
    if not stream:
        if url.find(".f4m") > 0 or url.find(".m3u8") > 0:
            stream = Raw(options, url)
        if not stream:
            log.error(
                "That site is not supported. Make a ticket or send a message")
            sys.exit(2)

    if is_py2:
        url = ensure_unicode(url)

    if options.all_episodes:
        get_all_episodes(stream, options, url)
    else:
        get_one_media(stream, options)
Exemplo n.º 9
0
def get_media(url, options):
    if "http" not in url[:4]:
        url = "http://%s" % url

    stream = service_handler(sites, options, url)
    if not stream:
        generic = Generic(options, url)
        url, stream = generic.get(sites)
    if not stream:
        if url.find(".f4m") > 0 or url.find(".m3u8") > 0:
            stream = Raw(options, url)
        if not stream:
            log.error("That site is not supported. Make a ticket or send a message")
            sys.exit(2)

    if options.all_episodes:
        if options.output and os.path.isfile(options.output):
            log.error("Output must be a directory if used with --all-episodes")
            sys.exit(2)
        elif options.output and not os.path.exists(options.output):
            try:
                os.makedirs(options.output)
            except OSError as e:
                log.error("%s: %s" % (e.strerror, e.filename))
                return

        episodes = stream.find_all_episodes(options)
        if episodes is None:
            return
        for idx, o in enumerate(episodes):
            if o == url:
                substream = stream
            else:
                substream = service_handler(sites, options, o)

            log.info("Episode %d of %d", idx + 1, len(episodes))

            # get_one_media overwrites options.output...
            get_one_media(substream, copy.copy(options))
    else:
        get_one_media(stream, options)
Exemplo n.º 10
0
def get_media(url, options):
    if "http" not in url[:4]:
        url = "http://%s" % url

    stream = service_handler(sites, options, url)
    if not stream:
        generic = Generic(options, url)
        url, stream = generic.get(sites)
    if not stream:
        if url.find(".f4m") > 0 or url.find(".m3u8") > 0:
            stream = Raw(options, url)
        if not stream:
            log.error("That site is not supported. Make a ticket or send a message")
            sys.exit(2)

    if options.all_episodes:
        get_all_episodes(stream, options, url)
    else:
        get_one_media(stream, options)
Exemplo n.º 11
0
def get_media(url, options, version="Unknown"):
    if "http" not in url[:4]:
        url = "http://%s" % url

    if options.get("verbose"):
        logging.debug("version: {0}".format(version))

    stream = service_handler(sites, options, url)
    if not stream:
        generic = Generic(options, url)
        url, stream = generic.get(sites)
    if not stream:
        if url.find(".f4m") > 0 or url.find(".m3u8") > 0 or url.find(".mpd") > 1:
            stream = Raw(options, url)
        if not stream:
            logging.error("That site is not supported. Make a ticket or send a message")
            sys.exit(2)

    if options.get("all_episodes") or stream.config.get("all_episodes"):
        get_all_episodes(stream, url)
    else:
        get_one_media(stream)
Exemplo n.º 12
0
 def test_service_handler(self):
     config = setup_defaults()
     assert isinstance(
         service_handler(sites, config, "https://www.svtplay.se"), Service)
Exemplo n.º 13
0
 def test_service_handler(self):
     config = setup_defaults()
     assert not service_handler(sites, config, "localhost")
Exemplo n.º 14
0
 def test_service_handler(self):
     config = setup_defaults()
     self.assertIsInstance(service_handler(sites, config, "https://www.svtplay.se"), Service)
Exemplo n.º 15
0
 def test_service_handler(self):
     config = setup_defaults()
     self.assertIsNone(service_handler(sites, config, "localhost"))
Exemplo n.º 16
0
 def test_service_handler(self):
     config = setup_defaults()
     self.assertIsNone(service_handler(sites, config, "localhost"))