<commit_before>import logging
from celery.task import task
from videos.models import VideoUrl
from videos.types import UPDATE_VERSION_ACTION
from auth.models import CustomUser as User
from models import ThirdPartyAccount


logger = logging.getLogger(__name__)


def get_youtube_data(user_pk):
    """
    Get data for all videos with completed languages.

    Return a list of 3-tuples like this

        (video, language, version,)

    """
    try:
        user = User.objects.get(pk=user_pk)
    except User.DoesNotExist:
        logger.error('User with PK %s not found' % user_pk)
        return

    usernames = [a.username for a in user.third_party_accounts.all()]
    urls = VideoUrl.objects.filter(owner_username__in=usernames)
    videos = [url.video for url in urls]

    data = []

    for video in videos:
        languages = video.completed_subtitle_languages()

        for language in languages:
            version = language.latest_version()
            data.append((video, language, version,))

    return data


@task()
def mirror_existing_youtube_videos(user_pk):
    data = get_youtube_data(user_pk)
<commit_msg>Don't die if there is no data<commit_after>import logging
from celery.task import task
from videos.models import VideoUrl
from videos.types import UPDATE_VERSION_ACTION
from auth.models import CustomUser as User
from models import ThirdPartyAccount


logger = logging.getLogger(__name__)


def get_youtube_data(user_pk):
    """
    Get data for all videos with completed languages.

    Return a list of 3-tuples like this

        (video, language, version,)

    """
    try:
        user = User.objects.get(pk=user_pk)
    except User.DoesNotExist:
        logger.error('User with PK %s not found' % user_pk)
        return

    usernames = [a.username for a in user.third_party_accounts.all()]
    urls = VideoUrl.objects.filter(owner_username__in=usernames)
    videos = [url.video for url in urls]

    data = []

    for video in videos:
        languages = video.completed_subtitle_languages()

        for language in languages:
            version = language.latest_version()
            data.append((video, language, version,))

    return data


@task()
def mirror_existing_youtube_videos(user_pk):
    data = get_youtube_data(user_pk)

    if not data:
        return

{'fraction_non_alphanumeric': 0.0794816414686825, 'fraction_numerical': 0.0008639308855291577, 'mean_word_length': 3.150537634408602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3486616', 'n_tokens_mistral': 699, 'n_tokens_neox': 666, 'n_words': 202}