Esempio n. 1
0
def track_unicode_special(DBSession, commit):
    tags_data = (
        'title:UnicodeAssention',
        'from:Hack//Sign',
        'artist:こ',
    )
    def _create_tag(tag_data):
        tag = get_tag(tag_data, create_if_missing=True)
        DBSession.add(tag)
        return tag
    tag_objs = tuple(_create_tag(tag) for tag in tags_data)
    commit()

    track = Track()
    track.id = 'x999'
    track.duration = 120
    track.tags[:] = tag_objs
    track.source_filename = 'unicode_special'

    DBSession.add(track)
    commit()

    yield track

    DBSession.delete(track)
    for tag_obj in tag_objs:
        DBSession.delete(tag_obj)
    commit()
Esempio n. 2
0
def create_test_track(id=None,
                      duration=None,
                      tags=(),
                      attachments=(),
                      lyrics=None,
                      source_filename=None):
    def _get_tag(tag):
        return get_tag(tag, create_if_missing=True)

    def _get_attachment(attachment):
        if hasattr(attachment, 'location') and hasattr(attachment, 'type'):
            return create_attachment(attachment)
        else:
            return DBSession.query(Attachment).filter(
                Attachment.location.like('%%{0}%%'.format(attachment))).one()

    track = Track()
    track.id = id if id else random_string(10)
    track.duration = duration if duration else random.randint(60, 360)
    for tag in tags:
        track.tags.append(_get_tag(tag))
    for attachment in attachments:
        track.attachments.append(_get_attachment(attachment))
    track.lyrics = lyrics or ''
    track.source_filename = source_filename

    DBSession.add(track)

    return track
Esempio n. 3
0
def track_unicode_special(DBSession, commit):
    tags_data = (
        'title:UnicodeAssention',
        'from:Hack//Sign',
        'artist:こ',
    )
    def _create_tag(tag_data):
        tag = get_tag(tag_data, create_if_missing=True)
        DBSession.add(tag)
        return tag
    tag_objs = tuple(_create_tag(tag) for tag in tags_data)
    commit()

    track = Track()
    track.id = 'x999'
    track.duration = 120
    track.tags[:] = tag_objs
    track.source_filename = 'unicode_special'

    DBSession.add(track)
    commit()

    yield track

    DBSession.delete(track)
    for tag_obj in tag_objs:
        DBSession.delete(tag_obj)
    commit()
Esempio n. 4
0
def create_test_track(id=None, duration=None, tags=[], attachments=[], lyrics=None):
    def _get_tag(tag):
        return get_tag(tag, create_if_missing=True)    
    def _get_attachment(filename):
        return DBSession.query(Attachment).filter(Attachment.location.like('%%{0}%%'.format(filename))).one()

    track = Track()
    track.id          = id       if id       else random_string(10)
    track.duration    = duration if duration else random.randint(60,360)
    [track.tags       .append(_get_tag       (t)) for t in tags       ]
    [track.attachments.append(_get_attachment(a)) for a in attachments]
    if lyrics:
        track.lyrics.append(lyrics)
    return track
Esempio n. 5
0
def track_import_post(request):
    existing_track_ids = _existing_tracks_dict().keys()

    for track_dict in _get_json_request(request):
        if track_dict['id'] in existing_track_ids:
            log.warning(
                'Exists: {source_filename} - {id}'.format(**track_dict))
            continue

        log.info('Import: {source_filename} - {id}'.format(**track_dict))
        track = Track()
        track.id = track_dict['id']
        track.source_filename = track_dict['source_filename']
        track.duration = track_dict['duration']
        track.lyrics = track_dict['lyrics']

        # Attachments
        for attachment_dict in track_dict['attachments']:
            assert attachment_dict['type'] in ATTACHMENT_TYPES
            attachment = Attachment()
            attachment.type = attachment_dict['type']
            attachment.location = attachment_dict['location']
            track.attachments.append(attachment)

        # Tags
        for tag_string in track_dict['tags']:
            tag = get_tag(tag_string, create_if_missing=True)
            if tag:
                track.tags.append(tag)
            elif tag_string:
                log.warning('null tag %s', tag_string)
        for duplicate_tag in (tag for tag in track.tags
                              if track.tags.count(tag) > 1):
            log.warning('Unneeded duplicate tag found %s in %s', duplicate_tag,
                        track.source_filename)
            track.tags.remove(duplicate_tag)

        DBSession.add(track)
        commit()

    request.registry.settings['karakara.tracks.version'] += 1
    return action_ok()
Esempio n. 6
0
def track_import_post(request):
    existing_track_ids = _existing_tracks_dict().keys()

    for track_dict in _get_json_request(request):
        if track_dict['id'] in existing_track_ids:
            log.warning('Exists: {source_filename} - {id}'.format(**track_dict))
            continue

        log.info('Import: {source_filename} - {id}'.format(**track_dict))
        track = Track()
        track.id = track_dict['id']
        track.source_filename = track_dict['source_filename']
        track.duration = track_dict['duration']
        track.lyrics = track_dict['lyrics']

        # Attachments
        for attachment_dict in track_dict['attachments']:
            assert attachment_dict['type'] in ATTACHMENT_TYPES
            attachment = Attachment()
            attachment.type = attachment_dict['type']
            attachment.location = attachment_dict['location']
            track.attachments.append(attachment)

        # Tags
        for tag_string in track_dict['tags']:
            tag = get_tag(tag_string, create_if_missing=True)
            if tag:
                track.tags.append(tag)
            elif tag_string:
                log.warning('null tag %s', tag_string)
        for duplicate_tag in (tag for tag in track.tags if track.tags.count(tag) > 1):
            log.warning('Unneeded duplicate tag found %s in %s', duplicate_tag, track.source_filename)
            track.tags.remove(duplicate_tag)

        DBSession.add(track)
        commit()

    request.registry.settings['karakara.tracks.version'] += 1
    return action_ok()
Esempio n. 7
0
    def import_track(self, name):
        log.debug('Attemping: %s', name)

        self.meta_manager.load(name)
        m = self.meta_manager.get(name)

        if not m.source_hash:
            raise TrackNotProcesedException()

        if self._missing_files(m.processed_files):
            # If we are missing any files but we have a source hash,
            # we may have some of the derived media missing.
            # Explicity mark the item for reencoding
            if PENDING_ACTION['encode'] not in m.pending_actions:  # Feels clunky to manage this as a list? maybe a set?
                m.pending_actions.append(PENDING_ACTION['encode'])
                self.meta_manager.save(name)  # Feels clunky
            raise TrackMissingProcessedFiles(id=m.source_hash in self.exisiting_track_ids and m.source_hash)

        if m.source_hash in self.exisiting_track_ids:
            log.debug('Exists: %s', name)
            return False

        log.info('Import: %s', name)
        track = Track()
        track.id = m.source_hash
        track.source_filename = name
        track.duration = m.source_details.get('duration')

        self._add_attachments(track, m.processed_files)
        self._add_lyrics(track, m.processed_files.get('srt'))
        self._add_tags(track, m.processed_files.get('tags'))

        DBSession.add(track)
        commit()
        self.exisiting_track_ids.add(m.source_hash)  # HACK!! .. we should not have duplicate hashs's in the source set. This is a temp patch

        return True
Esempio n. 8
0
def create_test_track(id=None, duration=None, tags=(), attachments=(), lyrics=None, source_filename=None):

    def _get_tag(tag):
        return get_tag(tag, create_if_missing=True)

    def _get_attachment(attachment):
        if hasattr(attachment, 'location') and hasattr(attachment, 'type'):
            return create_attachment(attachment)
        else:
            return DBSession.query(Attachment).filter(Attachment.location.like('%%{0}%%'.format(attachment))).one()

    track = Track()
    track.id = id if id else random_string(10)
    track.duration = duration if duration else random.randint(60, 360)
    for tag in tags:
        track.tags.append(_get_tag(tag))
    for attachment in attachments:
        track.attachments.append(_get_attachment(attachment))
    track.lyrics = lyrics or ''
    track.source_filename = source_filename

    DBSession.add(track)

    return track
Esempio n. 9
0
def random_tracks(request, DBSession, commit, num_tracks=800):
    log.info('Generating {0} random tracks'.format(num_tracks))

    # Attachment generation ----------------------------------------------------
    attachments_meta = [
        ('preview1.3gp' , 'preview'  ),
        ('preview2.flv' , 'preview'  ),
        ('image1.jpg'   , 'thumbnail'),
        ('image2.jpg'   , 'thumbnail'),
        ('image3.png'   , 'thumbnail'),
        ('processed.mpg', 'video'    ),
        ('subtitles.ssa', 'subtitle' ),
    ]
    attachments = []
    for location, type in attachments_meta:
        attachment = Attachment()
        attachment.location = location
        attachment.type     = type
        DBSession.add(attachment)
        attachments.append(attachment)
    commit()
    
    # Random Tag generation ----------------------------------------------------
    parent_tag = get_tag('from')
    for series_num in range(10):
        DBSession.add(Tag('Series %s'%random_string(1), parent_tag))
    commit()
    
    
    # --------------------------------------------------------------------------
    
    tags = DBSession.query(Tag).options(joinedload(Tag.parent)).all()
    alias_parent_tag = aliased(Tag)
    tags_category = DBSession.query(Tag).join(alias_parent_tag, Tag.parent).filter(alias_parent_tag.name=='category').all()
    tags_from     = DBSession.query(Tag).join(alias_parent_tag, Tag.parent).filter(alias_parent_tag.name=='from').all()
    
    def get_random_tags(num_tags=None):
        random_tags = []
        if not num_tags:
            num_tags = random.randint(1,5)
        for tag_num in range(num_tags):
            random_tags.append(tags[random.randint(0,len(tags)-1)])
        
        # if we have 'from' tags and NO category tag, then add a random category
        from_tags = [t for t in random_tags if t.parent and t.parent.name=='from']
        category_tags = [t for t in random_tags if t.parent and t.parent.name=='category']
        if from_tags and not category_tags:
            random_tags.append(random.choice(tags_category))
        if category_tags and not from_tags:
            random_tags.append(random.choice(tags_from))
        # only have 1 'from' tag
        for tag in from_tags[1:]:
            random_tags.remove(tag)
        # only have one category tag
        for tag in category_tags[1:]:
            random_tags.remove(tag)
        
        return random_tags
    
    def get_random_description(words=None, word_size=None):
        if not words:
            words     = random.randint(4,24)
        if not word_size:
            word_size = random.randint(2,16)
        return " ".join([random_string(word_size) for word in range(words)])
        
    # Track generation ---------------------------------------------------------
    tag_titles = [get_tag('Test Track {0}'.format(i), 'title', create_if_missing=True) for i in range(num_tracks)]
    #commit()

    for track_number in range(num_tracks):
        track = Track()
        track.id          = "track_%d"      % track_number
        #track.description = get_random_description()
        track.duration    = random.randint(60,360)
        track.tags        = list(set(get_random_tags())) + [tag_titles[track_number]]
        track.attachments = attachments
        DBSession.add(track)
    
    commit()
Esempio n. 10
0
def init_random_data(num_tracks=100):

    # Attachment generation ----------------------------------------------------
    attachments_meta = [
        ('preview1.3gp' , 'preview'  ),
        ('preview2.flv' , 'preview'  ),
        ('image1.jpg'   , 'image'    ),
        ('image2.jpg'   , 'image'    ),
        ('image3.png'   , 'image'    ),
        ('processed.mpg', 'processed'),
        ('subtitles.ssa', 'subtitle' ),
    ]
    attachments = []
    for location, type in attachments_meta:
        attachment = Attachment()
        attachment.location = location
        attachment.type     = type
        DBSession.add(attachment)
        attachments.append(attachment)
    
    
    # Random Tag generation ----------------------------------------------------
    parent_tag = get_tag('from')
    for series_num in range(10):
        DBSession.add(Tag('Series %s'%random_string(1), parent_tag))
    
    commit()
    
    
    # --------------------------------------------------------------------------
    
    tags = DBSession.query(Tag).all()
    
    def get_random_tags(num_tags=None):
        random_tags = []
        if not num_tags:
            num_tags = random.randint(1,5)
        for tag_num in range(num_tags):
            random_tags.append(tags[random.randint(0,len(tags)-1)])
        return random_tags
    
    def get_random_description(words=None, word_size=None):
        if not words:
            words     = random.randint(4,24)
        if not word_size:
            word_size = random.randint(2,16)
        return " ".join([random_string(word_size) for word in range(words)])
    
    
    # Track generation ---------------------------------------------------------
    for track_number in range(num_tracks):
        track = Track()
        track.id          = "track_%d"      % track_number
        track.title       = "Test Track %s" % track_number
        track.description = get_random_description()
        track.duration    = random.randint(60,360)
        track.tags        = list(set(get_random_tags()))
        track.attachments = attachments
        DBSession.add(track)
    
    commit()
Esempio n. 11
0
def random_tracks(request, DBSession, commit, num_tracks=800):
    """
    Generate 100's of random tracks
    """
    log.info('Generating {0} random tracks'.format(num_tracks))

    # Attachment generation ----------------------------------------------------
    attachments_meta = [
        ('preview1.3gp', 'preview'),
        ('preview2.flv', 'preview'),
        ('image1.jpg', 'image'),
        ('image2.jpg', 'image'),
        ('image3.png', 'image'),
        ('processed.mpg', 'video'),
        ('subtitles.srt', 'srt'),
    ]
    attachments = []
    for location, type in attachments_meta:
        attachment = Attachment()
        attachment.location = location
        attachment.type = type
        DBSession.add(attachment)
        attachments.append(attachment)
    commit()

    # Random Tag generation ----------------------------------------------------
    parent_tag = get_tag('from')
    for series_num in range(10):
        DBSession.add(Tag('Series %s' % random_string(1), parent_tag))
    commit()

    # --------------------------------------------------------------------------

    tags = DBSession.query(Tag).options(joinedload(Tag.parent)).all()
    alias_parent_tag = aliased(Tag)
    tags_category = DBSession.query(Tag).join(
        alias_parent_tag,
        Tag.parent).filter(alias_parent_tag.name == 'category').all()
    tags_from = DBSession.query(Tag).join(
        alias_parent_tag,
        Tag.parent).filter(alias_parent_tag.name == 'from').all()

    def get_random_tags(num_tags=None):
        random_tags = []
        if not num_tags:
            num_tags = random.randint(1, 5)
        for tag_num in range(num_tags):
            random_tags.append(tags[random.randint(0, len(tags) - 1)])

        # if we have 'from' tags and NO category tag, then add a random category
        from_tags = [
            t for t in random_tags if t.parent and t.parent.name == 'from'
        ]
        category_tags = [
            t for t in random_tags if t.parent and t.parent.name == 'category'
        ]
        if from_tags and not category_tags:
            random_tags.append(random.choice(tags_category))
        if category_tags and not from_tags:
            random_tags.append(random.choice(tags_from))
        # only have 1 'from' tag
        for tag in from_tags[1:]:
            random_tags.remove(tag)
        # only have one category tag
        for tag in category_tags[1:]:
            random_tags.remove(tag)

        return random_tags

    def get_random_description(words=None, word_size=None):
        if not words:
            words = random.randint(4, 24)
        if not word_size:
            word_size = random.randint(2, 16)
        return " ".join([random_string(word_size) for word in range(words)])

    # Track generation ---------------------------------------------------------
    tag_titles = [
        get_tag('Test Track {0}'.format(i), 'title', create_if_missing=True)
        for i in range(num_tracks)
    ]
    #commit()

    for track_number in range(num_tracks):
        track = Track()
        track.id = "track_%d" % track_number
        #track.description = get_random_description()
        track.duration = random.randint(60, 360)
        track.tags = list(set(get_random_tags())) + [tag_titles[track_number]]
        track.attachments = attachments
        DBSession.add(track)

    commit()
Esempio n. 12
0
def band_tracks(DBSession, commit):

    data = [
        {
            'id': 'go',
            'tags': {
                'title': 'Go!!!',
                'category': 'anime',
                'from': 'Naruto',
                'artist': 'Flow',
                'lang': 'jp',
                'use': 'opening',
            },
        },
        {
            'id': 'power_rangers',
            'tags': {
                'title': 'Go Go Power Rangers',
                'category': 'cartoon',
                'from': 'Mighty Morphing Power Rangers',
                'lang': 'en',
                'artist': 'Ron Wasserman',
            },
        },
        {
            'id': 'reignite',
            'tags': {
                'title': 'Reignite',
                'category': 'game',
                'from': 'Mass Effect',
                'lang': 'en',
                'use': 'cover',
                'artist': 'Malukah',
            },
        },
        {
            'id': 'alchemy',
            'tags': {
                'title': 'Alchemy',
                'category': 'anime',
                'from': 'Angel Beats',
                'use': 'insert',
                'artist': 'Girls Dead Monster',
                'lang': 'jp',
            },
        },
        {
            'id': 'god_knows',
            'tags': {
                'title': 'God Knows',
                'category': 'anime',
                'from': 'The Melancholy of Haruhi Suzumiya',
                'artist': 'Satoru Kosaki',
                'lang': 'jp',
            }
        },
        {
            'id': 'lagann',
            'tags': {
                'title': 'Sorairo Days',
                'category': 'anime',
                'from': 'Gurren Lagann',
                'artist': 'Iwasaki Taku',
                'lang': 'jp',
                'use': 'opening',
            }
        },
    ]

    for d in data:
        _id = "band_{0}".format(d['id'])

        track = get_track(_id)
        if not track:
            track = Track()
            track.id = _id
            track.duration = 300
            track.tags = [
                get_tag(tag, parent=parent, create_if_missing=True)
                for parent, tag in ChainMap(d['tags'], DEFAULT_TAGS).items()
            ]
            #track.attachments = attachments
            DBSession.add(track)

    commit()
Esempio n. 13
0
def band_tracks(DBSession, commit):

    data = [
        {
            'id': 'go',
            'tags': {
                'title': 'Go!!!',
                'category': 'anime',
                'from': 'Naruto',
                'artist': 'Flow',
                'lang': 'jp',
                'use': 'opening',
            },
        },
        {
            'id': 'power_rangers',
            'tags': {
                'title': 'Go Go Power Rangers',
                'category': 'cartoon',
                'from': 'Mighty Morphing Power Rangers',
                'lang': 'en',
                'artist': 'Ron Wasserman',
            },
        },
        {
            'id': 'reignite',
            'tags': {
                'title': 'Reignite',
                'category': 'game',
                'from': 'Mass Effect',
                'lang': 'en',
                'use': 'cover',
                'artist': 'Malukah',
            },
        },
        {
            'id': 'alchemy',
            'tags': {
                'title': 'Alchemy',
                'category': 'anime',
                'from': 'Angel Beats',
                'use': 'insert',
                'artist': 'Girls Dead Monster',
                'lang': 'jp',
            },
        },
        {
            'id': 'god_knows',
            'tags': {
                'title': 'God Knows',
                'category': 'anime',
                'from': 'The Melancholy of Haruhi Suzumiya',
                'artist': 'Satoru Kosaki',
                'lang': 'jp',
            }
        },
        {
            'id': 'lagann',
            'tags': {
                'title': 'Sorairo Days',
                'category': 'anime',
                'from': 'Gurren Lagann',
                'artist': 'Iwasaki Taku',
                'lang': 'jp',
                'use': 'opening',
            }
        },
    ]

    for d in data:
        _id = "band_{0}".format(d['id'])

        track = get_track(_id)
        if not track:
            track = Track()
            track.id = _id
            track.duration = 300
            track.tags = [get_tag(tag, parent=parent, create_if_missing=True) for parent, tag in ChainMap(d['tags'], DEFAULT_TAGS).items()]
            #track.attachments = attachments
            DBSession.add(track)

    commit()