本文整理汇总了Python中lib.util.Util.shellescape方法的典型用法代码示例。如果您正苦于以下问题:Python Util.shellescape方法的具体用法?Python Util.shellescape怎么用?Python Util.shellescape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.util.Util
的用法示例。
在下文中一共展示了Util.shellescape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ripper
# 需要导入模块: from lib.util import Util [as 别名]
# 或者: from lib.util.Util import shellescape [as 别名]
#.........这里部分代码省略.........
sample_type, # currently this is always 0, which means 16-bit
# signed native endian integer samples
sample_rate, # audio sample rate, in samples per second
channels): # number of audio channels, currently 1 or 2
self._downloaded += float(frame_size) * float(num_frames)
if self._ripping:
# 320 kilobits per second
# 40 kilobytes per second
# duration in milliseconds
# 40 bytes per millisecond
total_bytes = float(self._duration) * 40.0
# 100 = 4.41 (don't ask me why)
progress_perc = self._downloaded / total_bytes
progress_perc = progress_perc * (100.0 / 4.41)
progress.bar(range(100))
sys.stdout.write('\r > Progress: %.2f%%' % progress_perc)
try:
self._pipe.write(frames);
except IOError:
os.kill(os.getpid(), 9)
def rip_id3(self, session, track): # write ID3 data
mp3_path = self._util.get_mp3_path(track)
if self._json_queue.is_starred_track():
album = 'Spotify Starred'
else:
album = track.album().name()
disc = track.disc()
number = track.index()
title = track.name()
year = track.album().year()
artist = track.album().artist().name()
performers = ''
for performer in track.artists():
performers += performer.name()+', '
performers = performers.strip().rstrip(',')
if not self._json_queue.is_starred_track():
# download cover
image = session.image_create(track.album().cover())
while not image.is_loaded():
time.sleep(0.1)
with open('cover.jpg', 'wb') as fp:
fp.write(image.data())
# write id3 data
cmd = 'eyeD3'+\
' --title ' +self._util.shellescape(title)+\
' --artist ' +self._util.shellescape(performers)+\
' --album ' +self._util.shellescape(album)
if not self._json_queue.is_starred_track():
cmd = cmd\
+' --track ' +str(number) \
+' --disc-num ' +str(disc) \
+' --release-year ' +str(year) \
+' --recording-date ' +str(year) \
+' --add-image cover.jpg:FRONT_COVER' \
+' --text-frame TPE2:'+self._util.shellescape(artist)
else:
cmd = cmd+ \
' --text-frame TPE2:' \
+self._util.shellescape('Various Artists')
cmd = cmd+' temp.mp3 &>/dev/null'
print ''
with indent(3, quote = colored.cyan(' # ')):
try:
puts('Executing %s' % cmd)
except UnicodeEncodeError:
sys.stdout.write(' # Executing %s\n' % cmd)
self._util.shell(cmd)
try:
puts('Moving %s to %s' % ('temp.mp3', mp3_path))
except UnicodeEncodeError:
sys.stdout.write(' # Moving %s to %s\n' \
% ('temp.mp3', mp3_path))
# move mp3 to final directory
cmd = 'mv temp.mp3 %s' % mp3_path
self._util.shell(cmd)
# delete cover
if not self._json_queue.is_starred_track():
self._util.shell("rm -f cover.jpg")
self._json_queue.mark_as_downloaded(Link.from_track(track))