<commit_before>/* eslint camelcase: ["error", {properties: "never"}] */

const fs = require('fs');
const co = require('co');
const path = require('path');
const Bottleneck = require('bottleneck');
const waitkey = require('./waitkey');
const TMDbClient = require('./tmdbclient');
const Cacher = require('./cacher');

let limiter = new Bottleneck(0, 300);
let config = require(path.join(__dirname, '../config.js'));
let tmdb = new TMDbClient(config.tmdb.key);
let cache = new Cacher(path.join(__dirname, '../cache'));

co(function* () {
    let sessionId = yield cache.getData();
    if (!sessionId || !sessionId.length) {
        sessionId = yield getSessionId();
        cache.setData(sessionId);
    }
    let account = yield tmdb.call('/account', {
        session_id: sessionId
    });
    if (account.status_code === 3) {
        sessionId = yield getSessionId();
        cache.setData(sessionId);
        account = yield tmdb.call('/account', {
            session_id: sessionId
        });
    }
    let createdList = yield tmdb.call(`/account/${account.id}/lists`, {
        session_id: sessionId
    });
    let listId;
    if (createdList.results.length) {
        let result = createdList.results.find((item) => {
            return item.name === config.tmdb.list;
        });
        if (result) {
            listId = result.id;
        }
    }
    if (!listId) {
        let result = yield tmdb.call('/list', {}, 'POST', {
            name: config.tmdb.list,
            description: '',
            language: 'en',
            session_id: sessionId
        });
        listId = result.list_id;
    }
    console.log();
    console.log('session_id:', sessionId);
    console.log('account_id:', account.id);
    console.log('list_id:', listId);
    console.log();
    let movieDatas = yield extractDataFromFolderNames(config.sourceFolder);
    let movieMetadatas = yield findMovieMetadatas(movieDatas);
    let localMovies = movieMetadatas.map((metadata, i) => {
        let result = {
            _source: movieDatas[i]
        };
        if (metadata.total_results > 0) {
            Object.assign(result, metadata.results[0]);
        }
        return result;
    });
    let tmdbMovies = yield tmdb.call(`/list/${listId}`, {
        session_id: sessionId
    });
    let changes = getDiff(localMovies, tmdbMovies.items);

    yield addOrRemoveMovies(changes, listId, sessionId);

    logSummary(changes);
}).catch((error) => {
    console.log('Error', error);<commit_msg>fixed file locations<commit_after>/* eslint camelcase: ["error", {properties: "never"}] */

const fs = require('fs');
const co = require('co');
const path = require('path');
const Bottleneck = require('bottleneck');
const waitkey = require('./lib/waitkey');
const TMDbClient = require('./lib/tmdbclient');
const Cacher = require('./lib/cacher');

let limiter = new Bottleneck(0, 300);
let config = require('./config.js');
let tmdb = new TMDbClient(config.tmdb.key);
let cache = new Cacher('./cache');

co(function* () {
    let sessionId = yield cache.getData();
    if (!sessionId || !sessionId.length) {
        sessionId = yield getSessionId();
        cache.setData(sessionId);
    }
    let account = yield tmdb.call('/account', {
        session_id: sessionId
    });
    if (account.status_code === 3) {
        sessionId = yield getSessionId();
        cache.setData(sessionId);
        account = yield tmdb.call('/account', {
            session_id: sessionId
        });
    }
    let createdList = yield tmdb.call(`/account/${account.id}/lists`, {
        session_id: sessionId
    });
    let listId;
    if (createdList.results.length) {
        let result = createdList.results.find((item) => {
            return item.name === config.tmdb.list;
        });
        if (result) {
            listId = result.id;
        }
    }
    if (!listId) {
        let result = yield tmdb.call('/list', {}, 'POST', {
            name: config.tmdb.list,
            description: '',
            language: 'en',
            session_id: sessionId
        });
        listId = result.list_id;
    }
    console.log();
    console.log('session_id:', sessionId);
    console.log('account_id:', account.id);
    console.log('list_id:', listId);
    console.log();
    let movieDatas = yield extractDataFromFolderNames(config.sourceFolder);
    let movieMetadatas = yield findMovieMetadatas(movieDatas);
    let localMovies = movieMetadatas.map((metadata, i) => {
        let result = {
            _source: movieDatas[i]
        };
        if (metadata.total_results > 0) {
            Object.assign(result, metadata.results[0]);
        } else {
            console.log(result);
        }
        return result;
    });
    let tmdbMovies = yield tmdb.call(`/list/${listId}`, {
        session_id: sessionId
    });
    let changes = getDiff(localMovies, tmdbMovies.items);

    yield addOrRemoveMovies(changes, listId, sessionId);

    logSummary(changes);
}).catch((error) => {
    console.log('Error', error);
{'fraction_non_alphanumeric': 0.1526916149689814, 'fraction_numerical': 0.002801681008605163, 'mean_word_length': 2.5725518227305217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5667022', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1521, 'n_words': 321}