Exemplo n.º 1
0
 def filename(self):
     """
     Exposes the title of the video. If this is not set, one is
     generated based on the name of the video.
     """
     if not self._filename:
         self._filename = safe_filename(self.title)
     return self._filename
Exemplo n.º 2
0
 def filename(self):
     """
     Exposes the title of the video. If this is not set, one is
     generated based on the name of the video.
     """
     if not self._filename:
         self._filename = safe_filename(self.title)
     return self._filename
Exemplo n.º 3
0
def save_torrent_file(tf):
    torrent_cache_dir = os.path.join(common.conf.config_path, "torrent_cache")
    torrent_filename = "{0}.{1}.torrent".format(
        os.path.splitext(utils.safe_filename(tf.name))[0],
        tf.info_hash)
        
    torrent_file_abspath = os.path.join(torrent_cache_dir, torrent_filename)
    if not os.path.exists(torrent_file_abspath):
        with open(torrent_file_abspath, "wb") as fp:
            tf.seek(0)
            fp.write(tf.read())
Exemplo n.º 4
0
 def on_download(self, *args, **kwargs):
     item = self.results[self.window.get_item()]
     if item.download_url == "":
         item.get_download_url()
     log.debug("Starting requested download: {0} (using extractor: {1})".format(item.title, self.extractor.name))
     f = "{item_name}.{item_extension}".format(item_name=item.format_track(), item_extension=item.extractor.get_file_format())
     path = self.window.get_destination_path(utils.safe_filename(f))
     if path != None:
         log.debug("User has requested the following path: {0}".format(path,))
         if self.extractor.transcoder_enabled() == True: # Send download to vlc based transcoder
             utils.call_threaded(player.player.transcode_audio, item, path, _format=item.extractor.get_file_format(), metadata=item.get_metadata())
         else:
             log.debug("downloading %s URL to %s filename" % (item.download_url, path,))
             utils.call_threaded(utils.download_file, item.download_url, path, metadata=item.get_metadata())
Exemplo n.º 5
0
def sort_eoi(eoi, files):
    unique_events = set()
    events_to_sources = defaultdict(list)
    
    for csv in files:
        data = pd.read_csv(csv,
                           names=['timestamp', 'event'],
                           dtype={'event': str},
                           parse_dates=[0],
                           index_col=0)
        data.sort_index(inplace=True)
        data.to_csv(csv, mode='w')

        local_events = data.event.unique()
        unique_events.update(local_events)
        
        for event in eoi.event:
            if event in local_events:
                events_to_sources[safe_filename(event)].append(os.path.basename(os.path.normpath(csv)))
                    
    return unique_events, events_to_sources
Exemplo n.º 6
0
def torrent(request, id, filename=None):
    item = get_object_or_404(models.Item, itemId=id)
    if not item.access(request.user):
        return HttpResponseForbidden()
    if not item.torrent:
        raise Http404
    if not filename or filename.endswith('.torrent'):
        response = HttpResponse(item.get_torrent(request),
                                content_type='application/x-bittorrent')
        filename = utils.safe_filename("%s.torrent" % item.get('title'))
        response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8'))
        return response
    while filename.startswith('/'):
        filename = filename[1:]
    filename = filename.replace('/../', '/')
    filename = item.path('torrent/%s' % filename)
    filename = os.path.abspath(os.path.join(settings.MEDIA_ROOT, filename))
    response = HttpFileResponse(filename)
    response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % \
                                      quote(os.path.basename(filename.encode('utf-8')))
    return response
Exemplo n.º 7
0
def sort_eoi(eoi, files):
    unique_events = set()
    events_to_sources = defaultdict(list)

    for csv in files:
        data = pd.read_csv(csv,
                           names=['timestamp', 'event'],
                           dtype={'event': str},
                           parse_dates=[0],
                           index_col=0)
        data.sort_index(inplace=True)
        data.to_csv(csv, mode='w')

        local_events = data.event.unique()
        unique_events.update(local_events)

        for event in eoi.event:
            if event in local_events:
                events_to_sources[safe_filename(event)].append(
                    os.path.basename(os.path.normpath(csv)))

    return unique_events, events_to_sources
def torrent(request, id, filename=None):
    item = get_object_or_404(models.Item, itemId=id)
    if not item.access(request.user):
        return HttpResponseForbidden()
    if not item.torrent:
        raise Http404
    if not filename or filename.endswith('.torrent'):
        response = HttpResponse(item.get_torrent(request),
                                content_type='application/x-bittorrent')
        filename = utils.safe_filename("%s.torrent" % item.get('title'))
        response[
            'Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(
                filename.encode('utf-8'))
        return response
    while filename.startswith('/'):
        filename = filename[1:]
    filename = filename.replace('/../', '/')
    filename = item.path('torrent/%s' % filename)
    filename = os.path.abspath(os.path.join(settings.MEDIA_ROOT, filename))
    response = HttpFileResponse(filename)
    response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % \
                                      quote(os.path.basename(filename.encode('utf-8')))
    return response
Exemplo n.º 9
0
def determine_image_upload_path(instance, filename):
    return "uploads/%(filename)s" % {
        ## 'partition': get_partition_id(instance.pk),
        'filename': safe_filename(filename),
        }
Exemplo n.º 10
0
def determine_image_upload_path(instance, filename):
    return "uploads/%(filename)s" % {
        ## 'partition': get_partition_id(instance.pk),
        'filename': safe_filename(filename),
    }
Exemplo n.º 11
0
 def filename(self):
     if not self._filename:
         self._filename = safe_filename(self.title)
     return self._filename
Exemplo n.º 12
0
for i, chunk in enumerate(csv):
    data = defaultdict(list)

    t0 = time.time()

    for row in chunk.itertuples(index=False):
        timestamp, source, event = row
        if pd.notnull(source):
            data[source].append((timestamp, event))

    print('Demuxing chunk: {} seconds.'.format(pretty_float(time.time()-t0)), end=' ')

    t0 = time.time()

    for source in data.keys():
        with open('{}/{}'.format(args.source_dir, safe_filename(source)), 'a+') as _file:
            for timestamp, event in data[source]:
                print('{},{}'.format(timestamp, event), file=_file)

    print('Writing {} source csv files to disk: {} seconds.'.format(len(data.keys()), pretty_float(time.time()-t0)), end=' ')

    print('{}% done.'.format(100*(i+1)*args.chunksize/length))
    
t_end = time.time()-t_start

source_files = [ os.path.join(args.source_dir, f) for f in os.listdir(args.source_dir) ]

print('{} sources demultiplexed in {} seconds.'.format(len(source_files), pretty_float(t_end)))

eoi = pd.read_csv(args.eoi,
                  header=None,
Exemplo n.º 13
0
    data = defaultdict(list)

    t0 = time.time()

    for row in chunk.itertuples(index=False):
        timestamp, source, event = row
        if pd.notnull(source):
            data[source].append((timestamp, event))

    print('Demuxing chunk: {} seconds.'.format(pretty_float(time.time() - t0)),
          end=' ')

    t0 = time.time()

    for source in data.keys():
        with open('{}/{}'.format(args.source_dir, safe_filename(source)),
                  'a+') as _file:
            for timestamp, event in data[source]:
                print('{},{}'.format(timestamp, event), file=_file)

    print('Writing {} source csv files to disk: {} seconds.'.format(
        len(data.keys()), pretty_float(time.time() - t0)),
          end=' ')

    print('{}% done.'.format(100 * (i + 1) * args.chunksize / length))

t_end = time.time() - t_start

source_files = [
    os.path.join(args.source_dir, f) for f in os.listdir(args.source_dir)
]