Example #1
0
def add_artist(request, artist_name):
    what_client = get_what_client(request)
    response = what_client.request('artist', artistname=artist_name)['response']
    added = 0
    for group in response['torrentgroup']:
        if filter_group(response['name'], group):
            artist = html_unescape(response['name'])
            title = html_unescape(group['groupName'])
            release_type = group['releaseType']
            for torrent in group['torrent']:
                id = torrent['id']
                priority = filter_torrent(group, torrent)
                if priority and not is_existing(id):
                    format = torrent['format']
                    encoding = torrent['encoding']
                    torrent_size = torrent['size']
                    queue_item = QueueItem(
                        what_id=id,
                        priority=priority,
                        artist=artist,
                        title=title,
                        release_type=release_type,
                        format=format,
                        encoding=encoding,
                        torrent_size=torrent_size
                    )
                    queue_item.save()
                    added += 1
    return {
        'success': True,
        'added': added
    }
Example #2
0
    def update_from_what(cls, what_client, artist_id):
        try:
            artist = WhatArtist.objects.get(id=artist_id)
        except WhatArtist.DoesNotExist:
            artist = WhatArtist(
                id=artist_id
            )
        retrieved = timezone.now()
        response = what_client.request('artist', id=artist_id)['response']

        artist.retrieved = retrieved
        old_name = artist.name
        artist.name = html_unescape(response['name'])
        artist.image = html_unescape(response['image'])
        artist.wiki_body = response['body']
        artist.vanity_house = response['vanityHouse']
        artist.info_json = ujson.dumps(response)

        if old_name and artist.name != old_name:
            try:
                old_alias = artist.whatartistalias_set.get(name=artist.name)
                old_alias.delete()
            except WhatArtistAlias.DoesNotExist:
                pass
            with transaction.atomic():
                artist.save()
                WhatArtistAlias.get_or_create(artist, old_name)
        else:
            artist.save()

        return artist
Example #3
0
    def get_info(self, what_torrent):
        info = ujson.loads(what_torrent.info)

        info_text = []
        info_text.append(unicode(info['group']['id']))
        info_text.append(info['group']['recordLabel'])
        info_text.append(info['group']['name'])
        info_text.append(info['group']['catalogueNumber'])
        if info['group']['musicInfo']:
            for type, artists in info['group']['musicInfo'].items():
                if artists:
                    artist_names = [a['name'] for a in artists]
                    info_text.append(', '.join(artist_names))
        info_text.append(unicode(info['group']['year']))

        info_text.append(unicode(info['torrent']['id']))
        info_text.append(unicode(info['torrent']['remasterYear']))
        info_text.append(info['torrent']['filePath'])
        info_text.append(info['torrent']['remasterCatalogueNumber'])
        info_text.append(info['torrent']['remasterRecordLabel'])
        info_text.append(info['torrent']['remasterTitle'])

        info_text = '\r\n'.join(info_text)
        info_text = html_unescape(info_text)
        return info_text
Example #4
0
    def get_info(self, what_torrent):
        info = ujson.loads(what_torrent.info)

        info_text = []
        info_text.append(unicode(info['group']['id']))
        info_text.append(info['group']['recordLabel'])
        info_text.append(info['group']['name'])
        info_text.append(info['group']['catalogueNumber'])
        if info['group']['musicInfo']:
            for type, artists in info['group']['musicInfo'].items():
                if artists:
                    artist_names = [a['name'] for a in artists]
                    info_text.append(', '.join(artist_names))
        info_text.append(unicode(info['group']['year']))

        info_text.append(unicode(info['torrent']['id']))
        info_text.append(unicode(info['torrent']['remasterYear']))
        info_text.append(info['torrent']['filePath'])
        info_text.append(info['torrent']['remasterCatalogueNumber'])
        info_text.append(info['torrent']['remasterRecordLabel'])
        info_text.append(info['torrent']['remasterTitle'])

        info_text = '\r\n'.join(info_text)
        info_text = html_unescape(info_text)
        return info_text
Example #5
0
 def add_artists(self, importance, artists):
     for artist in artists:
         what_artist, artist_alias = WhatArtist.get_or_create_shell(
             artist['id'], html_unescape(artist['name']), self.retrieved)
         WhatTorrentArtist(
             artist=what_artist,
             artist_alias=artist_alias,
             torrent_group=self,
             importance=importance,
         ).save()
Example #6
0
 def update_if_newer(cls, group_id, retrieved, data_dict, torrents_dict=None):
     try:
         group = WhatTorrentGroup.objects.get(id=group_id)
         if retrieved < group.retrieved:
             return group
     except WhatTorrentGroup.DoesNotExist:
         group = WhatTorrentGroup(
             id=group_id
         )
     group.retrieved = retrieved
     group.wiki_body = data_dict['wikiBody']
     group.wiki_image = html_unescape(data_dict['wikiImage'])
     group.joined_artists = get_artists(data_dict)
     group.name = html_unescape(data_dict['name'])
     group.year = data_dict['year']
     group.record_label = html_unescape(data_dict['recordLabel'])
     group.catalogue_number = html_unescape(data_dict['catalogueNumber'])
     group.release_type = data_dict['releaseType']
     group.category_id = data_dict['categoryId']
     group.category_name = data_dict['categoryName']
     group.time = parse_datetime_with_timezone_support(data_dict['time'])
     group.vanity_house = data_dict['vanityHouse']
     group.info_json = ujson.dumps(data_dict)
     if torrents_dict is not None:
         group.torrents_json = ujson.dumps(torrents_dict)
     else:
         group.torrents_json = None
     with transaction.atomic():
         group.save()
         group.artists.clear()
         group.add_artists(1, data_dict['musicInfo']['artists'])
         group.add_artists(2, data_dict['musicInfo']['with'])
         group.add_artists(3, data_dict['musicInfo']['remixedBy'])
         group.add_artists(4, data_dict['musicInfo']['composers'])
         group.add_artists(5, data_dict['musicInfo']['conductor'])
         group.add_artists(6, data_dict['musicInfo']['dj'])
         group.add_artists(7, data_dict['musicInfo']['producer'])
     return group
Example #7
0
def add_collage(request, collage_id):
    what_client = get_what_client(request)
    response = what_client.request('collage', id=collage_id)['response']
    added = 0
    torrent_group_count = 0
    torrent_count = 0
    for group in response['torrentgroups']:
        if group['categoryId'] not in [1, '1']:
            continue
        artist = get_artists(group)
        title = html_unescape(group['name'])
        release_type = group['releaseType']
        for torrent in group['torrents']:
            what_id = torrent['torrentid']
            priority = filter_torrent(group, torrent)
            if priority and not is_existing(what_id):
                torrent_format = torrent['format']
                encoding = torrent['encoding']
                torrent_size = torrent['size']
                queue_item = QueueItem(
                    what_id=what_id,
                    priority=priority,
                    artist=artist,
                    title=title,
                    release_type=release_type,
                    format=torrent_format,
                    encoding=encoding,
                    torrent_size=torrent_size
                )
                queue_item.save()
                added += 1
            torrent_count += 1
        torrent_group_count += 1
    return {
        'success': True,
        'added': added,
        'groups': torrent_group_count,
        'torrents': torrent_count
    }
Example #8
0
def parse_file(file):
    parts = file.replace("}}}", "").split("{{{")
    return {"name": html_unescape(parts[0]), "size": int(parts[1])}
Example #9
0
def parse_file(file):
    parts = file.replace('}}}', '').split('{{{')
    return {
        'name': html_unescape(parts[0]),
        'size': int(parts[1])
    }