tag:blogger.com,1999:blog-17131334.post-1154343864929145262006-07-31T13:20:00.000+03:002006-07-31T19:21:27.066+03:00Мои скрипты: renbycue.py<span style="font-weight: bold;">Разрежем большой MP3, протегируем малые по CUE-файлу</span>.<br />Скачал я альбом с помощью осла - <a href="ed2k://%7Cfile%7CVA_-_Safi_Connection_The_Remixes-2006-UPE.rar%7C123212337%7C6A07AD217D605782B1621471564A3D0A%7C/">VA_-_Safi_Connection_The_Remixes</a><br />А он весь одним большим mp3 (118Mb), решил порезать, благо прилагался cue-файл следующего содержания:<br /><pre><br />PERFORMER <span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 230);">VA</span><span style="color: rgb(128, 0, 0);">"</span><br />TITLE <span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 230);">Safi Connection The Remixes</span><span style="color: rgb(128, 0, 0);">"</span><br />FILE <span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 230);">01-va_-_safi_connection_the_remixes-upe.mp3</span><span style="color: rgb(128, 0, 0);">"</span> MP3<br />TRACK <span style="color: rgb(0, 140, 0);">01</span> AUDIO<br />TITLE <span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 230);">Hello Houston Spiritual Enhancer Rmx</span><span style="color: rgb(128, 0, 0);">"</span><br />PERFORMER <span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 230);">Safi Connection</span><span style="color: rgb(128, 0, 0);">"</span><br />FLAGS DCP<br />INDEX <span style="color: rgb(0, 140, 0);">01</span> <span style="color: rgb(135, 69, 160);">00:00:00</span><br /><br /><span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span><br /><br />TRACK <span style="color: rgb(0, 140, 0);">10</span> AUDIO<br />TITLE <span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 230);">Fullon String Elec 3 Rmx</span><span style="color: rgb(128, 0, 0);">"</span><br />PERFORMER <span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 230);">Safi Connection</span><span style="color: rgb(128, 0, 0);">"</span><br />FLAGS DCP<br />INDEX <span style="color: rgb(0, 140, 0);">00</span> <span style="color: rgb(0, 140, 0);">67</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(135, 69, 160);">05:01</span><br />INDEX <span style="color: rgb(0, 140, 0);">01</span> <span style="color: rgb(0, 140, 0);">67</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(135, 69, 160);">07:01</span><br /></pre><br /><br />Дядька Curt сказал что нарезает в <a href="http://www.steinberg.net/">WaveLab</a> , я и последовал его рекомендации. Нашел этот инструмент на <a href="http://wzor.net/modules.php?name=News&file=article&amp;sid=3791">Wzor</a>'е и у <a href="http://fixdown.com/soft/7850.asp">китайцев</a>.<br />Для упрощения "нарезки", написал следующий сценарий на <a href="http://python.ru">python</a>:<br /><pre><br /><span style="color: rgb(0, 0, 230);">"cue info - print info from *.cue"</span><br /><br /><span style="color: rgb(105, 105, 105);">#cuei.py</span><br /><span style="color: rgb(105, 105, 105);">#rev. 0.2<br /></span><span style="color: rgb(105, 105, 105);">#dron@amerigo 200607311244</span><br /><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">import</span> sys<br /><span style="color: rgb(128, 0, 0); font-weight: bold;">from</span> datetime <span style="color: rgb(128, 0, 0); font-weight: bold;">import</span> timedelta<br /><span style="color: rgb(128, 0, 0); font-weight: bold;">from</span> ID3 <span style="color: rgb(128, 0, 0); font-weight: bold;">import</span> <span style="color: rgb(128, 128, 48);">*</span><br /><br />all <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(227, 74, 220);">open</span><span style="color: rgb(128, 128, 48);">(</span>sys<span style="color: rgb(128, 128, 48);">.</span>argv<span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>read<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><br />tracks <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(128, 128, 48);">[</span>el<span style="color: rgb(128, 128, 48);">.</span>split<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"\n"</span><span style="color: rgb(128, 128, 48);">)</span> <span style="color: rgb(128, 0, 0); font-weight: bold;">for</span> el <span style="color: rgb(128, 0, 0); font-weight: bold;">in</span> all<span style="color: rgb(128, 128, 48);">.</span>split<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"TRACK"</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">]</span><br />label <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">0</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">0</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>replace<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"PERFORMER"</span><span style="color: rgb(128, 128, 48);">,</span><span style="color: rgb(0, 0, 230);">""</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><br />album <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">0</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>replace<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"TITLE"</span><span style="color: rgb(128, 128, 48);">,</span><span style="color: rgb(0, 0, 230);">""</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><br /><br />starts <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(128, 128, 48);">]</span><br />tracklist <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(128, 128, 48);">]</span><br /><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">for</span> i <span style="color: rgb(128, 0, 0); font-weight: bold;">in</span> <span style="color: rgb(227, 74, 220);">range</span><span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">,</span> <span style="color: rgb(227, 74, 220);">len</span><span style="color: rgb(128, 128, 48);">(</span>tracks<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">:</span><br />title <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>replace<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"TITLE"</span><span style="color: rgb(128, 128, 48);">,</span><span style="color: rgb(0, 0, 230);">""</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><br />artist <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">2</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>replace<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"PERFORMER"</span><span style="color: rgb(128, 128, 48);">,</span><span style="color: rgb(0, 0, 230);">""</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">if</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">3</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>startswith<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"FLAGS"</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">:</span><br /> startfrom <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">4</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">8</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">]</span><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">else</span><span style="color: rgb(128, 128, 48);">:</span><br /> startfrom <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">3</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">8</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">]</span><br /><br /><span style="color: rgb(128, 128, 48);">(</span>h<span style="color: rgb(128, 128, 48);">,</span>m<span style="color: rgb(128, 128, 48);">,</span>s<span style="color: rgb(128, 128, 48);">)</span> <span style="color: rgb(128, 128, 48);">=</span> startfrom<span style="color: rgb(128, 128, 48);">.</span>split<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">":"</span><span style="color: rgb(128, 128, 48);">)</span><br />t <span style="color: rgb(128, 128, 48);">=</span> timedelta<span style="color: rgb(128, 128, 48);">(</span><br /> hours<span style="color: rgb(128, 128, 48);">=</span><span style="color: rgb(227, 74, 220);">int</span><span style="color: rgb(128, 128, 48);">(</span>h<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">,</span><br /> minutes<span style="color: rgb(128, 128, 48);">=</span><span style="color: rgb(227, 74, 220);">int</span><span style="color: rgb(128, 128, 48);">(</span>m<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">,</span><br /> seconds<span style="color: rgb(128, 128, 48);">=</span><span style="color: rgb(227, 74, 220);">int</span><span style="color: rgb(128, 128, 48);">(</span>s<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><br /><br />starts<span style="color: rgb(128, 128, 48);">.</span>append<span style="color: rgb(128, 128, 48);">(</span>t<span style="color: rgb(128, 128, 48);">)</span><br />tracklist<span style="color: rgb(128, 128, 48);">.</span>append<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"%d: %s - %s, from: %s,"</span> <span style="color: rgb(128, 128, 48);">%</span><br /> <span style="color: rgb(128, 128, 48);">(</span>i<span style="color: rgb(128, 128, 48);">,</span> artist<span style="color: rgb(128, 128, 48);">,</span> title<span style="color: rgb(128, 128, 48);">,</span> startfrom<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><br /><br />lengths <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(128, 128, 48);">]</span><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">for</span> i <span style="color: rgb(128, 0, 0); font-weight: bold;">in</span> <span style="color: rgb(227, 74, 220);">range</span><span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(227, 74, 220);">len</span><span style="color: rgb(128, 128, 48);">(</span>starts<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">,</span> <span style="color: rgb(0, 140, 0);">0</span><span style="color: rgb(128, 128, 48);">,</span> <span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">:</span><br />lengths<span style="color: rgb(128, 128, 48);">.</span>append<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(227, 74, 220);">str</span><span style="color: rgb(128, 128, 48);">(</span>starts<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span> <span style="color: rgb(128, 128, 48);">-</span> starts<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><br /><br />lengths<span style="color: rgb(128, 128, 48);">.</span>reverse<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><br />lengths<span style="color: rgb(128, 128, 48);">.</span>append<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"??:??:??"</span><span style="color: rgb(128, 128, 48);">)</span><br /><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">for</span> i <span style="color: rgb(128, 0, 0); font-weight: bold;">in</span> <span style="color: rgb(227, 74, 220);">range</span><span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 140, 0);">0</span><span style="color: rgb(128, 128, 48);">,</span> <span style="color: rgb(227, 74, 220);">len</span><span style="color: rgb(128, 128, 48);">(</span>tracklist<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">:</span><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">print</span> tracklist<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">,</span> lengths<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><br /></pre><br />Он парсит *.cue и вычисляет длину треков(длины часто не совпадают с заявленными в cue).<br />Вот его результат его работы:<br /><code><br />C:\mp3>python cuei.py 01-va_-_safi_connection_the_remixes-upe.cue<br />1: Safi Connection - Hello Houston Spiritual Enhancer Rmx, from: 00:00:00, 7:09:<br />2: Elec 3 feat. Anna K. - Define Yourself Safi Connection Rmx, from: 07:09:48, 7<br />3: Safi Connection And Saly D - Humna Lights Smhug Rmx, from: 14:17:37, 8:25:12<br />4: Smhug - Decode Safi Connection Rmx, from: 22:42:49, 7:25:15<br />5: Safi Connection - Solaric Seeds Life Style Rmx, from: 30:07:64, 6:53:39<br />6: Safi Connection - Froze Uriya Rmx, from: 37:01:43, 7:01:11<br />7: Safi Connection - Tarazan And JD-J Burn In Noise Rmx, from: 44:02:54, 7:12:10<br />8: Lemurians - Systematic Waves Safi Connection Rmx, from: 51:15:04, 7:03:18<br />9: Safi Connection - Figga Nigga Parrket Rmx, from: 58:18:22, 8:46:39<br />10: Safi Connection - Fullon String Elec 3 Rmx, from: 67:05:01, ??:??:??<br /></code><br />Далее "нарезал" 10 mp3-файлов, сохраняя каждый под его порядковым номером:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/6102/1585/1600/py_mp3_cue_wavelab_out_ss.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/6102/1585/320/py_mp3_cue_wavelab_out_ss.jpg" alt="" border="0" /></a><br />А вот скрипт, который все переименует и расставит mp3-тэги(точнее id3-тэги):<br /><pre><br /><span style="color: rgb(0, 0, 230);">"Renames and tags \d+.mp3 in './' by cue-file"</span><br /><br /><span style="color: rgb(105, 105, 105);">#renbycue.py</span><br /><span style="color: rgb(105, 105, 105);">#rev. 0.3</span><br /><span style="color: rgb(105, 105, 105);">#dron@amerigo 200607311241</span><br /><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">import</span> os<span style="color: rgb(128, 128, 48);">,</span> sys<br /><span style="color: rgb(128, 0, 0); font-weight: bold;">from</span> ID3 <span style="color: rgb(128, 0, 0); font-weight: bold;">import</span> <span style="color: rgb(128, 128, 48);">*</span><br /><br />all <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(227, 74, 220);">open</span><span style="color: rgb(128, 128, 48);">(</span>sys<span style="color: rgb(128, 128, 48);">.</span>argv<span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>read<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><br />tracks <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(128, 128, 48);">[</span>el<span style="color: rgb(128, 128, 48);">.</span>split<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"\n"</span><span style="color: rgb(128, 128, 48);">)</span> <span style="color: rgb(128, 0, 0); font-weight: bold;">for</span> el <span style="color: rgb(128, 0, 0); font-weight: bold;">in</span> all<span style="color: rgb(128, 128, 48);">.</span>split<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"TRACK"</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">]</span><br /><br /><br />perf <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">0</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">0</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>replace<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"PERFORMER"</span><span style="color: rgb(128, 128, 48);">,</span><span style="color: rgb(0, 0, 230);">""</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><br />album <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">0</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>replace<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"TITLE"</span><span style="color: rgb(128, 128, 48);">,</span><span style="color: rgb(0, 0, 230);">""</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><br /><br /><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">print</span> album<span style="color: rgb(128, 128, 48);">,</span> perf<br /><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">for</span> i <span style="color: rgb(128, 0, 0); font-weight: bold;">in</span> <span style="color: rgb(227, 74, 220);">range</span><span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">,</span> <span style="color: rgb(227, 74, 220);">len</span><span style="color: rgb(128, 128, 48);">(</span>tracks<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">:</span><br />title <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>replace<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"TITLE"</span><span style="color: rgb(128, 128, 48);">,</span><span style="color: rgb(0, 0, 230);">""</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><br />artist <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">2</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>replace<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"PERFORMER"</span><span style="color: rgb(128, 128, 48);">,</span><span style="color: rgb(0, 0, 230);">""</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">1</span><span style="color: rgb(128, 128, 48);">]</span><br /><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">if</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">3</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>startswith<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"FLAGS"</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">:</span> <span style="color: rgb(105, 105, 105);">#pass FLAGS</span><br /> startfrom <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">4</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">8</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">]</span><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">else</span><span style="color: rgb(128, 128, 48);">:</span><br /> startfrom <span style="color: rgb(128, 128, 48);">=</span> tracks<span style="color: rgb(128, 128, 48);">[</span>i<span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 140, 0);">3</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 128, 48);">.</span>strip<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(128, 128, 48);">-</span><span style="color: rgb(0, 140, 0);">8</span><span style="color: rgb(128, 128, 48);">:</span><span style="color: rgb(128, 128, 48);">]</span><br /><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">print</span> <span style="color: rgb(0, 0, 230);">"%s - %s, %s"</span> <span style="color: rgb(128, 128, 48);">%</span> <span style="color: rgb(128, 128, 48);">(</span>artist<span style="color: rgb(128, 128, 48);">,</span> title<span style="color: rgb(128, 128, 48);">,</span> startfrom<span style="color: rgb(128, 128, 48);">)</span><br />mp3 <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(0, 0, 230);">"%d.mp3"</span> <span style="color: rgb(128, 128, 48);">%</span> i<br /><span style="color: rgb(128, 0, 0); font-weight: bold;">try</span><span style="color: rgb(128, 128, 48);">:</span><br /> id3 <span style="color: rgb(128, 128, 48);">=</span> ID3<span style="color: rgb(128, 128, 48);">(</span>mp3<span style="color: rgb(128, 128, 48);">)</span><br /> id3<span style="color: rgb(128, 128, 48);">.</span>title <span style="color: rgb(128, 128, 48);">=</span> title<br /> id3<span style="color: rgb(128, 128, 48);">.</span>artist <span style="color: rgb(128, 128, 48);">=</span> artist<br /> id3<span style="color: rgb(128, 128, 48);">.</span>genre <span style="color: rgb(128, 128, 48);">=</span> id3<span style="color: rgb(128, 128, 48);">.</span>find_genre<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"psychadelic"</span><span style="color: rgb(128, 128, 48);">)</span><br /> id3<span style="color: rgb(128, 128, 48);">.</span>track <span style="color: rgb(128, 128, 48);">=</span> i<br /> id3<span style="color: rgb(128, 128, 48);">.</span>year <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(0, 0, 230);">"2006"</span><br /> id3<span style="color: rgb(128, 128, 48);">.</span>comment <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(0, 0, 230);">"renbycue03.py"</span><br /> id3<span style="color: rgb(128, 128, 48);">.</span>album <span style="color: rgb(128, 128, 48);">=</span> perf <span style="color: rgb(128, 128, 48);">+</span> <span style="color: rgb(0, 0, 230);">" "</span> <span style="color: rgb(128, 128, 48);">+</span> album<br /><br /> <span style="color: rgb(128, 0, 0); font-weight: bold;">print</span> id3<br /><br /><span style="color: rgb(128, 0, 0); font-weight: bold;">except</span> InvalidTagError<span style="color: rgb(128, 128, 48);">,</span> message<span style="color: rgb(128, 128, 48);">:</span><br /> <span style="color: rgb(128, 0, 0); font-weight: bold;">print</span> <span style="color: rgb(0, 0, 230);">"Invalid ID3 tag:"</span><span style="color: rgb(128, 128, 48);">,</span> message<br /><br />id3<span style="color: rgb(128, 128, 48);">.</span>write<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><br />id3<span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(227, 74, 220);">file</span><span style="color: rgb(128, 128, 48);">.</span>close<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><br />os<span style="color: rgb(128, 128, 48);">.</span>rename<span style="color: rgb(128, 128, 48);">(</span>mp3<span style="color: rgb(128, 128, 48);">,</span><span style="color: rgb(0, 0, 230);">"%02d-%s-%s.mp3"</span> <span style="color: rgb(128, 128, 48);">%</span> <span style="color: rgb(128, 128, 48);">(</span>i<span style="color: rgb(128, 128, 48);">,</span> artist<span style="color: rgb(128, 128, 48);">,</span> title<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><br /></pre><br />Использовал готовую библиотеку <a href="http://id3-py.sourceforge.net/">id3-py</a>.<br />Запустим на выполнение сценарий:<br /><code><br />C:\mp3>python renbycue.py 01-va_-_safi_connection_the_remixes-upe.cue<br />Album : VA Safi Connection The Remixes Track : 6 Year: 2006<br />Comment: renbycue03.py Genre : Psychadelic (67)<br />Safi Connection - Tarazan And JD-J Burn In Noise Rmx, 44:02:54<br />File : 7.mp3<br />Title : Tarazan And JD-J Burn In Noise Artist: Safi Connection<br />Album : VA Safi Connection The Remixes Track : 7 Year: 2006<br />Comment: renbycue03.py Genre : Psychadelic (67)<br />Lemurians - Systematic Waves Safi Connection Rmx, 51:15:04<br />File : 8.mp3<br />Title : Systematic Waves Safi Connecti Artist: Lemurians<br />Album : VA Safi Connection The Remixes Track : 8 Year: 2006<br />Comment: renbycue03.py Genre : Psychadelic (67)<br />Safi Connection - Figga Nigga Parrket Rmx, 58:18:22<br />File : 9.mp3<br />Title : Figga Nigga Parrket Rmx Artist: Safi Connection<br />Album : VA Safi Connection The Remixes Track : 9 Year: 2006<br />Comment: renbycue03.py Genre : Psychadelic (67)<br />Safi Connection - Fullon String Elec 3 Rmx, 67:05:01<br />File : 10.mp3<br />Title : Fullon String Elec 3 Rmx Artist: Safi Connection<br />Album : VA Safi Connection The Remixes Track : 10 Year: 2006<br />Comment: renbycue03.py Genre : Psychadelic (67)<br /></code><br />В исходной папке вырисовывается следующее:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/6102/1585/1600/py_mp3_cue_renbycue_out_ss.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/6102/1585/320/py_mp3_cue_renbycue_out_ss.png" alt="" border="0" /></a><br />Проверим наличие id3-тэгов с помощью <a href="http://www.winamp.com/">winamp</a>(Alt+3):<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/6102/1585/1600/py_mp3_cue_renbycue_winamp_tags_ss.3.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/6102/1585/320/py_mp3_cue_renbycue_winamp_tags_ss.3.png" alt="" border="0" /></a><br /><br />Мои закладки по теме <a href="http://del.icio.us/areus/python+mp3">тут</a>.<br /><br /><br /><br />Technorati Tags: <a href="http://technorati.com/tag/python" rel="tag">python</a>, <a href="http://technorati.com/tag/mp3" rel="tag">mp3</a>, <a href="http://technorati.com/tag/cue" rel="tag">cue</a>, <a href="http://technorati.com/tag/music" rel="tag">music</a>, <a href="http://technorati.com/tag/edit" rel="tag">edit</a>, <a href="http://technorati.com/tag/%D0%BC%D0%BE%D0%B8+%D1%81%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D1%8B" rel="tag">мои+скрипты</a>Андрейhttp://www.blogger.com/profile/02386268073602354435noreply@blogger.com