forked from direwolf424/Lanify
-
Notifications
You must be signed in to change notification settings - Fork 2
/
songs_add.js
220 lines (210 loc) · 8.15 KB
/
songs_add.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
var mongoose = require('mongoose');
var fs = require('fs');
var pa = require('path');
var Sync = require('sync');
var mm = require('musicmetadata');
var Song = require('./model/songs').Song;
var title1,filename;
//mongoose.createConnection('mongodb://localhost/music');
mongoose.connect('mongodb://localhost/music');
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function isBlank(str) {
return (!str || /^\s*$/.test(str));
}
function capitalizeFirstLetter(string) {
console.log('here',string);
return string.charAt(0).toUpperCase() + string.slice(1);
}
function delete_info(str){
str = str.replace(/\([0-9]+\)/gi,""); //for format (1234)
str = str.replace(/\[[0-9 a-z _ : , @ .]+\]/gi,""); //for anything beetween [word]
str = str.replace(/[']+/,""); //for ' "
str = str.replace(/["]+/,""); //for ' "
str = str.replace(/[#]+/,""); //for ' "
str = str.replace(/www\.[0-9 a-z]+\.com/gi,""); //for ' "
str = str.replace(/www\.[0-9 a-z]+\.org/gi,""); //for ' "
str = str.replace(/www\.[0-9 a-z]+\.pk/gi,""); //for ' "
str = str.replace(/www\.[0-9 a-z]+\.se/gi,""); //for ' "
str = str.replace(/www\.[0-9 a-z]+\.net/gi,""); //for ' "
str = str.replace(/www\.[0-9 a-z]+\.info/gi,""); //for ' "
str = str.replace(/www\.[0-9 a-z]+\.link/gi,""); //for ' "
str = str.replace(/www\.[0-9 a-z]+\.inf/gi,""); //for ' "
str = str.replace(/www\.[0-9 a-z]+\.eu/gi,""); //for ' "
str = str.replace(/- [0-9 a-z]+\.com/gi,""); //for ' "
str = str.replace(/@ [0-9 a-z]+\.com/gi,""); //for ' "
str = str.replace(/- [0-9 a-z]+\.org/gi,""); //for ' "
str = str.replace(/- [0-9 a-z]+\.PK/gi,""); //for ' "
str = str.replace(/- [0-9 a-z]+\.SE/gi,""); //for ' "
str = str.replace(/- [0-9 a-z]+\.net/gi,""); //for ' "
str = str.replace(/- [0-9 a-z]+\.info/gi,""); //for ' "
str = str.replace(/- [0-9 a-z]+\.link/gi,""); //for ' "
str = str.replace(/- [0-9 a-z]+\.inf/gi,""); //for ' "
str = str.replace(/[:]+/gi,''); //for ' "
str=str.replace(" - DJMaza.Info", "");
str=str.replace(" - DJMaza.INFO", "");
str=str.replace(" - www.Songs.PK", "");
str=str.replace(" - www.Songs.PK", "");
str=str.replace("[www.DJMaza.Com]", "");
str=str.replace(" - www.DJMaza.Com", "");
str=str.replace(" - www.MP3Khan.Com", "");
str=str.replace(" - DJMaza.Com", "");
str=str.replace(" - SceneDL", "");
str=str.replace(" - DownloadMing.SE", "");
str=str.replace(" - MP3Khan.Com", "");
str=str.replace("[PagalWorld.com]", "");
str=str.replace("(PagalWorld.com)", "");
str=str.replace("[www.Mp3HunGama.IN]", "");
str=str.replace(" - www.SongsPK.info", "");
str=str.replace("- Songspk.LINK", "");
str=str.replace("- DJMaza.Link", "");
str=str.replace("[www.LatestZone.Net]", "");
str=str.replace("- Songspk.name", "");
str=str.replace("- www.SongsLover.com", "");
str=str.replace("- urgrove.com", "");
str=str.replace("- Tinhkhucbathu.com", "");
str=str.replace("www.Songs.PK", "");
str=str.replace("www.djrobsonmichel.com", "");
str=str.replace("{www.LatestZone.Net}", "");
str=str.replace(":: www.FreeTeluguMp3Songs.com ::", "");
str=str.replace("[Songs.PK]", "");
str=str.replace("- PagalWorld.com", "");
str=str.replace("- www.SongsLover.com", "");
str = str.replace(/[-]+/,""); //for ' "
str = str.trim();
return str;
}
function split_Artist(str){
str1 = str[0].split(/[&,]+/);
for(var i=0;i<str1.length;i++){
str1[i]=delete_info(str1[i]);
}
return str1;
}
function calculate_length(time){
var time1 = parseInt(time);
var min = time1/60;
var sec=time%60;
if(isNaN(sec)){
sec='00';
}
else
sec=Math.floor(sec);
if(isNaN(min)){
min='00';
}
else
min=Math.floor(min);
min = min.toString();
sec = sec.toString();
if(min.length == 1)
min='0'+min;
if(sec.length == 1)
sec='0'+sec;
time = min +":"+sec;
return time;
}
var name;
//--------------------Hindi-----------------------------------
//var lang='hindi';
//var path= "/myfile/dc/lanify/Hindi2/";
//var path1="Hindi2/";
//---------------------English--------------------------
var lang='english';
var path= "/myfile/dc/lanify/English2/";
var path1="English2/";
//----------------telugu----------------------------------
//var lang='telugu';
//var path= "/myfile/dc/lanify/Telugu/";
//var path1="Telugu/";
var song_folder_arr = fs.readdirSync(path);
//console.log("hello",song_folder_arr);
var cntr=0;
Sync(function(){
var cnt=0;
for(j=0;j<song_folder_arr.length;j++){
var folder = path+song_folder_arr[j];
song_arr = fs.readdirSync(folder);
//console.log(folder);
console.log(song_arr,song_arr.length);
var tags;
for(var i=0;i<song_arr.length;i++)
{
var file = song_arr[i];
//console.log(file);
if(endsWith(file, ".mp3"))
{
cnt++;
//if(cnt<=596)
//continue;
var pat = path1+song_folder_arr[j]+'/'+file;
var time,metadata;
try{
metadata = mm.sync(null,fs.createReadStream("/myfile/dc/lanify/"+pat),{duration:true});
}
catch(e){
//console.log('-------------------------------------->>'+e);
continue;
}
time=metadata.duration;
//console.log('hello',metadata);
//console.log('hello1');
time = calculate_length(time);
title1 = metadata.title;
//console.log(title1);
if(isBlank(metadata.title)){
title1 = file.replace(".mp3","");
}
//if(isBlank(title1)||isBlank(metadata.artist)||isBlank(metadata.album))
//{
////console.log("----------->the string was empty");
//continue;
//}
//console.log('hello1');
arr_artist=split_Artist(metadata.artist);
//console.log('hello2');
var title = delete_info(title1);
var album = delete_info(metadata.album);
var year = metadata.year;
console.log('---->',title);
if(isBlank(title))
{
console.log("----------->the string was empty");
continue;
}
Song.update({"title":title},
{
$set: {
title:title,
album:album,
artist:arr_artist,
genre:metadata.genre,
path:pat,
album_art_small:path1+song_folder_arr[j]+'/cover/FRONT_COVER.jpg',
album_art:path1+song_folder_arr[j]+'/cover/FRONT_COVER.jpg',
rating:0,
views:0,
likes:0,
dislikes:0,
release_date:year,
length:time,
language:lang
},
$currentDate: {
lastModified: true,
}
},
{ upsert:true }).exec(function(err,write){
if(err)
console.log('updated');
else{
console.log(cnt + ' written ',title+' ',i);
//cnt++;
}
});
//console.log('skipping');
}
}
}
});