Repository navigation
Expand file tree
/
Copy pathfile_reader.py
More file actions
88 lines (68 loc) · 2.82 KB
/
Copy pathfile_reader.py
File metadata and controls
88 lines (68 loc) · 2.82 KB
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
#!/usr/bin/python3.5
'''
Jass is an open source client and recommender system for the SoulSeek network.
Copyright (C) 2017 Richard Dunn
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from __future__ import print_function
import os
import mutagen
from pprint import pprint
def recurAndPrint(path):
for entry in os.scandir(path):
if not entry.name.startswith('.') and entry.is_dir():
recurAndPrint(entry.path)
elif not entry.name.startswith('.') and entry.is_file():
try:
print('Size:', entry.stat().st_size)
print('0:', mutagen.File(entry.path).info.bitrate)
print('1:', mutagen.File(entry.path).info.length)
print('\n')
except mutagen.MutagenError as e:
print('Mutagen error:', e)
except AttributeError:
pass
def _buildFileFolder(path, file_folder):
fake_path = '@@wlaqp/' + path
file_folder[fake_path] = []
for entry in os.scandir(path):
if not entry.name.startswith('.') and entry.is_dir():
_buildFileFolder(entry.path, file_folder)
elif not entry.name.startswith('.') and entry.is_file():
this_file = {
'title': entry.name,
'size': entry.stat().st_size,
'ext' : entry.name.rsplit('.', 1)[1],
'attributes': {}
}
print(entry.name)
try:
mutagen_file = mutagen.File(entry.path)
if mutagen_file and not entry.path.endswith('.jpg'):
print(entry.name)
this_file['attributes']['0'] = mutagen_file.info.bitrate
print(mutagen_file.info.bitrate)
this_file['attributes']['1'] = round(mutagen_file.info.length)
print(mutagen_file.info.length)
except mutagen.MutagenError as e:
print('Mutagen error:', e)
finally:
file_folder[fake_path].append(this_file)
def buildFileFolder(path):
file_folder = {}
_buildFileFolder(path, file_folder)
pprint(file_folder)
return file_folder
if __name__ == '__main__':
path = 'collection'
file_folder = buildFileFolder(path)
pprint(file_folder)