コード例 #1
0
ファイル: views.py プロジェクト: Krazylee/spindle-code
def new(request):
    if request.method == 'POST':
        form = ItemMetadataForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data.copy()
            if 'caption_file' in data: del data['caption_file']

            item = Item(**data)
            item.duration = 0   #  FIXME
            item.published = timezone.now()
            item.save()

            return redirect(item_tracks, item_id=item.id)
    else:
        form = ItemMetadataForm()

    return render(request, 'spindle/new.html', {
        'form': form,
        })
コード例 #2
0
ファイル: feedscraper.py プロジェクト: bao1018/spindle-code
def records_to_items(items):
    # Two items are likely to represent the same content in different
    # forms if they have the same basename (foo.mp3 vs. foo.mpg), same
    # duration, and same title

    # A hash mapping keys of the form "TITLE/BASENAME/DURATION" into a
    # hash of URLs. Each hash of URLs maps a real .mp3 or .mpg URL to
    # the item record referring to it
    hash = {}

    for item in items:
        url = urlparse(item['url'])
        bname = splitext(basename(url.path))[0]
        key = u"{}/{}/{:d}".format(item['name'],
                                   bname,
                                   item['duration'])

        if key not in hash:
            hash[key] = {}

        hash[key][item['url']] = item

    # Loop over the hash and create Item objects which combine the
    # audio and video together
    for key, urlhash in hash.items():
        item = None
        for url, record in urlhash.items():
            if item is None:
                dct = dict((field, record[field])
                           for field in record
                           if field not in ('url', 'guid', 'type'))
                item = Item(**dct)

            if record['type'] == 'audio':
                item.audio_url = record['url']
                item.audio_guid = record['guid']
            else:
                item.video_url = record['url']
                item.video_guid = record['guid']

        if item: yield item
コード例 #3
0
ファイル: views.py プロジェクト: niteshiit/spindle-code
def new(request):
    if request.method == 'POST':
        form = ItemMetadataForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data.copy()
            if 'caption_file' in data: del data['caption_file']

            item = Item(**data)
            item.duration = 0  #  FIXME
            item.published = timezone.now()
            item.save()

            return redirect(item_tracks, item_id=item.id)
    else:
        form = ItemMetadataForm()

    return render(request, 'spindle/new.html', {
        'form': form,
    })
コード例 #4
0
def records_to_items(items):
    # Two items are likely to represent the same content in different
    # forms if they have the same basename (foo.mp3 vs. foo.mpg), same
    # duration, and same title

    # A hash mapping keys of the form "TITLE/BASENAME/DURATION" into a
    # hash of URLs. Each hash of URLs maps a real .mp3 or .mpg URL to
    # the item record referring to it
    hash = {}

    for item in items:
        url = urlparse(item['url'])
        bname = splitext(basename(url.path))[0]
        key = u"{}/{}/{:d}".format(item['name'], bname, item['duration'])

        if key not in hash:
            hash[key] = {}

        hash[key][item['url']] = item

    # Loop over the hash and create Item objects which combine the
    # audio and video together
    for key, urlhash in hash.items():
        item = None
        for url, record in urlhash.items():
            if item is None:
                dct = dict((field, record[field]) for field in record
                           if field not in ('url', 'guid', 'type'))
                item = Item(**dct)

            if record['type'] == 'audio':
                item.audio_url = record['url']
                item.audio_guid = record['guid']
            else:
                item.video_url = record['url']
                item.video_guid = record['guid']

        if item: yield item