def test_ask_create_no(self): item = self.add_track() with control_stdin('n'): out = self.runcli('alt', 'update', 'myexternal') self.assertIn('Skipping creation of', out) item.load() self.assertNotIn('alt.myexternal', item)
def test_transcode_from_lossy(self): self.config['convert']['never_convert_lossy_files'] = False [item] = self.add_item_fixtures(ext='ogg') with control_stdin('y'): self.run_command('convert', item.path) converted = os.path.join(self.convert_dest, 'converted.mp3') self.assertFileTag(converted, 'mp3')
def test_ask_create_yes(self): item = self.add_track() with control_stdin('y'): out = self.runcli('alt', 'update', 'myexternal') self.assertIn('Do you want to create the collection?', out) item.load() self.assertIn('alt.myexternal', item)
def test_convert_ogg_to_mp3_prevented(self): with control_stdin('y'): self.run_command('convert', self.album_ogg.items()[0].path) mp3path = os.path.join(self.convert_dest, 'converted.mp3') oggpath = os.path.join(self.convert_dest, 'converted.ogg') self.assertFalse(os.path.isfile(mp3path)) self.assertTrue(os.path.isfile(oggpath))
def test_external(self): external_dir = os.path.join(self.mkdtemp(), 'myplayer') self.config['convert']['formats'] = { 'aac': { 'command': 'bash -c "cp \'$source\' \'$dest\';' + 'printf ISAAC >> \'$dest\'"', 'extension': 'm4a' }, } self.config['alternatives'] = { 'myplayer': { 'directory': external_dir, 'paths': { 'default': u'$artist/$title' }, 'formats': u'aac mp3', 'query': u'onplayer:true', 'removable': True, } } self.add_album(artist='Bach', title='was mp3', format='mp3') self.add_album(artist='Bach', title='was m4a', format='m4a') self.add_album(artist='Bach', title='was ogg', format='ogg') self.add_album(artist='Beethoven', title='was ogg', format='ogg') external_from_mp3 = bytestring_path( os.path.join(external_dir, 'Bach', 'was mp3.mp3')) external_from_m4a = bytestring_path( os.path.join(external_dir, 'Bach', 'was m4a.m4a')) external_from_ogg = bytestring_path( os.path.join(external_dir, 'Bach', 'was ogg.m4a')) external_beet = bytestring_path( os.path.join(external_dir, 'Beethoven', 'was ogg.m4a')) self.runcli('modify', '--yes', 'onplayer=true', 'artist:Bach') with control_stdin('y'): out = self.runcli('alt', 'update', 'myplayer') self.assertIn('Do you want to create the collection?', out) self.assertNotFileTag(external_from_mp3, b'ISAAC') self.assertNotFileTag(external_from_m4a, b'ISAAC') self.assertFileTag(external_from_ogg, b'ISAAC') self.assertFalse(os.path.isfile(external_beet)) self.runcli('modify', '--yes', 'composer=JSB', 'artist:Bach') self.runcli('alt', 'update', 'myplayer') mediafile = MediaFile(external_from_ogg) self.assertEqual(mediafile.composer, 'JSB') self.runcli('modify', '--yes', 'onplayer!', 'artist:Bach') self.runcli('modify', '--album', '--yes', 'onplayer=true', 'albumartist:Beethoven') self.runcli('alt', 'update', 'myplayer') self.assertFalse(os.path.isfile(external_from_mp3)) self.assertFalse(os.path.isfile(external_from_m4a)) self.assertFalse(os.path.isfile(external_from_ogg)) self.assertFileTag(external_beet, b'ISAAC')
def test_not_removable(self): item = self.add_track() self.external_config['removable'] = False with control_stdin('y'): out = self.runcli('alt', 'update', 'myexternal') self.assertNotIn('Do you want to create the collection?', out) item.load() self.assertIn('alt.myexternal', item)
def test_convert_keep_new(self): self.assertEqual(os.path.splitext(self.item.path)[1], '.ogg') with control_stdin('y'): self.run_command('convert', '--keep-new', self.item.path) self.item.load() self.assertEqual(os.path.splitext(self.item.path)[1], '.mp3')
def test_external(self): external_dir = os.path.join(self.mkdtemp(), 'myplayer') self.config['convert']['formats'] = { 'aac': { 'command': 'bash -c "cp \'$source\' \'$dest\';' + 'printf ISAAC >> \'$dest\'"', 'extension': 'm4a' }, } self.config['alternatives'] = { 'myplayer': { 'directory': external_dir, 'paths': {'default': '$artist/$title'}, 'formats': 'aac mp3', 'query': 'onplayer:true', 'removable': True, } } self.add_album(artist='Bach', title='was mp3', format='mp3') self.add_album(artist='Bach', title='was m4a', format='m4a') self.add_album(artist='Bach', title='was ogg', format='ogg') self.add_album(artist='Beethoven', title='was ogg', format='ogg') external_from_mp3 = os.path.join(external_dir, 'Bach', 'was mp3.mp3') external_from_m4a = os.path.join(external_dir, 'Bach', 'was m4a.m4a') external_from_ogg = os.path.join(external_dir, 'Bach', 'was ogg.m4a') external_beet = os.path.join(external_dir, 'Beethoven', 'was ogg.m4a') self.runcli('modify', '--yes', 'onplayer=true', 'artist:Bach') with control_stdin('y'): out = self.runcli('alt', 'update', 'myplayer') self.assertIn('Do you want to create the collection?', out) self.assertNotFileTag(external_from_mp3, 'ISAAC') self.assertNotFileTag(external_from_m4a, 'ISAAC') self.assertFileTag(external_from_ogg, 'ISAAC') self.assertFalse(os.path.isfile(external_beet)) self.runcli('modify', '--yes', 'composer=JSB', 'artist:Bach') self.runcli('alt', 'update', 'myplayer') mediafile = MediaFile(external_from_ogg) self.assertEqual(mediafile.composer, 'JSB') self.runcli('modify', '--yes', 'onplayer!', 'artist:Bach') self.runcli('modify', '--album', '--yes', 'onplayer=true', 'albumartist:Beethoven') self.runcli('alt', 'update', 'myplayer') self.assertFalse(os.path.isfile(external_from_mp3)) self.assertFalse(os.path.isfile(external_from_m4a)) self.assertFalse(os.path.isfile(external_from_ogg)) self.assertFileTag(external_beet, 'ISAAC')
def test_embed_album_art(self): self.config['convert']['embed'] = True image_path = os.path.join(_common.RSRC, 'image-2x3.jpg') self.album.artpath = image_path self.album.store() with open(os.path.join(image_path)) as f: image_data = f.read() with control_stdin('y'): self.run_command('convert', self.item.path) converted = os.path.join(self.convert_dest, 'converted.mp3') mediafile = MediaFile(converted) self.assertEqual(mediafile.images[0].data, image_data)
def test_transcode_from_lossy_prevented(self): [item] = self.add_item_fixtures(ext='ogg') with control_stdin('y'): self.run_command('convert', item.path) converted = os.path.join(self.convert_dest, 'converted.ogg') self.assertNoFileTag(converted, 'mp3')
def test_format_option(self): with control_stdin('y'): self.run_command('convert', '--format', 'opus', self.item.path) converted = os.path.join(self.convert_dest, 'converted.ops') self.assertFileTag(converted, 'opus')
def test_rejecet_confirmation(self): with control_stdin('n'): self.run_command('convert', self.item.path) converted = os.path.join(self.convert_dest, 'converted.mp3') self.assertFalse(os.path.isfile(converted))
def test_convert(self): with control_stdin('y'): self.run_command('convert', self.item.path) converted = os.path.join(self.convert_dest, 'converted.mp3') self.assertFileTag(converted, 'mp3')
def modify(self, *args): with control_stdin("y"): ui._raw_main(["modify"] + list(args), self.lib)
def modify(self, *args): with control_stdin('y'): ui._raw_main(['modify'] + list(args), self.lib)
def test_convert_flac_to_mp3_works(self): with control_stdin('y'): self.run_command('convert', self.album_flac.items()[0].path) mp3path = os.path.join(self.convert_dest, 'converted.mp3') self.assertTrue(os.path.isfile(mp3path))