def download_album(celery_task, qobuz_album_id): try: qobuz_client = get_qobuz_client(lambda: None) qobuz_upload = QobuzUpload.objects.get(id=qobuz_album_id) assert len(qobuz_upload.album_data['tracks']['items']) == len(qobuz_upload.track_data) os.makedirs(qobuz_upload.temp_media_path) print 'Downloading images' if qobuz_upload.album_data['image']['back']: download_image(qobuz_upload, qobuz_upload.album_data['image']['back'], 'back.jpg') download_image(qobuz_upload, qobuz_upload.album_data['image']['large'], 'folder.jpg') print 'Download goodies' if 'goodies' in qobuz_upload.album_data: for i in xrange(len(qobuz_upload.album_data['goodies'])): download_goodie(qobuz_upload, i) print 'Downloading tracks' track_number = 0 media_number = 0 for i, track in enumerate(qobuz_upload.album_data['tracks']['items']): if track['media_number'] != media_number: track_number = 1 media_number = track['media_number'] download_track(qobuz_client, qobuz_upload, i, track_number) track_number += 1 print 'Generating torrent' generate_torrents(qobuz_upload) print 'Generating spectrals' os.makedirs(qobuz_upload.spectrals_path) for i in xrange(len(qobuz_upload.album_data['tracks']['items'])): generate_spectrals(qobuz_upload, i) qobuz_upload.track_data_json = ujson.dumps(qobuz_upload.track_data) recursive_chmod(qobuz_upload.temp_media_path, 0777) finally: connection.close()
def qiller_download(celery_task, qobuz_album_id): try: upload = QobuzUpload.objects.get(id=qobuz_album_id) qiller = upload.upload temp_dir = get_temp_dir(qiller.metadata.id) qiller.download(temp_dir, True) upload.set_upload(qiller) for item in os.listdir(temp_dir): recursive_chmod(os.path.join(temp_dir, item), 0777) upload.save() finally: connection.close()
def move_torrent_to_dest(self): print "Moving data to target location" os.remove(self.torrent_file_path) self.retrieve_new_torrent(self.new_torrent_info_hash) dest_path = os.path.join(dest_upload_dir, str(self.new_torrent["torrent"]["id"])) try: os.makedirs(dest_path) except OSError: raise Exception("Dest torrent directory already exists.") shutil.move(self.torrent_temp_dir, dest_path) recursive_chmod(dest_path, 0777)
def process(self): what_torrent_id = self.what_torrent['id'] if self.what_torrent_info['group']['categoryName'] != 'Music': print 'Skipping non-Music torrent', what_torrent_id return if self.flac_only and self.what_torrent_info['torrent']['format'] != 'FLAC': print 'Skipping non-FLAC torrent', what_torrent_id return try: status = WhatTorrentMigrationStatus.objects.get(what_torrent_id=what_torrent_id) if status.status == WhatTorrentMigrationStatus.STATUS_COMPLETE: print 'Skipping complete torrent', what_torrent_id return elif status.status == WhatTorrentMigrationStatus.STATUS_DUPLICATE: print 'Skipping duplicate torrent', what_torrent_id return elif status.status == WhatTorrentMigrationStatus.STATUS_SKIPPED: print 'Skipping skipped torrent', what_torrent_id return elif status.status == WhatTorrentMigrationStatus.STATUS_SKIPPED_PERMANENTLY: print 'Skipping permanently skipped torrent', what_torrent_id return elif status.status == WhatTorrentMigrationStatus.STATUS_FAILED_VALIDATION: print 'Skipping failed validation torrent', what_torrent_id return elif status.status == WhatTorrentMigrationStatus.STATUS_RESEEDED: print 'Skipping reseeded torrent', what_torrent_id return else: raise Exception('Not sure what to do with status {} on {}'.format( status.status, what_torrent_id)) except WhatTorrentMigrationStatus.DoesNotExist: pass if not self.check_valid(): return self.mktorrent() if not self.find_dupes(): return if not self.new_torrent: self.enhance_torrent_data() self.prepare_payload() self.print_info() self.prepare_payload_files() self.generate_spectrals() raw_input('Will perform upload (CHECK THE SPECTRALS)...') self.perform_upload() self.set_new_location() if self.REAL_RUN: os.makedirs(self.full_new_location) shutil.move(wm_str(self.torrent_dir_path), wm_str(self.full_new_location)) try: recursive_chmod(self.full_new_location, 0777) except OSError: print 'recursive_chmod failed' else: print 'os.makedirs({})'.format(self.full_new_location) print 'shutil.move({}, {})'.format(self.torrent_dir_path, self.full_new_location) print 'recursive_chmod({}, 0777)'.format(self.full_new_location) if self.REAL_RUN: self.add_to_wm() self.migration_status.status = WhatTorrentMigrationStatus.STATUS_COMPLETE self.migration_status.save() self.save_torrent_group_mapping() else: print 'add_to_wm()' print print