|
@@ -0,0 +1,117 @@
|
|
|
+Line # Mem usage Increment Line Contents
|
|
|
+================================================
|
|
|
+ 38 22.059 MiB 22.059 MiB @profile
|
|
|
+ 39 def play_init(group_id,sourceInfoId):
|
|
|
+ 40 22.059 MiB 0.000 MiB silent = "/PA-System/pa-api/media/silent.mp3"
|
|
|
+ 41 22.059 MiB 0.000 MiB i = 0
|
|
|
+ 42 22.059 MiB 0.000 MiB popen = 0
|
|
|
+ 43 22.059 MiB 0.000 MiB castInfo = {}
|
|
|
+ 44
|
|
|
+ 45 22.059 MiB 0.000 MiB s = shout.Shout()
|
|
|
+ 46 22.059 MiB 0.000 MiB print("Using libshout version %s" % shout.version())
|
|
|
+ 47 22.059 MiB 0.000 MiB s.host = gl.config['host']
|
|
|
+ 48 22.059 MiB 0.000 MiB s.port = int(gl.config['port'])
|
|
|
+ 49 22.059 MiB 0.000 MiB s.user = 'admin'
|
|
|
+ 50 22.059 MiB 0.000 MiB s.password = gl.config['secret']
|
|
|
+ 51 22.059 MiB 0.000 MiB s.mount = group_id
|
|
|
+ 52 22.059 MiB 0.000 MiB s.format = 'mp3'
|
|
|
+ 53 22.059 MiB 0.000 MiB s.protocol = 'http'
|
|
|
+ 54 22.059 MiB 0.000 MiB s.public = 0
|
|
|
+ 55 # s.format = 'vorbis' | 'mp3'
|
|
|
+ 56 # s.protocol = 'http' | 'xaudiocast' | 'icy'
|
|
|
+ 57 22.059 MiB 0.000 MiB s.name = ''
|
|
|
+ 58 22.059 MiB 0.000 MiB s.genre = ''
|
|
|
+ 59 22.059 MiB 0.000 MiB s.url = ''
|
|
|
+ 60 22.059 MiB 0.000 MiB s.SHOUT_AI_CHANNELS = gl.config['channels']
|
|
|
+ 61 22.059 MiB 0.000 MiB s.SHOUT_AI_BITRATE = gl.config['bitrate']
|
|
|
+ 62 22.059 MiB 0.000 MiB s.SHOUT_AI_SAMPLERATE = gl.config['samplerate']
|
|
|
+ 63 # s.public = 0 | 1
|
|
|
+ 64 # s.audio_info = { 'key': 'val', ... }
|
|
|
+ 65 # (keys are shout.SHOUT_AI_BITRATE, shout.SHOUT_AI_SAMPLERATE,
|
|
|
+ 66 # shout.SHOUT_AI_CHANNELS, shout.SHOUT_AI_QUALITY)
|
|
|
+ 67 22.059 MiB 0.000 MiB try:
|
|
|
+ 68 22.059 MiB 0.000 MiB s.open()
|
|
|
+ 69 except:
|
|
|
+ 70 print("open shout failed!")
|
|
|
+ 71 redisdb.delete(sourceInfoId)
|
|
|
+ 72 return False
|
|
|
+ 73 22.059 MiB 0.000 MiB while True:
|
|
|
+ 74 301.402 MiB 0.000 MiB if gl.groupstatus[group_id]['stop']:
|
|
|
+ 75 break
|
|
|
+ 76 301.402 MiB 0.254 MiB sourceInfo = getPlayInfo(sourceInfoId)
|
|
|
+ 77 301.402 MiB 0.000 MiB if(sourceInfo == None):
|
|
|
+ 78 break
|
|
|
+ 79 301.402 MiB 0.000 MiB playlist = sourceInfo["musicLibraries"]
|
|
|
+ 80 301.402 MiB 0.000 MiB listLen = len(playlist)
|
|
|
+ 81 301.402 MiB 0.000 MiB if(listLen == 0):
|
|
|
+ 82 break
|
|
|
+ 83 301.402 MiB 0.000 MiB if(gl.groupstatus[group_id]['select']):
|
|
|
+ 84 249.539 MiB 0.000 MiB i = gl.groupstatus[group_id]['playid']
|
|
|
+ 85 else:
|
|
|
+ 86 301.402 MiB 0.000 MiB if(sourceInfo["model"] == "once"):
|
|
|
+ 87 i = once
|
|
|
+ 88 301.402 MiB 0.000 MiB elif(sourceInfo["model"] == "random"):
|
|
|
+ 89 301.402 MiB 0.000 MiB i = random.randint(0, listLen - 1)
|
|
|
+ 90 301.402 MiB 0.000 MiB if (i >= listLen or i < 0):
|
|
|
+ 91 i = 0
|
|
|
+ 92 301.402 MiB 0.000 MiB once = i
|
|
|
+ 93 301.402 MiB 0.000 MiB playMusic = playlist[i]
|
|
|
+ 94 301.402 MiB 0.000 MiB name = playMusic['name']
|
|
|
+ 95 301.402 MiB 0.000 MiB fa = playMusic['path']
|
|
|
+ 96 301.402 MiB 0.000 MiB print("play music name: %s,music id: %d" % (name,i))
|
|
|
+ 97 301.402 MiB 0.000 MiB sourceInfo['musicId'] = i
|
|
|
+ 98 301.402 MiB 0.250 MiB updatePlayInfo(sourceInfoId,sourceInfo)
|
|
|
+ 99 301.402 MiB 0.000 MiB castInfo['action'] = "update"
|
|
|
+ 100 301.402 MiB 0.000 MiB castInfo['sourceId'] = sourceInfoId
|
|
|
+ 101 301.402 MiB 0.000 MiB sendCastInfo(castInfo)
|
|
|
+ 102 #fa = filelist[i]
|
|
|
+ 103 301.402 MiB 0.000 MiB try:
|
|
|
+ 104 301.402 MiB 0.000 MiB f = open(fa, 'rb')
|
|
|
+ 105 301.402 MiB 0.000 MiB gl.groupstatus[group_id] = {"stop":0,"next":0,"previous":0,"pause":0,"select":0,"playid":None}
|
|
|
+ 106 301.402 MiB 0.000 MiB print("opening file %s" % fa)
|
|
|
+ 107 except:
|
|
|
+ 108 i += 1
|
|
|
+ 109 time.sleep(2)
|
|
|
+ 110 continue
|
|
|
+ 111
|
|
|
+ 112 301.402 MiB 0.000 MiB s.set_metadata({'song': name})
|
|
|
+ 113 301.402 MiB 0.000 MiB status = "start"
|
|
|
+ 114 #nbuf = f.read(4096)
|
|
|
+ 115 301.402 MiB 0.000 MiB while True:
|
|
|
+ 116 301.898 MiB 0.246 MiB buf = f.read(4096)
|
|
|
+ 117 #buf = nbuf
|
|
|
+ 118 301.898 MiB 0.250 MiB if len(buf) == 0 or gl.groupstatus[group_id]['stop'] or gl.groupstatus[group_id]['next'] or gl.groupstatus[group_id]['previous'] or gl.groupstatus[group_id]['select']:
|
|
|
+ 119 301.402 MiB 0.000 MiB break
|
|
|
+ 120 301.898 MiB 0.004 MiB if gl.groupstatus[group_id]['pause']:
|
|
|
+ 121 if (popen == 0):
|
|
|
+ 122 sourceInfo['pause'] = 1
|
|
|
+ 123 updatePlayInfo(sourceInfoId,sourceInfo)
|
|
|
+ 124 print("opening file %s" % silent)
|
|
|
+ 125 p = open(silent, 'rb')
|
|
|
+ 126 popen = 1
|
|
|
+ 127 pbuf = p.read(4096)
|
|
|
+ 128 s.send(pbuf)
|
|
|
+ 129 s.sync()
|
|
|
+ 130 continue
|
|
|
+ 131 301.898 MiB 0.004 MiB if popen:
|
|
|
+ 132 sourceInfo['pause'] = 0
|
|
|
+ 133 updatePlayInfo(sourceInfoId,sourceInfo)
|
|
|
+ 134 p.close()
|
|
|
+ 135 popen = 0
|
|
|
+ 136 301.898 MiB 0.250 MiB s.send(buf)
|
|
|
+ 137 301.898 MiB 0.281 MiB s.sync()
|
|
|
+ 138 301.402 MiB 0.000 MiB f.close()
|
|
|
+ 139 301.402 MiB 0.000 MiB if gl.groupstatus[group_id]['stop']:
|
|
|
+ 140 break
|
|
|
+ 141 301.402 MiB 0.000 MiB if gl.groupstatus[group_id]['select']:
|
|
|
+ 142 249.539 MiB 0.000 MiB continue
|
|
|
+ 143 301.402 MiB 0.000 MiB if gl.groupstatus[group_id]['previous']:
|
|
|
+ 144 if (i == 0):
|
|
|
+ 145 i = 0
|
|
|
+ 146 else:
|
|
|
+ 147 i -= 1
|
|
|
+ 148 continue
|
|
|
+ 149 else:
|
|
|
+ 150 301.402 MiB 0.000 MiB i += 1
|
|
|
+ 151 s.close()
|
|
|
+ 152 redisdb.delete(sourceInfoId)
|