本文整理汇总了Python中svtplay_dl.log.log.info函数的典型用法代码示例。如果您正苦于以下问题:Python info函数的具体用法?Python info怎么用?Python info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_media
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)
示例2: output
def output(options, extension="mp4", openfd=True, mode="wb", **kwargs):
subtitlefiles = ["srt", "smi", "tt","sami", "wrst"]
ext = re.search(r"(\.\w{2,4})$", options.output)
if not ext:
options.output = "%s.%s" % (options.output, extension)
if options.output_auto and ext:
options.output = "%s.%s" % (options.output, extension)
elif extension == "srt" and ext:
options.output = "%s.srt" % options.output[:options.output.rfind(ext.group(1))]
if ext and extension == "srt" and ext.group(1).split(".")[-1] in subtitlefiles:
options.output = "%s.srt" % options.output[:options.output.rfind(ext.group(1))]
log.info("Outfile: %s", options.output)
if os.path.isfile(options.output) or \
findexpisode(os.path.dirname(os.path.realpath(options.output)), options.service, os.path.basename(options.output)):
if extension in subtitlefiles:
if not options.force_subtitle:
log.error("File (%s) already exists. Use --force-subtitle to overwrite" % options.output)
return None
else:
if not options.force:
log.error("File (%s) already exists. Use --force to overwrite" % options.output)
return None
if openfd:
file_d = open(options.output, mode, **kwargs)
return file_d
return True
示例3: remux
def remux(self):
if self.detect is None:
log.error("Cant detect ffmpeg or avconv. Cant mux files without it.")
return
if self.stream.finished is False:
return
if self.stream.options.output.endswith('.mp4') is False:
orig_filename = self.stream.options.output
new_name = "{0}.mp4".format(os.path.splitext(self.stream.options.output)[0])
log.info("Muxing %s into %s", orig_filename, new_name)
tempfile = "{0}.temp".format(self.stream.options.output)
name, ext = os.path.splitext(orig_filename)
arguments = ["-c", "copy", "-copyts", "-f", "mp4"]
if ext == ".ts":
arguments += ["-bsf:a", "aac_adtstoasc"]
arguments += ["-y", tempfile]
cmd = [self.detect, "-i", orig_filename]
cmd += arguments
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
stderr = stderr.decode('utf-8', 'replace')
msg = stderr.strip().split('\n')[-1]
log.error("Something went wrong: %s", msg)
return
log.info("Muxing done, removing the old file.")
os.remove(self.stream.options.output)
os.rename(tempfile, new_name)
示例4: merge
def merge(self):
if self.detect is None:
log.error("Cant detect ffmpeg or avconv. Cant mux files without it.")
return
if self.stream.finished is False:
return
orig_filename = self.stream.options.output
log.info("Merge audio and video into %s", orig_filename)
tempfile = "{0}.temp".format(self.stream.options.output)
audio_filename = "{0}.m4a".format(os.path.splitext(self.stream.options.output)[0])
arguments = ["-c:v", "copy", "-c:a", "copy", "-f", "mp4", "-y", tempfile]
cmd = [self.detect, "-i", orig_filename, "-i", audio_filename]
cmd += arguments
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
stderr = stderr.decode('utf-8', 'replace')
msg = stderr.strip().split('\n')[-1]
log.error("Something went wrong: %s", msg)
return
log.info("Merging done, removing old files.")
os.remove(self.stream.options.output)
os.remove(audio_filename)
os.rename(tempfile, self.stream.options.output)
示例5: output
def output(options, extention="mp4", openfd=True, mode="wb", **kwargs):
if is_py2:
file_d = file
else:
file_d = io.IOBase
if options.output != "-":
ext = re.search(r"(\.\w{2,3})$", options.output)
if not ext:
options.output = "%s.%s" % (options.output, extention)
if options.output_auto and ext:
options.output = "%s.%s" % (options.output, extention)
if extention == "srt" and ext:
options.output = "%s.srt" % options.output[:options.output.rfind(ext.group(1))]
log.info("Outfile: %s", options.output)
if os.path.isfile(options.output) or \
findexpisode(os.path.dirname(os.path.realpath(options.output)), options.service, os.path.basename(options.output)):
if extention == "srt":
if not options.force_subtitle:
log.error("File (%s) already exists. Use --force-subtitle to overwrite" % options.output)
return None
else:
if not options.force:
log.error("File (%s) already exists. Use --force to overwrite" % options.output)
return None
if openfd:
file_d = open(options.output, mode, **kwargs)
else:
if openfd:
if is_py2:
file_d = sys.stdout
else:
file_d = sys.stdout.buffer
return file_d
示例6: get_all_episodes
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))
示例7: download_rtmp
def download_rtmp(options, url):
""" Get the stream from RTMP """
args = []
if options.live:
args.append("-v")
if options.resume:
args.append("-e")
extension = re.search("(\.[a-z0-9]+)$", url)
if options.output != "-":
if not extension:
extension = re.search("-y (.+):[-_a-z0-9\/]", options.other)
if not extension:
options.output = "%s.flv" % options.output
else:
options.output = "%s.%s" % (options.output, extension.group(1))
else:
options.output = options.output + extension.group(1)
log.info("Outfile: %s", options.output)
args += ["-o", options.output]
if options.silent or options.output == "-":
args.append("-q")
if options.other:
if sys.version_info < (3, 0):
args += shlex.split(options.other.encode("utf-8"))
else:
args += shlex.split(options.other)
command = ["rtmpdump", "-r", url] + args
try:
subprocess.call(command)
except OSError as e:
log.error("Could not execute rtmpdump: " + e.strerror)
示例8: output
def output(options, filename, extention="mp4", openfd=True):
if is_py3:
file_d = io.IOBase
else:
file_d = file
if options.output != "-":
ext = re.search(r"(\.[a-z0-9]+)$", filename)
if not ext:
options.output = "%s.%s" % (options.output, extention)
log.info("Outfile: %s", options.output)
if (os.path.isfile(options.output) or \
findexpisode(os.path.dirname(os.path.realpath(options.output)), options.service, os.path.basename(options.output))) and \
not options.force:
log.error("File already exists. Use --force to overwrite")
return None
if openfd:
file_d = open(options.output, "wb")
else:
if openfd:
if is_py3:
file_d = sys.stdout.buffer
else:
file_d = sys.stdout
return file_d
示例9: get_one_media
def get_one_media(stream, options):
if not options.output or os.path.isdir(options.output):
data = stream.get_urldata()
match = re.search(r"(?i)<title[^>]*>\s*(.*?)\s*</title>", data, re.S)
if match:
options.output_auto = True
title_tag = decode_html_entities(match.group(1))
if not options.output:
options.output = filenamify(title_tag)
else:
# output is a directory
options.output = os.path.join(options.output, filenamify(title_tag))
if platform.system() == "Windows":
# ugly hack. replace \ with / or add extra \ because c:\test\kalle.flv will add c:_tab_est\kalle.flv
if options.output.find("\\") > 0:
options.output = options.output.replace("\\", "/")
videos = []
subs = []
streams = stream.get(options)
for i in streams:
if isinstance(i, VideoRetriever):
if options.preferred:
if options.preferred == i.name():
videos.append(i)
else:
videos.append(i)
if isinstance(i, subtitle):
subs.append(i)
if options.subtitle and options.output != "-":
if subs:
subs[0].download(copy.copy(options))
if options.force_subtitle:
return
if len(videos) == 0:
log.error("Can't find any streams for that url")
else:
stream = select_quality(options, videos)
log.info("Selected to download %s, bitrate: %s",
stream.name(), stream.bitrate)
try:
stream.download()
except UIException as e:
if options.verbose:
raise e
log.error(e.message)
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")
示例10: download
def download(self):
if self.options.live and not self.options.force:
raise LiveHLSException(self.url)
m3u8 = get_http_data(self.url)
globaldata, files = parsem3u(m3u8)
encrypted = False
key = None
try:
keydata = globaldata["KEY"]
encrypted = True
except KeyError:
pass
if encrypted:
try:
from Crypto.Cipher import AES
except ImportError:
log.error("You need to install pycrypto to download encrypted HLS streams")
sys.exit(2)
match = re.search(r'URI="(https?://.*?)"', keydata)
key = get_http_data(match.group(1))
rand = os.urandom(16)
decryptor = AES.new(key, AES.MODE_CBC, rand)
if self.options.output != "-":
extension = re.search(r"(\.[a-z0-9]+)$", self.options.output)
if not extension:
self.options.output = "%s.ts" % self.options.output
log.info("Outfile: %s", self.options.output)
if os.path.isfile(self.options.output) and not self.options.force:
log.info("File already exists. use --force to overwrite")
return
file_d = open(self.options.output, "wb")
else:
file_d = sys.stdout
n = 0
eta = ETA(len(files))
for i in files:
item = _get_full_url(i[0], self.url)
if self.options.output != "-":
eta.increment()
progressbar(len(files), n, ''.join(['ETA: ', str(eta)]))
n += 1
data = get_http_data(item)
if encrypted:
data = decryptor.decrypt(data)
file_d.write(data)
if self.options.output != "-":
file_d.close()
progress_stream.write('\n')
示例11: save
def save(options, data):
filename = re.search(r"(.*)\.[a-z0-9]{2,3}$", options.output)
if filename:
options.output = "%s.srt" % filename.group(1)
else:
options.output = "%s.srt" % options.output
log.info("Subtitle: %s", options.output)
fd = open(options.output, "w")
fd.write(data)
fd.close()
示例12: get_one_media
def get_one_media(stream, options):
# Make an automagic filename
if not filename(options, stream):
return
videos = []
subs = []
streams = stream.get(options)
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 options.subtitle and options.output != "-":
if subs:
subs[0].download()
if options.force_subtitle:
return
if len(videos) == 0:
log.error("Can't find any streams for that url")
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.message)
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")
示例13: save
def save(options, data):
filename = re.search(r"(.*)\.[a-z0-9]{2,3}$", options.output)
if filename:
options.output = "%s.srt" % filename.group(1)
else:
options.output = "%s.srt" % options.output
log.info("Subtitle: %s", options.output)
if os.path.isfile(options.output) and not options.force:
log.info("File already exists. use --force to overwrite")
return
fd = open(options.output, "w")
fd.write(data)
fd.close()
示例14: remux
def remux(self):
if self.detect is None:
log.error("Cant detect ffmpeg or avconv. Cant mux files without it.")
return
if self.stream.finished is False:
return
if formatname(self.stream.output, self.config, self.stream.output_extention).endswith('.mp4') is False:
orig_filename = formatname(self.stream.output, self.config, self.stream.output_extention)
name, ext = os.path.splitext(orig_filename)
new_name = u"{0}.mp4".format(name)
cmd = [self.detect, "-i", orig_filename]
_, stdout, stderr = run_program(cmd, False) # return 1 is good here.
videotrack, audiotrack = self._checktracks(stderr)
if self.config.get("merge_subtitle"):
log.info(u"Muxing {0} and merging its subtitle into {1}".format(orig_filename, new_name))
else:
log.info(u"Muxing {0} into {1}".format(orig_filename, new_name))
tempfile = u"{0}.temp".format(orig_filename)
arguments = ["-map", "0:{}".format(videotrack), "-map", "0:{}".format(audiotrack), "-c", "copy", "-f", "mp4"]
if ext == ".ts":
arguments += ["-bsf:a", "aac_adtstoasc"]
if self.config.get("merge_subtitle"):
langs = self.sublanguage()
for stream_num, language in enumerate(langs):
arguments += ["-map", str(stream_num + 1), "-c:s:" + str(stream_num), "mov_text",
"-metadata:s:s:" + str(stream_num), "language=" + language]
if self.subfixes and len(self.subfixes) >= 2:
for subfix in self.subfixes:
subfile = "{0}.srt".format(name + subfix)
cmd += ["-i", subfile]
else:
subfile = "{0}.srt".format(name)
cmd += ["-i", subfile]
arguments += ["-y", tempfile]
cmd += arguments
returncode, stdout, stderr = run_program(cmd)
if returncode != 0:
return
if self.config.get("merge_subtitle") and not self.config.get("subtitle"):
log.info("Muxing done, removing the old files.")
if self.subfixes and len(self.subfixes) >= 2:
for subfix in self.subfixes:
subfile = "{0}.srt".format(name + subfix)
os.remove(subfile)
else:
os.remove(subfile)
else:
log.info("Muxing done, removing the old file.")
os.remove(orig_filename)
os.rename(tempfile, new_name)
示例15: download
def download(self):
""" Get the stream from HTTP """
request = Request(self.url)
request.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
try:
response = urlopen(request)
except HTTPError as e:
log.error("Something wrong with that url")
log.error("Error code: %s", e.code)
sys.exit(5)
try:
total_size = response.info()['Content-Length']
except KeyError:
total_size = 0
total_size = int(total_size)
bytes_so_far = 0
if self.options.output != "-":
extension = re.search(r"(\.[a-z0-9]+)$", self.url)
if extension:
self.options.output = self.options.output + extension.group(1)
else:
self.options.output = "%s.mp4" % self.options.output
log.info("Outfile: %s", self.options.output)
if os.path.isfile(self.options.output) and not self.options.force:
log.info("File already exists. use --force to overwrite")
return
file_d = open(self.options.output, "wb")
else:
file_d = sys.stdout
lastprogress = 0
while 1:
chunk = response.read(8192)
bytes_so_far += len(chunk)
if not chunk:
break
file_d.write(chunk)
if self.options.output != "-":
now = time.time()
if lastprogress + 1 < now:
lastprogress = now
progress(bytes_so_far, total_size)
if self.options.output != "-":
file_d.close()