Package: jack / 3.1.1+cvs20050801-31

44_guess_toc_ogg_flac.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Implement OGG and FLAC support for --guess-toc.  SourceForge #1089407

Also fix a problem with the progress information ("ren") when a filename
contains Unicode chars.

Depends on 33_flac_mutagen.patch


diff -urN jack-3.1.1+cvs20050801~/jack_functions.py jack-3.1.1+cvs20050801/jack_functions.py
--- jack-3.1.1+cvs20050801~/jack_functions.py	2006-04-04 23:09:17.000000000 +0200
+++ jack-3.1.1+cvs20050801/jack_functions.py	2006-04-04 23:25:59.000000000 +0200
@@ -33,6 +33,8 @@
 import jack_helpers
 
 from jack_globals import *
+from jack_init import ogg
+from jack_init import flac
 
 progress_changed = None
 
@@ -152,21 +154,17 @@
     erg = []
     progr = []
     for i in names:
-        i_name = os.path.basename(i)[:-4]
-        i_ext  = string.upper(os.path.basename(i)[-4:])
+        i_name, i_ext = os.path.splitext(os.path.basename(i))
+        i_ext = i_ext.upper()
+        # erg: NUM, LEN, START, COPY, PRE, CH, RIP, RATE, NAME
         if i_ext == ".MP3":
             x = jack_mp3.mp3format(i) 
             if not x:
                 error("could not get MP3 info for file \"%x\"" % i)
             blocks = int(x['length'] * CDDA_BLOCKS_PER_SECOND + 0.5)
-            #           NUM, LEN,    START, COPY, PRE, CH, RIP, RATE,
-            #   NAME
-            erg.append([num, blocks, start, 0,    0,   2,  1,   x['bitrate'],
-                i_name])
+            erg.append([num, blocks, start, 0, 0, 2, 1, x['bitrate'], i_name])
             progr.append([num, "dae", "  *   [          simulated           ]"])
             progr.append([num, "enc", `x['bitrate']`, "[ s i m u l a t e d %3ikbit]" % (x['bitrate'] + 0.5)])
-            if cf['_name'] % num != i_name:
-                progr.append([num, "ren", cf['_name'] % num + "-->" + i_name])
         elif i_ext == ".WAV":
             x = sndhdr.whathdr(i)
             if not x:
@@ -190,14 +188,37 @@
             blocks = blocks / CDDA_BLOCKSIZE
             erg.append([num, blocks, start, 0, 0, 2, 1, cf['_bitrate'], i_name])
             progr.append([num, "dae", "  =p  [  s  i  m  u  l  a  t  e  d   ]"])
-            if cf['_name'] % num != i_name:
-                progr.append([num, "ren", cf['_name'] % num + "-->" + i_name])
         elif i_ext == ".OGG":
-            error("you still have to wait for ogg support for this operation, sorry.")
+            if ogg:
+                x = ogg.vorbis.VorbisFile(i)
+                blocks = int(x.time_total(0) * CDDA_BLOCKS_PER_SECOND + 0.5)
+                bitrate = temp_rate = int(x.raw_total(0) * 8 / x.time_total(0) / 1000 + 0.5)
+                erg.append([num, blocks, start, 0, 0, 2, 1, bitrate, i_name])
+                progr.append([num, "dae", "  *   [          simulated           ]"])
+                progr.append([num, "enc", `bitrate`, "[ s i m u l a t e d %3ikbit]" % bitrate])
+            else:
+                error("The OGG Python bindings are not installed.")
         elif i_ext == ".FLAC":
-            error("you still have to wait for FLAC support for this ooperation, sorry.")
+            if flac:
+                # TODO: move all of this duplicate code (see update_progress in
+                # jack_prepare.py) into a jack_flac or jack_audio or jack_formats.
+                # The same goes for the OGG stuff above
+                f = flac.FLAC(i)
+                size = os.path.getsize(i)
+                if f.info and size:
+                    blocks = int(float(f.info.total_samples)/f.info.sample_rate * CDDA_BLOCKS_PER_SECOND + 0.5)
+                    bitrate = int(size * 8 * f.info.sample_rate / f.info.total_samples / 1000)
+                else:
+                    blocks = bitrate = 0
+                erg.append([num, blocks, start, 0, 0, 2, 1, bitrate, i_name])
+                progr.append([num, "dae", "  *   [          simulated           ]"])
+                progr.append([num, "enc", `bitrate`, "[ s i m u l a t e d %3ikbit]" % bitrate])
+            else:
+                error("The FLAC Python bindings are not installed.")
         else:
             error("this is neither .mp3 nor .ogg nor .wav nor .flac: %s" % i)
+        if cf['_name'] % num != i_name:
+            progr.append([num, "ren", cf['_name'] % num + "-->" + unicode(i_name, cf['_charset'], "replace")])
         num = num + 1
         start = start + blocks
     for i in progr:     # this is deferred so that it is only written if no