Exemple #1
0
def get_one_media(stream):
    # Make an automagic filename
    if not filename(stream):
        return

    if stream.config.get("merge_subtitle"):
        if not which("ffmpeg"):
            logging.error(
                "--merge-subtitle needs ffmpeg. Please install ffmpeg.")
            logging.info("https://ffmpeg.org/download.html")
            sys.exit(2)

    videos = []
    subs = []
    subfixes = []
    error = []
    streams = stream.get()
    try:
        for i in streams:
            if isinstance(i, Exception):
                error.append(i)
            elif not exclude(stream.config, formatname(i.output,
                                                       stream.config)):
                if isinstance(i, VideoRetriever):
                    if stream.config.get("preferred"):
                        if stream.config.get("preferred").lower() == i.name:
                            videos.append(i)
                    else:
                        videos.append(i)
                if isinstance(i, subtitle):
                    subs.append(i)
    except Exception:
        if stream.config.get("verbose"):
            raise
        else:
            logging.error("svtplay-dl crashed")
            logging.error(
                "Run again and add --verbose as an argument, to get more information"
            )
            logging.error(
                "If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues"
            )
            logging.error(
                "Include the URL used, the stack trace and the output of svtplay-dl --version in the issue"
            )
        return

    try:
        after_date = datetime.strptime(stream.config.get("after_date"),
                                       "%Y-%m-%d")
    except (ValueError, TypeError, KeyError,
            AttributeError):  # gotta catch em all..
        after_date = None
    try:
        pub_date = datetime.fromtimestamp(stream.output["publishing_datetime"])
    except (ValueError, TypeError, KeyError):
        pub_date = None
    if after_date is not None and pub_date is not None and pub_date.date(
    ) < after_date.date():
        logging.info(
            "Video {}S{}E{} skipped since published {} before {}. ".format(
                stream.output["title"], stream.output["season"],
                stream.output["episode"], pub_date.date(), after_date.date()))
        return

    if stream.config.get("require_subtitle") and not subs:
        logging.info("No subtitles available")
        return

    if stream.config.get("subtitle") and stream.config.get("get_url"):
        if subs:
            if stream.config.get("get_all_subtitles"):
                for sub in subs:
                    print(sub.url)
            else:
                print(subs[0].url)
        if stream.config.get("force_subtitle"):
            return

    def options_subs_dl(subfixes):
        if subs:
            if stream.config.get("get_all_subtitles"):
                for sub in subs:
                    sub.download()
                    if stream.config.get("merge_subtitle"):
                        if sub.subfix:
                            subfixes += [sub.subfix]
                        else:
                            stream.config.set("get_all_subtitles", False)
            else:
                subs[0].download()
        elif stream.config.get("merge_subtitle"):
            stream.config.set("merge_subtitle", False)

    if stream.config.get("subtitle") and not stream.config.get("get_url"):
        options_subs_dl(subfixes)
        if stream.config.get("force_subtitle"):
            if not subs:
                logging.info("No subtitles available")
            return

    if stream.config.get(
            "merge_subtitle") and not stream.config.get("subtitle"):
        options_subs_dl(subfixes)
    if not videos:
        errormsg = None
        for exc in error:
            if errormsg:
                errormsg = "{}. {}".format(errormsg, str(exc))
            else:
                errormsg = str(exc)
        if errormsg:
            logging.error("No videos found. {}".format(errormsg))
        else:
            logging.error("No videos found.")
    else:
        if stream.config.get("list_quality"):
            list_quality(videos)
            return
        if stream.config.get("nfo"):
            # Create NFO files
            write_nfo_episode(stream.output, stream.config)
            write_nfo_tvshow(stream.output, stream.config)
            if stream.config.get("force_nfo"):
                return
        try:
            fstream = select_quality(stream.config, videos)
            if fstream.config.get("get_url"):
                print(fstream.url)
                return
            logging.info("Selected to download %s, bitrate: %s", fstream.name,
                         fstream.bitrate)
            fstream.download()
        except UIException as e:
            if fstream.config.get("verbose"):
                raise e
            logging.error(e)
            sys.exit(2)

        if fstream.config.get("thumbnail") and hasattr(stream,
                                                       "get_thumbnail"):
            stream.get_thumbnail(stream.config)

        post = postprocess(fstream, fstream.config, subfixes)
        if fstream.audio and post.detect:
            post.merge()
        if fstream.audio and not post.detect and fstream.finished:
            logging.warning(
                "Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds"
            )
        if fstream.name == "hls" or fstream.config.get("remux"):
            post.remux()
        if fstream.config.get("silent_semi") and fstream.finished:
            logging.log(
                25, "Download of %s was completed" % fstream.options.output)
Exemple #2
0
def get_one_media(stream):
    # Make an automagic filename
    if not filename(stream):
        return

    if stream.config.get("merge_subtitle"):
        if not which('ffmpeg'):
            log.error("--merge-subtitle needs ffmpeg. Please install ffmpeg.")
            log.info("https://ffmpeg.org/download.html")
            sys.exit(2)

    videos = []
    subs = []
    subfixes = []
    error = []
    streams = stream.get()
    try:
        for i in streams:
            if isinstance(i, Exception):
                error.append(i)
            elif not exclude(stream.config, formatname(i.output,
                                                       stream.config)):
                if isinstance(i, VideoRetriever):
                    if stream.config.get("preferred"):
                        if stream.config.get("preferred").lower() == i.name:
                            videos.append(i)
                    else:
                        videos.append(i)
                if isinstance(i, subtitle):
                    subs.append(i)
    except Exception as e:
        if stream.config.get("verbose"):
            raise
        else:
            logging.error("svtplay-dl crashed")
            logging.error(
                "Run again and add --verbose as an argument, to get more information"
            )
            logging.error(
                "If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues"
            )
            logging.error(
                "Include the URL used, the stack trace and the output of svtplay-dl --version in the issue"
            )
        return

    if stream.config.get("require_subtitle") and not subs:
        logging.info("No subtitles available")
        return

    if stream.config.get("subtitle") and stream.config.get("get_url"):
        if subs:
            if stream.config.get("get_all_subtitles"):
                for sub in subs:
                    print(sub.url)
            else:
                print(subs[0].url)
        if stream.config.get("force_subtitle"):
            return

    def options_subs_dl(subfixes):
        if subs:
            if stream.config.get("get_all_subtitles"):
                for sub in subs:
                    sub.download()
                    if stream.config.get("merge_subtitle"):
                        if sub.subfix:
                            subfixes += [sub.subfix]
                        else:
                            stream.config.set("get_all_subtitles", False)
            else:
                subs[0].download()
        elif stream.config.get("merge_subtitle"):
            stream.config.set("merge_subtitle", False)

    if stream.config.get("subtitle") and not stream.config.get("get_url"):
        options_subs_dl(subfixes)
        if stream.config.get("force_subtitle"):
            return

    if stream.config.get(
            "merge_subtitle") and not stream.config.get("subtitle"):
        options_subs_dl(subfixes)

    if not videos:
        errormsg = None
        for exc in error:
            if errormsg:
                errormsg = "{}. {}".format(errormsg, str(exc))
            else:
                errormsg = str(exc)
        logging.error("No videos found. {}".format(errormsg))
    else:
        if stream.config.get("list_quality"):
            list_quality(videos)
            return
        try:
            stream = select_quality(stream.config, videos)
            if stream.config.get("get_url"):
                print(stream.url)
                return
            logging.info("Selected to download %s, bitrate: %s", stream.name,
                         stream.bitrate)
            stream.download()
        except UIException as e:
            if stream.config.get("verbose"):
                raise e
            log.error(e)
            sys.exit(2)

        if stream.config.get("thumbnail") and hasattr(stream, "get_thumbnail"):
            stream.get_thumbnail(stream.config)
        post = postprocess(stream, stream.config, subfixes)
        if stream.audio and post.detect:
            post.merge()
        if stream.audio and not post.detect and stream.finished:
            logging.warning(
                "Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds"
            )
        if stream.name == "hls" or stream.config.get("remux"):
            post.remux()
        if stream.config.get("silent_semi") and stream.finished:
            logging.log(25,
                        "Download of %s was completed" % stream.options.output)
Exemple #3
0
def get_one_media(stream, options):
    # Make an automagic filename
    if not filename(stream):
        return

    if options.merge_subtitle:
        from svtplay_dl.utils import which
        if not which('ffmpeg'):
            log.error("--merge-subtitle needs ffmpeg. Please install ffmpeg.")
            log.info("https://ffmpeg.org/download.html")
            sys.exit(2)

    videos = []
    subs = []
    subfixes = []
    error = []
    streams = stream.get()
    try:
        for i in streams:
            if isinstance(i, VideoRetriever):
                if options.preferred:
                    if options.preferred.lower() == i.name():
                        videos.append(i)
                else:
                    videos.append(i)
            if isinstance(i, subtitle):
                subs.append(i)
            if isinstance(i, Exception):
                error.append(i)
    except Exception as e:
        if options.verbose:
            raise
        else:
            log.error("svtplay-dl crashed")
            log.error("Run again and add --verbose as an argument, to get more information")
            log.error("If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues")
            log.error("Include the URL used, the stack trace and the output of svtplay-dl --version in the issue")
        sys.exit(3)

    if options.require_subtitle and not subs:
        log.info("No subtitles available")
        return

    if options.subtitle and options.get_url:
        if subs:
            if options.get_all_subtitles:
                for sub in subs:
                    print(sub.url)
            else:
                print(subs[0].url)
        if options.force_subtitle: 
            return

    def options_subs_dl(subfixes):
        if subs:
            if options.get_all_subtitles:
                for sub in subs:
                    sub.download()
                    if options.merge_subtitle:
                        if sub.subfix:
                            subfixes += [sub.subfix]
                        else:
                            options.get_all_subtitles = False
            else: 
                subs[0].download()
        elif options.merge_subtitle:
            options.merge_subtitle = False

    if options.subtitle and options.output != "-" and not options.get_url:
        options_subs_dl(subfixes)
        if options.force_subtitle:
            return

    if options.merge_subtitle and not options.subtitle:
        options_subs_dl(subfixes)

    if not videos:
        log.error("No videos found.")
        for exc in error:
            log.error(str(exc))
    else:
        if options.list_quality:
            list_quality(videos)
            return
        try:
            stream = select_quality(options, videos)
            if options.get_url:
                print(stream.url)
                return
            log.info("Selected to download %s, bitrate: %s",
                     stream.name(), stream.bitrate)
            stream.download()
        except UIException as e:
            if options.verbose:
                raise e
            log.error(e)
            sys.exit(2)

        if options.thumbnail and hasattr(stream, "get_thumbnail"):
            if options.output != "-":
                log.info("Getting thumbnail")
                stream.get_thumbnail(options)
            else:
                log.warning("Can not get thumbnail when fetching to stdout")
        post = postprocess(stream, options, subfixes)
        if stream.name() == "dash" and post.detect:
            post.merge()
        if stream.name() == "dash" and not post.detect and stream.finished:
            log.warning("Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds")
        if options.remux:
            post.remux()
        if options.silent_semi and stream.finished:
            log.log(25, "Download of %s was completed" % stream.options.output)
Exemple #4
0
def get_one_media(stream, options):
    # Make an automagic filename
    if not filename(stream):
        return

    if options.merge_subtitle:
        from svtplay_dl.utils import which
        if not which('ffmpeg'):
            log.error("--merge-subtitle needs ffmpeg. Please install ffmpeg.")
            log.info("https://ffmpeg.org/download.html")
            sys.exit(2)

    videos = []
    subs = []
    subfixes = []
    error = []
    streams = stream.get()
    try:
        for i in streams:
            if isinstance(i, VideoRetriever):
                if options.preferred:
                    if options.preferred.lower() == i.name():
                        videos.append(i)
                else:
                    videos.append(i)
            if isinstance(i, subtitle):
                subs.append(i)
            if isinstance(i, Exception):
                error.append(i)
    except Exception as e:
        if options.verbose:
            log.error("version: %s" % __version__)
            raise
        else:
            log.error("svtplay-dl crashed")
            log.error("Run again and add --verbose as an argument, to get more information")
            log.error("If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues")
            log.error("Include the URL used, the stack trace and the output of svtplay-dl --version in the issue")
        sys.exit(3)

    if options.require_subtitle and not subs:
        log.info("No subtitles available")
        return

    if options.subtitle and options.get_url:
        if subs:
            if options.get_all_subtitles:
                for sub in subs:
                    print(sub.url)
            else:
                print(subs[0].url)
        if options.force_subtitle: 
            return

    def options_subs_dl(subfixes):
        if subs:
            if options.get_all_subtitles:
                for sub in subs:
                    sub.download()
                    if options.merge_subtitle:
                        if sub.subfix:
                            subfixes += [sub.subfix]
                        else:
                            options.get_all_subtitles = False
            else: 
                subs[0].download()
        elif options.merge_subtitle:
            options.merge_subtitle = False

    if options.subtitle and options.output != "-" and not options.get_url:
        options_subs_dl(subfixes)
        if options.force_subtitle:
            return

    if options.merge_subtitle and not options.subtitle:
        options_subs_dl(subfixes)


    if len(videos) == 0:
        for exc in error:
            log.error(str(exc))
    else:
        if options.list_quality:
            list_quality(videos)
            return
        try:
            stream = select_quality(options, videos)
            if options.get_url:
                print(stream.url)
                return
            log.info("Selected to download %s, bitrate: %s",
                     stream.name(), stream.bitrate)
            stream.download()
        except UIException as e:
            if options.verbose:
                raise e
            log.error(e)
            sys.exit(2)

        if options.thumbnail and hasattr(stream, "get_thumbnail"):
            if options.output != "-":
                log.info("Getting thumbnail")
                stream.get_thumbnail(options)
            else:
                log.warning("Can not get thumbnail when fetching to stdout")
        post = postprocess(stream, options, subfixes)
        if stream.name() == "dash" and post.detect:
            post.merge()
        if stream.name() == "dash" and not post.detect and stream.finished:
            log.warning("Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds")
        if options.remux:
            post.remux()
        if options.silent_semi and stream.finished:
            log.log(25, "Download of %s was completed" % stream.options.output)
Exemple #5
0
def get_one_media(stream):
    # Make an automagic filename
    if not filename(stream):
        return

    if stream.config.get("merge_subtitle"):
        if not which('ffmpeg'):
            logging.error("--merge-subtitle needs ffmpeg. Please install ffmpeg.")
            logging.info("https://ffmpeg.org/download.html")
            sys.exit(2)

    videos = []
    subs = []
    subfixes = []
    error = []
    streams = stream.get()
    try:
        for i in streams:
            if isinstance(i, Exception):
                error.append(i)
            elif not exclude(stream.config, formatname(i.output, stream.config)):
                if isinstance(i, VideoRetriever):
                    if stream.config.get("preferred"):
                        if stream.config.get("preferred").lower() == i.name:
                            videos.append(i)
                    else:
                        videos.append(i)
                if isinstance(i, subtitle):
                    subs.append(i)
    except Exception:
        if stream.config.get("verbose"):
            raise
        else:
            logging.error("svtplay-dl crashed")
            logging.error("Run again and add --verbose as an argument, to get more information")
            logging.error("If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues")
            logging.error("Include the URL used, the stack trace and the output of svtplay-dl --version in the issue")
        return

    try:
        after_date = datetime.strptime(stream.config.get("after_date"), "%Y-%m-%d")
    except (ValueError, TypeError, KeyError, AttributeError):  # gotta catch em all..
        after_date = None
    try:
        pub_date = datetime.fromtimestamp(stream.output["publishing_datetime"])
    except (ValueError, TypeError, KeyError):
        pub_date = None
    if after_date is not None and pub_date is not None and pub_date.date() < after_date.date():
        logging.info("Video {}S{}E{} skipped since published {} before {}. ".format(
            stream.output["title"],
            stream.output["season"],
            stream.output["episode"],
            pub_date.date(),
            after_date.date()))
        return

    if stream.config.get("require_subtitle") and not subs:
        logging.info("No subtitles available")
        return

    if stream.config.get("subtitle") and stream.config.get("get_url"):
        if subs:
            if stream.config.get("get_all_subtitles"):
                for sub in subs:
                    print(sub.url)
            else:
                print(subs[0].url)
        if stream.config.get("force_subtitle"):
            return

    def options_subs_dl(subfixes):
        if subs:
            if stream.config.get("get_all_subtitles"):
                for sub in subs:
                    sub.download()
                    if stream.config.get("merge_subtitle"):
                        if sub.subfix:
                            subfixes += [sub.subfix]
                        else:
                            stream.config.set("get_all_subtitles", False)
            else:
                subs[0].download()
        elif stream.config.get("merge_subtitle"):
            stream.config.set("merge_subtitle", False)

    if stream.config.get("subtitle") and not stream.config.get("get_url"):
        options_subs_dl(subfixes)
        if stream.config.get("force_subtitle"):
            return

    if stream.config.get("merge_subtitle") and not stream.config.get("subtitle"):
        options_subs_dl(subfixes)
    if not videos:
        errormsg = None
        for exc in error:
            if errormsg:
                errormsg = "{}. {}".format(errormsg, str(exc))
            else:
                errormsg = str(exc)
        if errormsg:
            logging.error("No videos found. {}".format(errormsg))
        else:
            logging.error("No videos found.")
    else:
        if stream.config.get("list_quality"):
            list_quality(videos)
            return
        if stream.config.get("nfo"):
            # Create NFO files
            write_nfo_episode(stream.output, stream.config)
            write_nfo_tvshow(stream.output, stream.config)
            if stream.config.get("force_nfo"):
                return
        try:
            fstream = select_quality(stream.config, videos)
            if fstream.config.get("get_url"):
                print(fstream.url)
                return
            logging.info("Selected to download %s, bitrate: %s", fstream.name, fstream.bitrate)
            fstream.download()
        except UIException as e:
            if fstream.config.get("verbose"):
                raise e
            logging.error(e)
            sys.exit(2)

        if fstream.config.get("thumbnail") and hasattr(stream, "get_thumbnail"):
            stream.get_thumbnail(stream.config)

        post = postprocess(fstream, fstream.config, subfixes)
        if fstream.audio and post.detect:
            post.merge()
        if fstream.audio and not post.detect and fstream.finished:
            logging.warning("Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds")
        if fstream.name == "hls" or fstream.config.get("remux"):
            post.remux()
        if fstream.config.get("silent_semi") and fstream.finished:
            logging.log(25, "Download of %s was completed" % fstream.options.output)
Exemple #6
0
def get_one_media(stream, options):
    # Make an automagic filename
    if not filename(stream):
        return

    videos = []
    subs = []
    error = []
    streams = stream.get()
    try:
        for i in streams:
            if isinstance(i, VideoRetriever):
                if options.preferred:
                    if options.preferred.lower() == i.name():
                        videos.append(i)
                else:
                    videos.append(i)
            if isinstance(i, subtitle):
                subs.append(i)
            if isinstance(i, Exception):
                error.append(i)
    except Exception as e:
        if options.verbose:
            raise
        else:
            log.error("svtplay-dl crashed")
            log.error("Run again and add --verbose as an argument, to get more information")
            log.error("If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues")
            log.error("Include the URL used, the stack trace and the output of svtplay-dl --version in the issue")
        sys.exit(3)

    if options.require_subtitle and not subs:
        log.info("No subtitles available")
        return

    if options.subtitle and options.output != "-":
        if subs:
            subs[0].download()
        if options.force_subtitle:
            return

    if len(videos) == 0:
        for exc in error:
            log.error(str(exc))
    else:
        if options.list_quality:
            list_quality(videos)
            return
        stream = select_quality(options, videos)
        log.info("Selected to download %s, bitrate: %s",
                 stream.name(), stream.bitrate)
        if options.get_url:
            print(stream.url)
            return
        try:
            stream.download()
        except UIException as e:
            if options.verbose:
                raise e
            log.error(e)
            sys.exit(2)

        if options.thumbnail and hasattr(stream, "get_thumbnail"):
            if options.output != "-":
                log.info("Getting thumbnail")
                stream.get_thumbnail(options)
            else:
                log.warning("Can not get thumbnail when fetching to stdout")
        post = postprocess(stream)
        if stream.name() == "dash" and post.detect:
            post.merge()
        if stream.name() == "dash" and not post.detect and stream.finished:
            log.warning("Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds")
        if options.remux:
            post.remux()