示例#1
0
    def transcode_upload_lossless(self):
        print "Will transcode {0}".format(self.what_id)

        self.what_torrent = self.what.request("torrent", id=self.what_id)["response"]
        what_group_id = self.what_torrent["group"]["id"]
        self.what_group = self.what.request("torrentgroup", id=what_group_id)["response"]

        if self.what_torrent["torrent"]["format"] != "FLAC":
            raise Exception("Cannot transcode a non-FLAC torrent.")
        if not self.force_warnings and torrent_is_preemphasized(self.what_torrent):
            raise Exception("Cannot transcode a pre-emphasized torrent!")
        # if not self.force_warnings and self.what_torrent['torrent']['reported']:
        # raise Exception('Cannot transcode a reported torrent!')
        if not self.force_warnings and self.what_torrent["torrent"]["scene"]:
            raise Exception("Cannot transcode a scene torrent due to possible release group name in the file names.")

        mp3_ids = get_mp3_ids(self.what_group, self.what_torrent)
        if self.force_v0 and "V0" in mp3_ids:
            del mp3_ids["V0"]
        if self.force_320 and "320" in mp3_ids:
            del mp3_ids["320"]
        for bitrate in ["V0", "320"]:
            if not bitrate in mp3_ids:
                single_job = TranscodeSingleJob(
                    self.what, self.what_torrent, self.report_progress, self.source_dir, bitrate
                )
                single_job.force_warnings = self.force_warnings
                single_job.run()
                print "Uploaded {0}".format(bitrate.upper())
示例#2
0
    def transcode_upload_lossless(self):
        print 'Will transcode {0}'.format(self.what_id)

        self.what_torrent = self.what.request('torrent', id=self.what_id)['response']
        what_group_id = self.what_torrent['group']['id']
        self.what_group = self.what.request('torrentgroup', id=what_group_id)['response']

        if self.what_torrent['torrent']['format'] != 'FLAC':
            raise Exception('Cannot transcode a non-FLAC torrent.')
        if not self.force_warnings and torrent_is_preemphasized(self.what_torrent):
            raise Exception('Cannot transcode a pre-emphasized torrent!')
        # if not self.force_warnings and self.what_torrent['torrent']['reported']:
        # raise Exception('Cannot transcode a reported torrent!')
        if not self.force_warnings and self.what_torrent['torrent']['scene']:
            raise Exception('Cannot transcode a scene torrent due to possible release group name '
                            'in the file names.')

        mp3_ids = get_mp3_ids(self.what_group, self.what_torrent)
        if self.force_v0 and 'V0' in mp3_ids:
            del mp3_ids['V0']
        if self.force_320 and '320' in mp3_ids:
            del mp3_ids['320']
        for bitrate in TRANSCODER_FORMATS:
            if bitrate not in mp3_ids:
                single_job = TranscodeSingleJob(self.what, self.what_torrent, self.report_progress,
                                                self.source_dir,
                                                bitrate)
                single_job.force_warnings = self.force_warnings
                single_job.run()
                print 'Uploaded {0}'.format(bitrate.upper())
示例#3
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)
        }
示例#4
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)}
示例#5
0
 def test_get_mp3_ids(self):
     what_group = {
         'torrents': [
             {
                 'id': 0,
                 'format': 'FLAC',
                 'encoding': 'Lossless',
                 'media': 'CD',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 1,
                 'format': 'MP3',
                 'encoding': '320',
                 'media': 'CD',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 2,
                 'format': 'FLAC',
                 'encoding': 'Lossless',
                 'media': 'CD',
                 'remastered': True,
                 'remasterCatalogueNumber': 'catno',
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 3,
                 'format': 'FLAC',
                 'encoding': 'Lossless',
                 'media': 'WEB',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 4,
                 'format': 'MP3',
                 'encoding': 'V0 (VBR)',
                 'media': 'WEB',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 5,
                 'format': 'MP3',
                 'encoding': 'V2 (VBR)',
                 'media': 'WEB',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
         ]
     }
     self.assertEqual(
         get_mp3_ids(what_group, {'torrent': what_group['torrents'][0]}),
         {'320': 1})
     self.assertEqual(
         get_mp3_ids(what_group, {'torrent': what_group['torrents'][2]}),
         {})
     self.assertEqual(
         get_mp3_ids(what_group, {'torrent': what_group['torrents'][3]}), {
             'V0': 4,
             'V2': 5
         })
示例#6
0
 def test_get_mp3_ids(self):
     what_group = {
         'torrents': [
             {
                 'id': 0,
                 'format': 'FLAC',
                 'encoding': 'Lossless',
                 'media': 'CD',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 1,
                 'format': 'MP3',
                 'encoding': '320',
                 'media': 'CD',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 2,
                 'format': 'FLAC',
                 'encoding': 'Lossless',
                 'media': 'CD',
                 'remastered': True,
                 'remasterCatalogueNumber': 'catno',
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 3,
                 'format': 'FLAC',
                 'encoding': 'Lossless',
                 'media': 'WEB',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 4,
                 'format': 'MP3',
                 'encoding': 'V0 (VBR)',
                 'media': 'WEB',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
             {
                 'id': 5,
                 'format': 'MP3',
                 'encoding': 'V2 (VBR)',
                 'media': 'WEB',
                 'remastered': False,
                 'remasterCatalogueNumber': None,
                 'remasterRecordLabel': None,
                 'remasterTitle': None,
                 'remasterYear': None,
             },
         ]
     }
     self.assertEqual(get_mp3_ids(what_group, {
         'torrent': what_group['torrents'][0]
     }), {'320': 1})
     self.assertEqual(get_mp3_ids(what_group, {
         'torrent': what_group['torrents'][2]
     }), {})
     self.assertEqual(get_mp3_ids(what_group, {
         'torrent': what_group['torrents'][3]
     }), {'V0': 4, 'V2': 5})