/*
 * Copyright (c) Created by Can Kuşcu on 26/4/2018
 */

const moment = require('moment');
const PlayerDB = require('../PlayerDB');
const DM = require('../../downloader/DownloadManager').DownloadManager;
const dm = new DM();
const smgutils = require('../../utils/smgutils');
const sutils = new smgutils();
let db = new PlayerDB();
global.db = db;
global.deviceID = 7787;
global.url = 'http://cdn.smg.com.tr/';
// const schedules = require('./schedulesDB');
// let sch = new schedules({db, moment});
// const announces = require('./announcesDB');
// let ann = new announces({db, moment});
const announces = require('../../downloader/announcesDownloader');
let ann = new announces({db, moment});
const schedules = require('../../downloader/schedulesDownloader');
let sch = new schedules({db, moment});

console.log('uyandi ' + new moment().utc(true).toJSON().substr(11,19));
db.initsync()

async function main() {
    let q1 = await ann.checkDownloads();
    let q = await sch.checkDownloads();
    // let q1 = await ann.start();
    // let q = await sch.start();

    await q.forEach(obj => {
        //console.log(obj.FileName);
        dm.addFileToQue(obj.FileName);
    });

    await q1.forEach(obj => {
        dm.addFileToQue(obj.FileName);
    });
}
setTimeout(() => {
    main();
}, 10000)
// dm.start();
