1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """Create magma files interactively via commandline dialogs.
22
23 Usage: magma_creator_cli.py file1 file2, ...
24
25 Examples:
26 - magma_creator_cli.py input_file.txt input_file2.txt Infinite-Hands--free-software.ogg
27
28
29 This will implement features from magma-for-streaming-mediav0.07.txt
30
31 It is mainly a proof of concept, yet, and it may change!
32
33 Ideas:
34 - Check, if tagpy or similar are avaible, and if yes, add metadata from the file tags.
35 """
36
37
38 from magma_list import Magma
39 from magma_list import MagmaFile
40
41
43 """Edit the data inside a magma file - add metadata."""
44
45 print "First this script will try to get some values automatically. "
46 automatically_generated_tags = []
47
48 if not magma_file.name.endswith(".mp3") or magma_file.name.endswith(".ogg"):
49 print "No mp3 or ogg file. We only support mp3 and ogg vorbis at the moment."
50 return
51
52
53 magma_file.data["audio"] = {}
54 try:
55 from tagpy import FileRef
56
57 filetags = FileRef(magma_file.path)
58 print "yes, FileRef"
59
60 try:
61 audioprops = filetags.audioProperties()
62 except: pass
63 try:
64 tagfile = filetags.file()
65 except: pass
66 try:
67 tag = filetags.tag()
68 except: pass
69
70 try:
71
72 magma_file.data["audio"]["length-ms"] = audioprops.length*1000
73 automatically_generated_tags.append(("length-ms", magma_file.data["audio"]["length-ms"]))
74 except: pass
75 try:
76
77 magma_file.data["audio"]["bitrate-kbps"] = audioprops.bitrate
78 automatically_generated_tags.append(("bitrate-kbps", magma_file.data["audio"]["bitrate-kbps"]))
79 except: pass
80 try:
81
82 magma_file.data["audio"]["samplerate-Hz"] = audioprops.sampleRate
83 automatically_generated_tags.append(("samplerate-Hz", magma_file.data["audio"]["samplerate-Hz"]))
84 except: pass
85 try:
86
87 magma_file.data["size-Bytes"] = tagfile.length()
88 automatically_generated_tags.append(("size-Bytes", magma_file.data["size-bits"]))
89 except: pass
90
91
92 try:
93
94 magma_file.data["audio"]["title"] = tag.title
95 automatically_generated_tags.append(("title", magma_file.data["audio"]["title"]))
96 except: pass
97
98 try:
99
100 magma_file.data["audio"]["year"] = tag.year
101 automatically_generated_tags.append(("year", magma_file.data["audio"]["year"]))
102 except: pass
103
104 try:
105
106 magma_file.data["audio"]["track"] = tag.track
107 automatically_generated_tags.append(("track", magma_file.data["audio"]["track"]))
108 except: pass
109
110 try:
111
112 magma_file.data["audio"]["genre"] = tag.genre
113 automatically_generated_tags.append(("genre", magma_file.data["audio"]["genre"]))
114 except: pass
115
116 try:
117
118 magma_file.data["audio"]["comment"] = tag.comment
119 automatically_generated_tags.append(("comment", magma_file.data["audio"]["comment"]))
120 except: pass
121 except: pass
122
123 print "The following tags were added:"
124 for i in automatically_generated_tags:
125 print i
126
127
128
129
130
132 """Create magma files interactively via commandline dialogs.
133
134 @param files: A list of files to hash.
135 @type files: List
136 """
137 magma = Magma(input_files=files)
138 print "Basic magma list: "
139 print magma
140
141 print "------ ------ ------ ------ ------ ------ "
142
143 print "Now we try add metadata using tagpy. "
144 for i in range(len(magma.files)):
145 magma.files[i].path = files[i]
146 edit_file(magma.files[i])
147
148 print "------ ------ ------ ------ ------ ------ "
149 print "The magma list now looks like this: "
150 print "---"
151 print magma
152
153 ip_port = raw_input("... \nIf you use Gnutella, you can now give a list of IP:PORT pairs seperated by spaces as alternate-locations. For example you can give your clients IP and its port, alternately your dyndns host and your client port. They can greatly increase the performance of downloads but break your anonymity. \nExample: 127.0.0.1:6465 0.0.0.0:9999 example.dyndns.org:1234 \nIf you want to add alt-locs, please add the IP:PORT pairs now: ")
154 alt_locs = ip_port.split()
155
156 try:
157
158
159
160
161 if len(alt_locs) > 0:
162 for i in magma.files:
163 i.data["gnutella"]["alt-locs"] = alt_locs
164 except:
165 print "You need the IPy module to add alt-locs, and the IP addresses need to be valid. No alt-locs added."
166 print "To fix it just run 'easy_install IPy', and check the format of the IPs"
167
168 target_file = raw_input("Where shall we save it? ")
169 magma.save(target_file)
170
171
172
174 """Usage instructions.
175
176 @return: Usage instructions (String)."""
177
178 usage = __doc__.split("\n\n")[1:]
179 usage_string = "\n\n".join(usage)
180 return usage_string
181
182
183
185 """Do all doctests.
186
187 @return: None"""
188 from doctest import testmod
189 testmod()
190
191
192 if __name__ == "__main__":
193 _test()
194 from sys import argv
195 if argv[1] in ["--help", "-h", "?", "--usage"]:
196 print usage()
197 else:
198 create_magma_list_interactively(argv[1:])
199