Commit 1740086d authored by Javinator9889's avatar Javinator9889 🎼

Merge branch 'milestone#4' into 'master'

Milestone#4

See merge request !6
parents 53c4ab68 601d109b
Pipeline #95 passed with stage
in 7 minutes and 10 seconds
......@@ -102,3 +102,6 @@ venv.bak/
# mypy
.mypy_cache/
# keys folder
keys/
# https://hub.docker.com/r/library/python/tags/
image: python:latest
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
paths:
- .cache/pip
- venv/
before_script:
- python -V # Print out python version for debugging
- apt update && apt upgrade -y
- apt install -y libchromaprint-tools ffmpeg --install-recommends
- pip install -r YouTubeMDBot/requirements.txt
test:pylint:
script:
- pip install pylint
- pylint -j 0 --exit-zero --ignored-classes=_socketobject *.py YouTubeMDBot
test:
script:
- python -m unittest $(pwd)/YouTubeMDBot/tests/*.py
<mxfile host="Electron" modified="2019-10-19T12:30:48.266Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/12.1.0 Chrome/76.0.3809.139 Electron/6.0.7 Safari/537.36" etag="v1HPNPNhdJK3ik61crrq" version="12.1.0" type="device" pages="1"><diagram name="Page-1" id="efa7a0a1-bf9b-a30e-e6df-94a7791c09e9">7V1Nl5s2FP01XjaHb5vlfGSaTdq0c3qarObIINt0AE1AZMb59RVGwraEOwyWkZgqmxjBCNC9enq670nM3Jvs5dcCPG0+oximM8eKX2bu7cxxbNddkP/qkm1TsrCcpmBdJDG9aF9wn/yEtNCipVUSw/LoQoxQipOn48II5TmM8FEZKAr0fHzZCqXHd30CaygU3EcgFUv/TmK8oW/hBPvyTzBZb9id7SBszixB9LguUJXT+80cd7X715zOAKuLvmi5ATF6PihyP87cmwIh3PzKXm5gWrcta7bm7+5OnG2fu4A57vMHle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bdwqnKE+yebL2NHk/Xo0oT5qNF2VtvOhagiDZMdsZdevFdqtPA/hFAOe8SNUbqzpWV7omv8d+CrbpbiW1CUGcu3Ebv6BHeQDCsUQ90gQgxmVBwL6kqkyvdKwJJlu2xutVd5CS3LiDZ7qDjtWlhXLDxT0G9b4bSWS+yCLBVHA7faqPWDuWKHTiJINicMMMB8Mw1iB+5VgTlBtbZvYYD5R+reUdjQcnPvhrLSHMdw31vYIlJn1bMPsm8nlsBLi01oXqDzY51gQVwtZB6WECdPpM65RNgFEILycYBVxgSr0+yIg7LavQd6cAOqU0VuFcq2BPcBl4f5oozmrgP9MZ8jHmvjTxeaeDnzWeoAmBDWwPLnuqLyhPPzD/VcEFtU971jU1SubgJDWt3hzUK8TZhjbONVV9vzj5Zg7ySsp5HCSHBUL48HLibmw+oxjWV/wL</diagram></mxfile>
\ No newline at end of file
This diff is collapsed.
-- MySQL Script generated by MySQL Workbench
-- lun 22 jul 2019 14:28:48 CEST
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE[email protected]@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema youtubemd
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema youtubemd
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `youtubemd` DEFAULT CHARACTER SET utf8mb4 ;
SHOW WARNINGS;
USE `youtubemd` ;
-- -----------------------------------------------------
-- Table `youtubemd`.`User`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`User` (
`id` INT(64) NOT NULL DEFAULT 0,
`name` VARCHAR(45) NULL DEFAULT 'User',
`surname` VARCHAR(45) NULL,
`username` VARCHAR(45) NULL,
`lastSeen` DATETIME NOT NULL,
`firstUsage` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
CHECKSUM = 1
PACK_KEYS = 1;
SHOW WARNINGS;
CREATE UNIQUE INDEX `id_UNIQUE` ON `youtubemd`.`User` (`id` ASC) VISIBLE;
SHOW WARNINGS;
CREATE UNIQUE INDEX `username_UNIQUE` ON `youtubemd`.`User` (`username` ASC) VISIBLE;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`Preferences`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`Preferences` (
`language` VARCHAR(3) NOT NULL DEFAULT 'en',
`audioQuality` ENUM('320k', '256k', '128k') NOT NULL DEFAULT '128k',
`audioSampling` ENUM('44000', '48000') NOT NULL DEFAULT '44000',
`sendSongLinks` TINYINT NOT NULL DEFAULT 0,
`User_id` INT(64) NOT NULL,
PRIMARY KEY (`User_id`),
CONSTRAINT `fk_Preferences_User`
FOREIGN KEY (`User_id`)
REFERENCES `youtubemd`.`User` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
CHECKSUM = 1;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`Metadata`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`Metadata` (
`idMetadata` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(100) NOT NULL,
`artist` VARCHAR(60) NOT NULL,
`cover` BLOB NOT NULL,
`duration` INT NULL,
`customMetadata` TINYINT NOT NULL DEFAULT 0,
PRIMARY KEY (`idMetadata`))
ENGINE = InnoDB
AUTO_INCREMENT = 0
CHECKSUM = 1;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`VideoInformation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`VideoInformation` (
`id` VARCHAR(11) NOT NULL,
`title` VARCHAR(100) NOT NULL,
`channel` VARCHAR(60) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
CHECKSUM = 1;
SHOW WARNINGS;
CREATE UNIQUE INDEX `id_UNIQUE` ON `youtubemd`.`VideoInformation` (`id` ASC) VISIBLE;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`DownloadInformation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`DownloadInformation` (
`file_id` VARCHAR(50) NOT NULL,
`audioQuality` ENUM('320k', '256k', '128k') NOT NULL,
`audioSampling` ENUM('44000', '48000') NULL,
`Metadata_idMetadata` INT NOT NULL,
`VideoInformation_id` VARCHAR(11) NOT NULL,
PRIMARY KEY (`file_id`, `Metadata_idMetadata`, `VideoInformation_id`),
CONSTRAINT `fk_DownloadInformation_Metadata1`
FOREIGN KEY (`Metadata_idMetadata`)
REFERENCES `youtubemd`.`Metadata` (`idMetadata`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_DownloadInformation_VideoInformation1`
FOREIGN KEY (`VideoInformation_id`)
REFERENCES `youtubemd`.`VideoInformation` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
CHECKSUM = 1;
SHOW WARNINGS;
CREATE UNIQUE INDEX `file_id_UNIQUE` ON `youtubemd`.`DownloadInformation` (`file_id` ASC) VISIBLE;
SHOW WARNINGS;
CREATE INDEX `fk_DownloadInformation_Metadata1_idx` ON `youtubemd`.`DownloadInformation` (`Metadata_idMetadata` ASC) VISIBLE;
SHOW WARNINGS;
CREATE INDEX `fk_DownloadInformation_VideoInformation1_idx` ON `youtubemd`.`DownloadInformation` (`VideoInformation_id` ASC) VISIBLE;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`History`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`History` (
`User_id` INT(64) NOT NULL,
`DownloadInformation_file_id` VARCHAR(50) NOT NULL,
PRIMARY KEY (`User_id`, `DownloadInformation_file_id`),
CONSTRAINT `fk_History_User1`
FOREIGN KEY (`User_id`)
REFERENCES `youtubemd`.`User` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_History_DownloadInformation1`
FOREIGN KEY (`DownloadInformation_file_id`)
REFERENCES `youtubemd`.`DownloadInformation` (`file_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
CHECKSUM = 1;
SHOW WARNINGS;
CREATE INDEX `fk_History_DownloadInformation1_idx` ON `youtubemd`.`History` (`DownloadInformation_file_id` ASC) VISIBLE;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`VideoStatistics`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`VideoStatistics` (
`timesRequested` INT NOT NULL DEFAULT 0,
`VideoInformation_id` VARCHAR(11) NOT NULL,
PRIMARY KEY (`VideoInformation_id`),
CONSTRAINT `fk_VideoStatistics_VideoInformation1`
FOREIGN KEY (`VideoInformation_id`)
REFERENCES `youtubemd`.`VideoInformation` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
CHECKSUM = 1;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`DownloadStatistics`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`DownloadStatistics` (
`timesRequested` INT NOT NULL DEFAULT 0,
`DownloadInformation_file_id` VARCHAR(50) NOT NULL,
PRIMARY KEY (`DownloadInformation_file_id`),
CONSTRAINT `fk_DownloadStatistics_DownloadInformation1`
FOREIGN KEY (`DownloadInformation_file_id`)
REFERENCES `youtubemd`.`DownloadInformation` (`file_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
CHECKSUM = 1;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`Playlist`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`Playlist` (
`id` VARCHAR(60) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
CHECKSUM = 1;
SHOW WARNINGS;
CREATE UNIQUE INDEX `id_UNIQUE` ON `youtubemd`.`Playlist` (`id` ASC) VISIBLE;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`Playlist_has_VideoInformation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`Playlist_has_VideoInformation` (
`Playlist_id` VARCHAR(60) NOT NULL,
`VideoInformation_id` VARCHAR(11) NOT NULL,
PRIMARY KEY (`Playlist_id`, `VideoInformation_id`),
CONSTRAINT `fk_Playlist_has_VideoInformation_Playlist1`
FOREIGN KEY (`Playlist_id`)
REFERENCES `youtubemd`.`Playlist` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Playlist_has_VideoInformation_VideoInformation1`
FOREIGN KEY (`VideoInformation_id`)
REFERENCES `youtubemd`.`VideoInformation` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
CHECKSUM = 1;
SHOW WARNINGS;
CREATE INDEX `fk_Playlist_has_VideoInformation_VideoInformation1_idx` ON `youtubemd`.`Playlist_has_VideoInformation` (`VideoInformation_id` ASC) VISIBLE;
SHOW WARNINGS;
CREATE INDEX `fk_Playlist_has_VideoInformation_Playlist1_idx` ON `youtubemd`.`Playlist_has_VideoInformation` (`Playlist_id` ASC) VISIBLE;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `youtubemd`.`PlaylistStatistics`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `youtubemd`.`PlaylistStatistics` (
`timesRequested` INT NOT NULL,
`Playlist_id` VARCHAR(60) NOT NULL,
PRIMARY KEY (`Playlist_id`),
CONSTRAINT `fk_PlaylistStatistics_Playlist1`
FOREIGN KEY (`Playlist_id`)
REFERENCES `youtubemd`.`Playlist` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
CHECKSUM = 1;
SHOW WARNINGS;
SET SQL_MODE[email protected]OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS[email protected]OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS[email protected]OLD_UNIQUE_CHECKS;
-- PostgreSQL model for YouTubeMDBot application
-- Created by Javinator9889 - thu, 24 October, 2019
-- Last modification: mon, 4 November, 2019
-- Version 1.1
-- DROP schema - only for testing
-- DROP SCHEMA IF EXISTS youtubemd CASCADE;
-- DROP TYPE IF EXISTS AFORMAT;
-- DROP TYPE IF EXISTS aquality;
-- DROP TYPE IF EXISTS behaviour;
-- Custom "enum" types
CREATE TYPE AFORMAT AS ENUM ('mp3', 'm4a', 'ogg');
CREATE TYPE AQUALITY AS ENUM ('128k', '96k');
CREATE TYPE BEHAVIOUR AS ENUM ('always', 'not_found', 'ask', 'never');
-- Create DB schema
CREATE SCHEMA IF NOT EXISTS youtubemd;
-- ---------------------------------------
-- Table User --
-- ---------------------------------------
CREATE TABLE IF NOT EXISTS youtubemd.User
(
"id" INT PRIMARY KEY NOT NULL,
"name" VARCHAR(45),
"tag" VARCHAR(45),
"lang" VARCHAR(2),
"first_access" date
);
-- ---------------------------------------------
-- Table Preferences --
-- ---------------------------------------------
CREATE TABLE IF NOT EXISTS youtubemd.Preferences
(
"audio_format" AFORMAT NOT NULL DEFAULT 'm4a',
"audio_quality" AQUALITY NOT NULL DEFAULT '128k',
"song_behaviour" BEHAVIOUR NOT NULL DEFAULT 'not_found',
"send_song_link" BOOLEAN DEFAULT False,
"user_id" INT NOT NULL,
PRIMARY KEY ("user_id"),
CONSTRAINT "fk_user_id"
FOREIGN KEY ("user_id")
REFERENCES youtubemd.User ("id")
ON DELETE CASCADE
ON UPDATE CASCADE
);
-- ------------------------------------------
-- Table YouTube --
-- ------------------------------------------
CREATE TABLE IF NOT EXISTS youtubemd.YouTube
(
"id" VARCHAR(11) UNIQUE NOT NULL,
"times_requested" INT NOT NULL DEFAULT 0,
PRIMARY KEY ("id")
);
-- ------------------------------------------
-- Table Metadata --
-- ------------------------------------------
CREATE TABLE IF NOT EXISTS youtubemd.Metadata
(
"id" BIGSERIAL NOT NULL,
"artist" VARCHAR(45) NOT NULL,
"album" VARCHAR(45) NOT NULL,
"cover" BYTEA NOT NULL,
"release_id" VARCHAR(36),
"recording_id" VARCHAR(36),
"duration" INT,
"title" VARCHAR(45),
"custom_metadata" BOOLEAN,
PRIMARY KEY ("id")
);
-- ----------------------------------------------------
-- Relation between YouTube and Metadata --
-- ----------------------------------------------------
CREATE TABLE IF NOT EXISTS youtubemd.Video_Has_Metadata
(
"id" VARCHAR(11) NOT NULL,
"metadata_id" INT NOT NULL,
PRIMARY KEY ("id", "metadata_id"),
CONSTRAINT "fk_video_id"
FOREIGN KEY ("id")
REFERENCES youtubemd.YouTube ("id"),
CONSTRAINT "fk_metadata_id"
FOREIGN KEY ("metadata_id")
REFERENCES youtubemd.Metadata ("id")
);
-- --------------------------------------
-- Table File --
-- --------------------------------------
CREATE TABLE IF NOT EXISTS youtubemd.File
(
"id" VARCHAR(50) UNIQUE NOT NULL,
"metadata_id" INT UNIQUE NOT NULL,
"audio_quality" AQUALITY NOT NULL,
"size" INT,
PRIMARY KEY ("id", "metadata_id"),
CONSTRAINT "fk_metadata_id"
FOREIGN KEY ("metadata_id")
REFERENCES youtubemd.Metadata ("id")
);
-- -----------------------------------------
-- Table History --
-- -----------------------------------------
CREATE TABLE IF NOT EXISTS youtubemd.History
(
"id" BIGSERIAL NOT NULL,
"file_id" VARCHAR(50) NOT NULL,
"user_id" INT NOT NULL,
"metadata_id" INT NOT NULL,
"date" date,
PRIMARY KEY ("id", "file_id", "user_id", "metadata_id"),
CONSTRAINT "fk_user_id"
FOREIGN KEY ("user_id")
REFERENCES youtubemd.User ("id")
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT "fk_file_id"
FOREIGN KEY ("file_id")
REFERENCES youtubemd.File ("id"),
CONSTRAINT "fk_metadata_id"
FOREIGN KEY ("metadata_id")
REFERENCES youtubemd.Metadata ("id")
);
-- ------------------------------------------
-- Table Playlist --
-- ------------------------------------------
CREATE TABLE IF NOT EXISTS youtubemd.Playlist
(
"id" VARCHAR(22) NOT NULL UNIQUE,
PRIMARY KEY ("id")
);
-- ----------------------------------------------
-- Table YouTube stats --
-- ----------------------------------------------
CREATE TABLE IF NOT EXISTS youtubemd.YouTubeStats
(
"id" VARCHAR(11) NOT NULL UNIQUE,
"daily_requests" INT NOT NULL DEFAULT 1,
"weekly_requests" INT NOT NULL DEFAULT 1,
"monthly_requests" INT NOT NULL DEFAULT 1,
PRIMARY KEY ("id"),
CONSTRAINT "fk_youtube_id"
FOREIGN KEY ("id")
REFERENCES youtubemd.YouTube ("id")
);
-- Additional indexes
CREATE INDEX youtubemd.user_preferences_ix ON youtubemd.Preferences ("user_id");
CREATE INDEX youtubemd.video_metadata_ix ON youtubemd.Video_Has_Metadata ("id", "metadata_id");
CREATE INDEX youtubemd.history_ix ON youtubemd.History ("id", "file_id", "user_id", "metadata_id");
-- Trigger that updated the different stats
CREATE FUNCTION youtubemd.process_stats() RETURNS trigger AS
$$
DECLARE
daily_value INT;
weekly_value INT;
monthly_value INT;
BEGIN
IF (SELECT EXISTS(SELECT 1 FROM youtubemd.YouTubeStats WHERE youtubemd.YouTubeStats.id = NEW.id)) THEN
SELECT INTO daily_value, weekly_value, monthly_value youtubemd.YouTubeStats.daily_requests,
youtubemd.YouTubeStats.weekly_requests,
youtubemd.YouTubeStats.monthly_requests
FROM youtubemd.YouTubeStats
WHERE youtubemd.YouTubeStats.id = NEW.id;
daily_value = daily_value + 1;
weekly_value = weekly_value + 1;
monthly_value = monthly_value + 1;
UPDATE youtubemd.YouTubeStats
SET daily_requests = daily_value,
weekly_requests = weekly_value,
monthly_requests = monthly_value
WHERE id = NEW.id;
ELSE
INSERT INTO youtubemd.YouTubeStats (id) VALUES (NEW.id);
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Complementary functions with useful operations
CREATE FUNCTION youtubemd.top_10_daily()
RETURNS TABLE
(
id VARCHAR(11),
daily_requests INT
)
AS
$$
BEGIN
RETURN QUERY SELECT DISTINCT youtubemd.YouTubeStats.id, youtubemd.YouTubeStats.daily_requests
FROM youtubemd.youtubestats
ORDER BY daily_requests DESC
FETCH FIRST 10 ROWS ONLY;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION youtubemd.top_10_weekly()
RETURNS TABLE
(
id VARCHAR(11),
weekly_requests INT
)
AS
$$
BEGIN
RETURN QUERY SELECT DISTINCT youtubemd.YouTubeStats.id, youtubemd.YouTubeStats.weekly_requests
FROM youtubemd.youtubestats
ORDER BY weekly_requests DESC
FETCH FIRST 10 ROWS ONLY;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION youtubemd.top_10_monthly()
RETURNS TABLE
(
id VARCHAR(11),
monthly_requests INT
)
AS
$$
BEGIN
RETURN QUERY SELECT DISTINCT youtubemd.YouTubeStats.id, youtubemd.YouTubeStats.monthly_requests
FROM youtubemd.youtubestats
ORDER BY monthly_requests DESC
FETCH FIRST 10 ROWS ONLY;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION youtubemd.clear_daily_stats() AS
$$
BEGIN
UPDATE youtubemd.YouTubeStats SET daily_requests = 0;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION youtubemd.clear_weekly_stats() AS
$$
BEGIN
UPDATE youtubemd.YouTubeStats SET weekly_requests = 0;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION youtubemd.clear_monthly_stats() AS
$$
BEGIN
UPDATE youtubemd.YouTubeStats SET monthly_requests = 0;
END;
$$ LANGUAGE plpgsql;
-- Init the trigger
CREATE TRIGGER stats_update
AFTER INSERT OR UPDATE
ON youtubemd.YouTube
FOR EACH ROW
EXECUTE PROCEDURE youtubemd.process_stats();
This source diff could not be displayed because it is too large. You can view the blob instead.
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
# Default ignored files
/workspace.xml
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
\ No newline at end of file
<component name="ProjectDictionaryState">
<dictionary name="javinator9889">
<words>
<w>acoustid</w>
<w>ffmpeg</w>
<w>fpcalc</w>
<w>javinator</w>
</words>
</dictionary>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxProjectSettings">
<option name="version" value="2" />
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/YouTubeMDBot.iml" filepath="$PROJECT_DIR$/.idea/YouTubeMDBot.iml" />
</modules>
</component>
</project>
\ No newline at end of file