def test_modland_file(self): cybrev = Production.objects.get(title="Cybernoid's Revenge") link = ProductionLink(production=cybrev, is_download_link=True) link.url = 'https://files.exotica.org.uk/modland/?file=artists/gasman/cybernoids_revenge.zip' self.assertEqual(link.link_class, 'ModlandFile') self.assertEqual(link.parameter, '/artists/gasman/cybernoids_revenge.zip')
def test_sceneorg_file(self): pondlife = Production.objects.get(title='Pondlife') link = ProductionLink(production=pondlife, is_download_link=True) link.url = 'https://www.scene.org/file_dl.php?url=ftp%3A//ftp.scene.org/pub/parties/2001/forever01/pondlife.zip' self.assertEqual(link.link_class, 'SceneOrgFile') self.assertEqual(link.parameter, '/parties/2001/forever01/pondlife.zip') self.assertEqual( link.link.nl_url, 'ftp://ftp.scene.org/pub/parties/2001/forever01/pondlife.zip') self.assertEqual( link.link.download_url, 'ftp://ftp.scene.org/pub/parties/2001/forever01/pondlife.zip') self.assertEqual( link.link.nl_http_url, 'http://archive.scene.org/pub/parties/2001/forever01/pondlife.zip') self.assertEqual( link.link.nl_https_url, 'https://archive.scene.org/pub/parties/2001/forever01/pondlife.zip' ) link.url = 'https://www.scene.org/file_dl.php?foo=http%3A//example.com/pondlife.zip' self.assertEqual(link.link_class, 'BaseUrl') with self.assertRaises(TypeError): link.url = b'https://unicode.example.com/'
def test_discogs_release(self): cybrev = Production.objects.get(title="Cybernoid's Revenge") link = ProductionLink(production=cybrev, is_download_link=True) link.url = 'https://discogs.com/gasman/release/42' self.assertEqual(link.link_class, 'DiscogsRelease') self.assertEqual(link.parameter, '42/gasman') self.assertEqual(str(link.link), 'http://www.discogs.com/gasman/release/42')
def test_speccypl_production(self): pondlife = Production.objects.get(title='Pondlife') link = ProductionLink(production=pondlife, is_download_link=False) link.url = 'http://speccy.pl/archive/prod.php?id=14' self.assertEqual(link.link_class, 'SpeccyPlProduction') self.assertEqual(link.parameter, 14) self.assertEqual(str(link.link), 'http://speccy.pl/archive/prod.php?id=14')
def test_bandcamp_track(self): cybrev = Production.objects.get(title="Cybernoid's Revenge") link = ProductionLink(production=cybrev, is_download_link=True) link.url = 'https://gasman.bandcamp.com/track/cybernoids-revenge' self.assertEqual(link.link_class, 'BandcampTrack') self.assertEqual(link.parameter, 'gasman/cybernoids-revenge') self.assertEqual( str(link.link), 'https://gasman.bandcamp.com/track/cybernoids-revenge')
def test_github_directory(self): pondlife = Production.objects.get(title='Pondlife') link = ProductionLink(production=pondlife, is_download_link=False) link.url = 'http://github.com/gasman/demos/tree/main/pondlife' self.assertEqual(link.link_class, 'GithubDirectory') self.assertEqual(link.parameter, 'gasman/demos/main/pondlife') self.assertEqual(str(link.link), 'http://github.com/gasman/demos/tree/main/pondlife')
def test_modarchive_other_params(self): cybrev = Production.objects.get(title="Cybernoid's Revenge") link = ProductionLink(production=cybrev, is_download_link=True) link.url = 'https://modarchive.org/index.php?request=view_by_moduleid&query=123' self.assertEqual(link.link_class, 'ModarchiveModule') self.assertEqual(link.parameter, '123') link.url = 'https://modarchive.org/index.php?request=view_by_instrument&query=keytar' self.assertEqual(link.link_class, 'BaseUrl') link.url = 'https://modarchive.org/index.php?request=view_by_moduleid&whichone=123' self.assertEqual(link.link_class, 'BaseUrl')
def test_youtube_video(self): pondlife = Production.objects.get(title='Pondlife') link = ProductionLink(production=pondlife, is_download_link=False) link.url = 'https://www.youtube.com/watch?v=ldoVS0idTBw' self.assertEqual(link.link_class, 'YoutubeVideo') self.assertEqual(link.parameter, 'ldoVS0idTBw') self.assertEqual(str(link.link), 'https://www.youtube.com/watch?v=ldoVS0idTBw') link.url = 'https://www.youtube.com/watch?v=ldoVS0idTBw&t=250' self.assertEqual(link.link_class, 'YoutubeVideo') self.assertEqual(link.parameter, 'ldoVS0idTBw/250') self.assertEqual(str(link.link), 'https://www.youtube.com/watch?v=ldoVS0idTBw&t=250') link.url = 'https://www.youtu.be/ldoVS0idTBw' self.assertEqual(link.link_class, 'YoutubeVideo') self.assertEqual(link.parameter, 'ldoVS0idTBw') link.url = 'https://www.youtu.be/ldoVS0idTBw?t=250' self.assertEqual(link.link_class, 'YoutubeVideo') self.assertEqual(link.parameter, 'ldoVS0idTBw/250') link.url = 'https://www.youtube.com/embed/ldoVS0idTBw' self.assertEqual(link.link_class, 'YoutubeVideo') self.assertEqual(link.parameter, 'ldoVS0idTBw') link.url = 'https://www.youtube.com/embed/ldoVS0idTBw?start=250' self.assertEqual(link.link_class, 'YoutubeVideo') self.assertEqual(link.parameter, 'ldoVS0idTBw/250') link.url = 'https://www.youtube.com/watch?t=250' self.assertEqual(link.link_class, 'BaseUrl') self.assertEqual(link.parameter, 'https://www.youtube.com/watch?t=250')
def test_youtube(self): pondlife = Production.objects.get(title='Pondlife') link = ProductionLink(production=pondlife, is_download_link=False) link.url = 'https://www.youtube.com/watch?v=ldoVS0idTBw' oembed_url = link.link.get_oembed_url(max_width=800, max_height=600) self.assertTrue( oembed_url.startswith('https://www.youtube.com/oembed')) self.assertIn('format=json', oembed_url) self.assertIn('maxwidth=800', oembed_url) self.assertIn('maxheight=600', oembed_url) embed_data = link.link.get_embed_data() self.assertEqual(embed_data['video_width'], 1280) self.assertEqual(embed_data['video_height'], 720) self.assertEqual(embed_data['thumbnail_width'], 480) self.assertEqual(embed_data['thumbnail_height'], 360) embed_html = link.link.get_embed_html(640, 480) self.assertEqual( embed_html, '<iframe width="640" height="480" src="https://www.youtube.com/embed/ldoVS0idTBw?autoplay=1" ' 'frameborder="0" allowfullscreen></iframe>') link.url = 'https://www.youtube.com/watch?v=ldoVS0idTBw&t=60' self.assertEqual(link.parameter, 'ldoVS0idTBw/60') embed_html = link.link.get_embed_html(640, 480) self.assertEqual( embed_html, '<iframe width="640" height="480" src="https://www.youtube.com/embed/ldoVS0idTBw?start=60&autoplay=1" ' 'frameborder="0" allowfullscreen></iframe>') link.url = 'https://www.youtube.com/watch?v=ldoVS0idTBw&t=1m30' self.assertEqual(link.parameter, 'ldoVS0idTBw/1m30') embed_html = link.link.get_embed_html(640, 480) self.assertEqual( embed_html, '<iframe width="640" height="480" src="https://www.youtube.com/embed/ldoVS0idTBw?start=90&autoplay=1" ' 'frameborder="0" allowfullscreen></iframe>')
def test_vimeo(self): pondlife = Production.objects.get(title='Pondlife') link = ProductionLink(production=pondlife, is_download_link=False) link.url = 'https://vimeo.com/3156959' oembed_url = link.link.get_oembed_url(max_width=800, max_height=600) self.assertTrue( oembed_url.startswith('https://vimeo.com/api/oembed.json')) self.assertIn('maxwidth=800', oembed_url) self.assertIn('maxheight=600', oembed_url) embed_data = link.link.get_embed_data() self.assertEqual(embed_data['video_width'], 480) self.assertEqual(embed_data['video_height'], 270) self.assertEqual(embed_data['thumbnail_width'], 295) self.assertEqual(embed_data['thumbnail_height'], 166) embed_html = link.link.get_embed_html(640, 480) self.assertEqual( embed_html, """<iframe width="640" height="480" src="https://player.vimeo.com/video/3156959?autoplay=1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>""" )
def handle_noargs(self, **options): for link in PartyExternalLink.objects.filter( link_class='BitworldParty'): conn = httplib.HTTPConnection("bitworld.bitfellas.org") conn.request("GET", "/party.php?id=%s" % link.parameter) response = conn.getresponse() if response.status == 301: new_link = PartyExternalLink(party_id=link.party_id) new_link.url = response.getheader('Location') try: sid = transaction.savepoint() new_link.save() transaction.savepoint_commit(sid) print "added url %s for party id %d" % (new_link.url, new_link.party_id) except IntegrityError: # this link duplicates an existing one - we just didn't recognise it # until now due to different link formats. Fair game to delete it transaction.savepoint_rollback(sid) print "%s already exists - skipping" % (new_link.url) else: print "Unexpected response status code %d - skipping" % response.status conn.close() sleep(1) for link in ProductionLink.objects.filter(link_class='BitworldDemo'): conn = httplib.HTTPConnection("bitworld.bitfellas.org") conn.request("GET", "/demo.php?id=%s" % link.parameter) response = conn.getresponse() if response.status == 301: new_link = ProductionLink(production_id=link.production_id) new_link.url = response.getheader('Location') try: sid = transaction.savepoint() new_link.save() transaction.savepoint_commit(sid) print "added url %s for prod id %d" % ( new_link.url, new_link.production_id) except IntegrityError: # this link duplicates an existing one - we just didn't recognise it # until now due to different link formats. Fair game to delete it transaction.savepoint_rollback(sid) print "%s already exists - skipping" % (new_link.url) else: print "Unexpected response status code %d - skipping" % response.status conn.close() sleep(1)
def test_atariki_entry(self): pondlife = Production.objects.get(title='Pondlife') link = ProductionLink(production=pondlife, is_download_link=False) link.url = 'http://atariki.krap.pl/index.php/Cool_Emotion' self.assertEqual(link.link_class, 'AtarikiEntry') self.assertEqual(str(link.link), 'http://atariki.krap.pl/index.php/Cool_Emotion') gasman = Releaser.objects.get(name='Gasman') link = ReleaserExternalLink(releaser=gasman) link.url = 'http://atariki.krap.pl/index.php/Ars' self.assertEqual(link.link_class, 'AtarikiEntry') forever2e3 = Party.objects.get(name='Forever 2e3') link = PartyExternalLink(party=forever2e3) link.url = 'http://atariki.krap.pl/index.php/Lato_Ludzik%C3%B3w_1999' self.assertEqual(link.link_class, 'AtarikiEntry')
def import_release(release): with transaction.atomic(): title = release.title if release.supertype == 'music': title = strip_music_extensions(title) prod = Production.objects.create( title=title, supertype=release.supertype, data_source='janeway', release_date_date=release.release_date_date, release_date_precision=release.release_date_precision, ) prod.links.create(link_class='KestraBitworldRelease', parameter=release.janeway_id, is_download_link=False) for author_name in release.author_names.all(): nick = get_nick_for_name(author_name) if nick: prod.author_nicks.add(nick) if release.platform == 'ocs': prod.platforms.add(Platform.objects.get(name='Amiga OCS/ECS')) elif release.platform == 'aga': prod.platforms.add(Platform.objects.get(name='Amiga AGA')) elif release.platform == 'ppc': prod.platforms.add(Platform.objects.get(name='Amiga PPC/RTG')) for prod_type in release.types.all(): prod.types.add( ProductionType.objects.get(name=prod_type.type_name)) credits = release.credits.order_by('name_id', 'category') # merge credits with the same nick and category into one entry; # do this by forming a tuple of (resolved nick, category) for each credit and grouping on that for (nick, category), credits_for_nick in itertools.groupby( credits, lambda credit: (get_nick_for_name(credit.name), credit.category)): if not nick: continue # merge all non-empty descriptions into one string descriptions = filter( bool, [credit.description for credit in credits_for_nick]) description = ', '.join(descriptions) prod.credits.create(data_source='janeway', nick=nick, category=category, role=description) for download_link in release.download_links.all(): link = ProductionLink(production=prod, is_download_link=True, source='janeway', description=download_link.comment) link.url = download_link.url link.save() # import pack contents (when this release is a pack) pack_member_index = 1 for pack_member in release.pack_contents.select_related( 'content').order_by('id'): # look for a Demozoo record for a prod with this Janeway reference try: pack_member_link = ProductionLink.objects.get( link_class='KestraBitworldRelease', parameter=pack_member.content.janeway_id) except (ProductionLink.DoesNotExist, ProductionLink.MultipleObjectsReturned): continue prod.pack_members.create(data_source='janeway', member_id=pack_member_link.production_id, position=pack_member_index) pack_member_index += 1 # import packs that this release is packed in for pack_rel in release.packed_in.select_related('pack').order_by( 'id'): # look for a Demozoo record for a prod with this Janeway reference try: pack_link = ProductionLink.objects.get( link_class='KestraBitworldRelease', parameter=pack_rel.pack.janeway_id) except (ProductionLink.DoesNotExist, ProductionLink.MultipleObjectsReturned): continue next_position = (pack_link.production.pack_members.aggregate( pos=Max('position'))['pos'] or 0) + 1 pack_link.production.pack_members.create(data_source='janeway', member=prod, position=next_position) # import soundtrack links (for soundtracks in this prod) soundtrack_index = 1 for soundtrack_rel in release.soundtrack_links.select_related( 'soundtrack').order_by('id'): # look for a Demozoo record for a prod with this Janeway reference try: soundtrack_link = ProductionLink.objects.get( link_class='KestraBitworldRelease', parameter=soundtrack_rel.soundtrack.janeway_id) except (ProductionLink.DoesNotExist, ProductionLink.MultipleObjectsReturned): continue prod.soundtrack_links.create( data_source='janeway', soundtrack_id=soundtrack_link.production_id, position=soundtrack_index) soundtrack_index += 1 # import soundtrack links (for prods that this is the soundtrack for) for soundtrack_rel in release.appearances_as_soundtrack.select_related( 'release').order_by('id'): # look for a Demozoo record for a prod with this Janeway reference try: prod_link = ProductionLink.objects.get( link_class='KestraBitworldRelease', parameter=soundtrack_rel.release.janeway_id) except (ProductionLink.DoesNotExist, ProductionLink.MultipleObjectsReturned): continue next_position = (prod_link.production.soundtrack_links.aggregate( pos=Max('position'))['pos'] or 0) + 1 prod_link.production.soundtrack_links.create( data_source='janeway', soundtrack=prod, position=next_position) return prod
def test_base_url(self): pondlife = Production.objects.get(title='Pondlife') link = ProductionLink(production=pondlife, is_download_link=False) link.url = 'http://example.com/gfsdfgsdf' self.assertEqual(link.link.get_embed_data(), None)