Package magma ::
Package magma ::
Module magma_creator_cli_proof_of_concept
|
|
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 """Ask, whether one of the files is an audio file."""
44 print "Now, let's make it a audio list."
45 print ""
46 audio = raw_input("Is one of the file a audio file (yes/No)? ")
47
48 while not audio.lower() in ["yes", "no", "", "y", "n"]:
49 audio = raw_input("Is one of the file a audio file? Please answer either 'yes' or 'no'. Just clicking enter skips: ")
50
51 if audio.lower() == "no" or audio.lower() == "n" or audio.lower() == "":
52 return
53
54
55
56
57 audio = raw_input("Please enter which file it is (1 or 2 or ...): ")
58 while not audio in [str(i) for i in range(1, len(magma.files) + 1)]:
59 audio = raw_input("Please enter a valid number (1 or 2 or ...): ")
60 print "Now onwards to editing file", audio + ":", magma.files[int(audio) -1].name
61 file_to_edit = magma.files[int(audio) -1]
62 file_to_edit.path = files[int(audio) -1]
63 edit_file(file_to_edit)
64
65 print "So now, the file looks like this:"
66
67 print magma
68
69 magma_filename = raw_input("Please enter a name to which to save the file. It should end on .magma: ")
70 magma.save(magma_filename)
71
72 print "Magma file saved as", magma_filename
73
74 print "It contains the following magnets:"
75 for i in magma.magnets:
76 print i
77
78
80 """Edit the data inside a magma file - add metadata."""
81
82 print "First this script will try to get some values automatically. "
83 automatically_generated_tags = []
84
85 magma_file.data["audio"] = {}
86 try:
87 from tagpy import FileRef
88
89 filetags = FileRef(magma_file.path)
90
91 audioprops = filetags.audioProperties()
92 tagfile = filetags.file()
93 try:
94
95 magma_file.data["audio"]["length-ms"] = audioprops.length*1000
96 automatically_generated_tags.append(("length-ms", magma_file.data["audio"]["length-ms"]))
97 except: pass
98 try:
99
100 magma_file.data["audio"]["bitrate-kbps"] = audioprops.bitrate
101 automatically_generated_tags.append(("bitrate-kbps", magma_file.data["audio"]["bitrate-kbps"]))
102 except: pass
103 try:
104
105 magma_file.data["audio"]["samplerate-Hz"] = audioprops.sampleRate
106 automatically_generated_tags.append(("samplerate-Hz", magma_file.data["audio"]["samplerate-Hz"]))
107 except: pass
108 try:
109
110 magma_file.data["size-Bytes"] = tagfile.length()
111 automatically_generated_tags.append(("size-Bytes", magma_file.data["size-bits"]))
112 except: pass
113 except:
114 pass
115
116 print "The following tags were added:"
117 for i in automatically_generated_tags:
118 print i
119
120
121 magma_file.data["title"] = raw_input("Please enter the title of the file: ")
122 magma_file.data["description"] = raw_input("Please enter a description of the file: ")
123
124
125 magma_file.data["audio"]["artists"] = []
126 artist1 = {}
127 artist1["name"] = raw_input("Please enter the name of its artist: ")
128 artist1["website"] = raw_input("Please enter an url to the website of the artist: ")
129 magma_file.data["audio"]["artists"] .append(artist1)
130
131
132 magma_file.data["audio"]["album"] = raw_input("Please enter the name of the album: ")
133 magma_file.data["year"] = raw_input("Please enter the year when this work was published: ")
134 magma_file.data["audio"]["tracknumber"] = raw_input("Please enter the tracknumber of this file: ")
135
136
137
138
140 """Create magma files interactively via commandline dialogs.
141
142 @param files: A list of files to hash.
143 @type files: List
144 """
145 magma = Magma(input_files=files)
146 print "Basic magma list: "
147 print magma
148
149 ask_audio(files, magma)
150
151
152
153
155 """Usage instructions.
156
157 @return: Usage instructions (String)."""
158
159 usage = __doc__.split("\n\n")[1:]
160 usage_string = "\n\n".join(usage)
161 return usage_string
162
163
164
166 """Do all doctests.
167
168 @return: None"""
169 from doctest import testmod
170 testmod()
171
172
173 if __name__ == "__main__":
174 _test()
175 from sys import argv
176 create_magma_list_interactively(argv[1:])
177