Esempio n. 1
0
def update(request):
    for t_r in TranscodeRequest.objects.filter(celery_task_id=None):
        t_torrent = get_trans_torrent(t_r.what_torrent)
        t_torrent.sync_t_torrent()
        if t_torrent.torrent_done == 1:
            run_transcode_task(t_r)

    for t_r in TranscodeRequest.objects.filter(date_completed=None).exclude(celery_task_id=None):
        result = AsyncResult(t_r.celery_task_id)
        if result.successful():
            t_r.date_completed = timezone.now()
            t_r.save()

    return HttpResponse('')
Esempio n. 2
0
def update(request):
    for t_r in TranscodeRequest.objects.filter(celery_task_id=None):
        t_torrent = get_trans_torrent(t_r.what_torrent)
        t_torrent.sync_t_torrent()
        if t_torrent.torrent_done == 1:
            run_transcode_task(t_r)

    for t_r in TranscodeRequest.objects.filter(date_completed=None).exclude(
            celery_task_id=None):
        result = AsyncResult(t_r.celery_task_id)
        if result.successful():
            t_r.date_completed = timezone.now()
            t_r.save()

    return HttpResponse('')
Esempio n. 3
0
    def process_request(t_r):
        t_r.show_retry_button = False

        if t_r.celery_task_id is None:
            try:
                t_torrent = get_trans_torrent(t_r.what_torrent)
                t_torrent.sync_t_torrent()
                if t_torrent.torrent_done == 1:
                    t_r.status = 'download complete. transcoding should start within 1 minute.'
                else:
                    t_r.status = 'downloading ({0:.0%})'.format(
                        t_torrent.torrent_done)
                downloading.append(t_r)
            except TransTorrent.DoesNotExist:
                t_r.status = 'torrent has been removed'
                failed.append(t_r)
        elif t_r.date_completed is not None:
            t_r.status = 'completed {0} ago'.format(
                timesince_filter(t_r.date_completed))
            succeeded.append(t_r)
        else:
            async_result = AsyncResult(t_r.celery_task_id)
            if async_result.state == states.PENDING:
                t_r.status = 'pending transcoding'
                pending.append(t_r)
            elif async_result.state == states.STARTED:
                t_r.status = 'transcoding'
                transcoding.append(t_r)
            elif async_result.state == 'PROGRESS':
                t_r.status = 'transcoding: {0}'.format(
                    async_result.info['status_message'])
                transcoding.append(t_r)
            elif async_result.state == states.SUCCESS:
                t_r.status = 'completed'
                succeeded.append(t_r)
            elif async_result.state == states.FAILURE:
                t_r.show_retry_button = allow_retry
                t_r.status = 'failed - {0}({1})'.format(
                    type(async_result.result).__name__,
                    async_result.result.message)
                failed.append(t_r)
        what_client = get_what_client(request)
        t_r.status = t_r.status.replace(what_client.authkey,
                                        '<authkey>').replace(
                                            what_client.passkey, '<passkey>')
Esempio n. 4
0
    def process_request(t_r):
        t_r.show_retry_button = False

        if t_r.celery_task_id is None:
            try:
                t_torrent = get_trans_torrent(t_r.what_torrent)
                t_torrent.sync_t_torrent()
                if t_torrent.torrent_done == 1:
                    t_r.status = 'download complete. transcoding should start within 1 minute.'
                else:
                    t_r.status = 'downloading ({0:.0%})'.format(t_torrent.torrent_done)
                downloading.append(t_r)
            except TransTorrent.DoesNotExist:
                t_r.status = 'torrent has been removed'
                failed.append(t_r)
        elif t_r.date_completed is not None:
            t_r.status = 'completed {0} ago'.format(timesince_filter(t_r.date_completed))
            succeeded.append(t_r)
        else:
            async_result = AsyncResult(t_r.celery_task_id)
            if async_result.state == states.PENDING:
                t_r.status = 'pending transcoding'
                pending.append(t_r)
            elif async_result.state == states.STARTED:
                t_r.status = 'transcoding'
                transcoding.append(t_r)
            elif async_result.state == 'PROGRESS':
                t_r.status = 'transcoding: {0}'.format(async_result.info['status_message'])
                transcoding.append(t_r)
            elif async_result.state == states.SUCCESS:
                t_r.status = 'completed'
                succeeded.append(t_r)
            elif async_result.state == states.FAILURE:
                t_r.show_retry_button = allow_retry
                t_r.status = 'failed - {0}({1})'.format(type(async_result.result).__name__,
                                                        async_result.result.message)
                failed.append(t_r)
        what_client = get_what_client(request)
        t_r.status = t_r.status.replace(what_client.authkey, '<authkey>').replace(
            what_client.passkey, '<passkey>')
Esempio n. 5
0
def request_transcode(request):
    try:
        request_what_user = request_get_what_user(request)
    except Exception:
        return {
            'message': 'You don\'t have permission to add transcode requests.'
        }

    try:
        what_id = int(request.POST['what_id'])
    except:
        return {
            'message': 'Missing or invalid what id'
        }

    try:
        try:
            TranscodeRequest.objects.get(what_torrent_id=what_id)
            return {
                'message': 'This has already been requested.'
            }
        except TranscodeRequest.DoesNotExist:
            pass

        what_client = get_what_client(request)

        what_torrent = WhatTorrent.get_or_create(request, what_id=what_id)
        if what_torrent.info_loads['torrent']['format'] != 'FLAC':
            return {
                'message': 'This is not a FLAC torrent. Only FLACs can be transcoded.'
            }
        if what_torrent.info_loads['torrent']['reported']:
            return {
                'message': 'You cannot add a request for a torrent that has been reported.'
            }
        if what_torrent.info_loads['torrent']['scene']:
            return {
                'message': 'Cannot transcode a scene torrent due to possible release group name in the file names.'
            }
        if torrent_is_preemphasized(what_torrent.info_loads):
            return {
                'message': 'This sounds as if it is pre-emphasized. Will not add request.'
            }

        group = what_client.request('torrentgroup', id=what_torrent.info_loads['group']['id'])['response']

        mp3_ids = get_mp3_ids(group, what_torrent.info_loads)

        if '320' in mp3_ids and 'V0' in mp3_ids:
            return {
                'message': 'This torrent already has both a V0 and a 320.'
            }

        transcode_request = TranscodeRequest(
            what_torrent=what_torrent,
            requested_by_ip=request.META['REMOTE_ADDR'],
            requested_by_what_user=request_what_user,
        )
        transcode_request.save()

        try:
            get_trans_torrent(what_torrent)
        except TransTorrent.DoesNotExist:
            instance = ReplicaSet.get_what_master().get_preferred_instance()
            download_location = DownloadLocation.get_what_preferred()
            m_torrent = add_torrent(request, instance, download_location, what_id)
            if request.user.is_authenticated():
                m_torrent.what_torrent.added_by = request.user
            else:
                m_torrent.what_torrent.added_by = None
            m_torrent.what_torrent.tags = 'transcode'
            m_torrent.what_torrent.save()

            if request.user.is_authenticated():
                log_user = request.user
            else:
                log_user = None
            LogEntry.add(log_user, u'action', u'Transcode What.CD user {0} added {1} to {2}'.format(request_what_user, m_torrent, m_torrent.instance))

        return {
            'message': 'Request added.',
        }
    except Exception as ex:
        tb = traceback.format_exc()
        if request.user.is_authenticated():
            current_user = request.user
        else:
            current_user = None
        LogEntry.add(current_user, u'error', u'What user {0} tried adding what_id {1}. Error: {2}'.format(request_what_user, what_id, ex), tb)
        return {
            'message': 'Error adding request: ' + str(ex)
        }
Esempio n. 6
0
def run_request_transcode(request, what_id):
    try:
        request_what_user = request_get_what_user(request)
    except Exception:
        return {
            'message': 'You don\'t have permission to add transcode requests.'
        }

    try:
        what_id = int(what_id)
    except:
        return {'message': 'Missing or invalid what id'}

    try:
        try:
            TranscodeRequest.objects.get(what_torrent_id=what_id)
            return {'message': 'This has already been requested.'}
        except TranscodeRequest.DoesNotExist:
            pass

        what_client = get_what_client(request)

        what_torrent = WhatTorrent.get_or_create(request, what_id=what_id)
        if what_torrent.info_loads['torrent']['format'] != 'FLAC':
            return {
                'message':
                'This is not a FLAC torrent. Only FLACs can be transcoded.'
            }
        if what_torrent.info_loads['torrent']['reported']:
            return {
                'message':
                'You cannot add a request for a torrent that has been reported.'
            }
        if what_torrent.info_loads['torrent']['scene']:
            return {
                'message':
                'Cannot transcode a scene torrent due to possible'
                ' release group name in the file names.'
            }
        if torrent_is_preemphasized(what_torrent.info_loads):
            return {
                'message':
                'This sounds as if it is pre-emphasized. Will not add request.'
            }

        group = what_client.request(
            'torrentgroup',
            id=what_torrent.info_loads['group']['id'])['response']

        mp3_ids = get_mp3_ids(group, what_torrent.info_loads)

        if all(f in mp3_ids for f in TRANSCODER_FORMATS):
            return {
                'message':
                'This torrent already has all the formats: {0}.'.format(
                    ', '.join(TRANSCODER_FORMATS))
            }

        transcode_request = TranscodeRequest(
            what_torrent=what_torrent,
            requested_by_ip=request.META['REMOTE_ADDR'],
            requested_by_what_user=request_what_user,
        )
        transcode_request.save()

        try:
            get_trans_torrent(what_torrent)
        except TransTorrent.DoesNotExist:
            instance = ReplicaSet.get_what_master().get_preferred_instance()
            download_location = DownloadLocation.get_what_preferred()
            m_torrent = add_torrent(request, instance, download_location,
                                    what_id)
            if request.user.is_authenticated():
                m_torrent.what_torrent.added_by = request.user
            else:
                m_torrent.what_torrent.added_by = None
            m_torrent.what_torrent.tags = 'transcode'
            m_torrent.what_torrent.save()

            if request.user.is_authenticated():
                log_user = request.user
            else:
                log_user = None
            LogEntry.add(
                log_user, u'action',
                u'Transcode What.CD user {0} added {1} to {2}'.format(
                    request_what_user, m_torrent, m_torrent.instance))

        return {
            'message': 'Request added.',
        }
    except Exception as ex:
        tb = traceback.format_exc()
        if request.user.is_authenticated():
            current_user = request.user
        else:
            current_user = None
        LogEntry.add(
            current_user, u'error',
            u'What user {0} tried adding what_id {1}. Error: {2}'.format(
                request_what_user, what_id, ex), tb)
        return {'message': 'Error adding request: ' + str(ex)}