Script to claim isrc and insert track
===============

### Use

This script is used as part of cleanup after a BACON outage. It is invoked usually via a jenkins job, https://scheduler.theorchard.io/job/bacon-claim-isrc/

 See https://docs.google.com/document/d/14oOux_zP2lOOefLfhGvxoAh0TIKWeZH_5uj7AI77RLo/edit?usp=sharing for more details.

### Installation

```
cd bacon-create-track
pyvenv-3.6 venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
export FILENAME="data/yt_recent_assets_and_claims_missing_metadata.csv"
chmod 777 logs
cp .env.shadow .env
```
### Running the script 
``
python index.py
``
### CSV Format

The input csv should have the following columns:

| Column | Description |
| -------- | ------------- |
| ISRC | Should always be empty (if non-empty, row will be skipped)|
| CHANNEL_ID | Youtube channel id |
| VIDEO_TITLE | Title of Video |
| VIDEO_DURATION_SEC | Length of video in seconds |

### Example SQL 

The following Snowflake query (used to identify dmgi videos not claimed by BACON in a particular time period) gives an example of how to produce an input file.

```sql
SELECT
    yvr.isrc,
    yvr.channel_id,
    yvr.video_title,
    yvr.video_length video_duration_sec
FROM
    facts.prod.staging_raw_youtube_video_report yvr
    INNER JOIN facts.prod.staging_raw_youtube_asset_report yar 
        ON yar.asset_id = yvr.asset_id
    INNER JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.youtube_channel ych
        ON yvr.channel_id = ych.youtube_channel_id
    INNER JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.youtube_channel_cms_account_history yccah 
        ON yccah.id = ych.youtube_channel_cms_account_history_id
    INNER JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.youtube_channel_cms_account ycca 
        ON yccah.youtube_channel_cms_account_id = ycca.id
WHERE
    ych.auto_claim = 'yes'
    AND ycca.cmsa_content_owner = 'dmgi'
    AND yvr.video_id = yvr.custom_id
    AND yvr.time_uploaded BETWEEN '2021-02-22' AND '2021-03-06';
```