Пример #1
0
        def task(beans):
            for bean in beans:
                path = bean.path
                if path and (get_file_extension(path) in [".m3u", ".m3u8"]
                             and bean not in checked_m3u_beans):
                    checked_m3u_beans.append(bean)
                    for b in beans:
                        if (os.path.dirname(b.path) == os.path.dirname(path)
                                and os.path.isfile(b.path)
                                and get_file_extension(
                                    b.path) not in [".m3u", ".m3u8"]):
                            m3u_beans_for_delete.append(bean)
                            break
                    task(beans)

                if path and (get_file_extension(path) == ".cue"
                             and bean not in checked_cue_beans):

                    checked_cue_beans.append(bean)
                    filtered_beans = [
                        b for b in beans
                        if (os.path.dirname(b.path) != os.path.dirname(path)
                            or os.path.isdir(b.path)
                            or get_file_extension(b.path) == ".cue")
                    ]
                    return task(filtered_beans)
            return beans
Пример #2
0
        def task(beans):
            for bean in beans:
                path = bean.path
                if path and (get_file_extension(path) in [".m3u", ".m3u8"] and bean not in checked_m3u_beans):
                    checked_m3u_beans.append(bean)
                    for b in beans:
                        if (
                            os.path.dirname(b.path) == os.path.dirname(path)
                            and os.path.isfile(b.path)
                            and get_file_extension(b.path) not in [".m3u", ".m3u8"]
                        ):
                            m3u_beans_for_delete.append(bean)
                            break
                    return task(beans)

                if path and (get_file_extension(path) == ".cue" and bean not in checked_cue_beans):

                    checked_cue_beans.append(bean)
                    filtered_beans = [
                        b
                        for b in beans
                        if (
                            os.path.dirname(b.path) != os.path.dirname(path)
                            or os.path.isdir(b.path)
                            or get_file_extension(b.path) == ".cue"
                        )
                    ]
                    return task(filtered_beans)
            return beans
Пример #3
0
        def task(rows):
            for row in rows:
                index = self.path[0]
                path = row[index]
                if path and (is_m3u(path) and row not in checked_m3u_rows):
                    checked_m3u_rows.append(row)
                    for r in rows:
                        if (os.path.dirname(r[index]) == os.path.dirname(path)
                                and os.path.isfile(r[index])
                                and not is_m3u(r[index])):
                            m3u_rows_for_delete.append(r)
                            break
                    return task(rows)

                if path and (get_file_extension(path) == ".cue"
                             and row not in checked_cue_rows):

                    checked_cue_rows.append(row)
                    filtered_rows = [
                        r for r in rows
                        if (os.path.dirname(r[index]) != os.path.dirname(path)
                            or os.path.isdir(r[index])
                            or get_file_extension(r[index]) == ".cue")
                    ]
                    return task(filtered_rows)
            return rows
Пример #4
0
def udpate_id3_for_beans(beans):
    for bean in beans:
        if get_file_extension(bean.text) in FC().audio_formats:
            try:
                udpate_id3(bean)
            except Exception, e:
                logging.warn("update id3 error - % s" % e)
        elif get_file_extension(bean.text) in FC().video_formats:
            list = ["ffmpeg", "-i", bean.path, "|", "grep", "1"]#, "|", "cut", "-d", "\' \'", "-f", "4", "|", "sed", "s/,//"
            ffmpeg = Popen(list, universal_newlines=True, stderr=PIPE)
            for line in ffmpeg.stderr:
                if line.strip().startswith('Duration:'):
                    bean.time = os.path.splitext(line.strip().split(" ")[1])[0]
                    break
Пример #5
0
def udpate_id3_for_beans(beans):
    for bean in beans:
        if get_file_extension(bean.text) in FC().audio_formats:
            try:
                udpate_id3(bean)
            except Exception, e:
                logging.warn("update id3 error - % s" % e)
        elif get_file_extension(bean.text) in FC().video_formats:
            list = [
                "ffmpeg", "-i", bean.path, "|", "grep", "1"
            ]  #, "|", "cut", "-d", "\' \'", "-f", "4", "|", "sed", "s/,//"
            ffmpeg = Popen(list, universal_newlines=True, stderr=PIPE)
            for line in ffmpeg.stderr:
                if line.strip().startswith('Duration:'):
                    bean.time = os.path.splitext(line.strip().split(" ")[1])[0]
                    break
Пример #6
0
 def _play(self, bean):
     
     
     self.count_errors = 0
     
     if not bean.path:
         bean.path = get_bean_posible_paths(bean)
     
     if bean.path and bean.type != FTYPE_RADIO and bean.path.startswith("http"):
         if not url_utils.is_exists(bean.path):
             bean.path = None
     
     if not bean.path:            
         if not self.fill_bean_from_vk(bean):
             if self.vk_service.is_show_authorization():
                 return None
                 
             if self.count_errors < 4:
                 time.sleep(0.5)
                 self.count_errors += 1
                 self.next()
        
     if bean.path and os.path.isdir(bean.path):
         return None
     
     self.media_engine.play(bean)  
     self.is_scrobbled = False
     self.start_time = False      
     
     if not get_file_extension(bean.path) in FC().video_formats:
         self.update_info_panel(bean)
         self.set_visible_video_panel(False)
Пример #7
0
 def iter_is_parent(self, ff_row_ref, ff_model, to_tree, to_model, to_parent_iter, pos=INTO_OR_AFTER):
     ff_iter = self.get_iter_from_row_reference(ff_row_ref)
     refs = self.content_filter(ff_iter, ff_model) 
     for ref in refs:
         iter = self.get_iter_from_row_reference(ref)
         file_name = ff_model.get_value(iter, self.path[0])
         ext = get_file_extension(file_name)
         if ext == ".cue" and to_tree.current_view == VIEW_PLAIN:
             last_iter = to_parent_iter
             cue_beans = CueReader(file_name).get_common_beans()
             for bean in cue_beans:
                 row = self.get_row_from_bean(bean)
                 to_child_iter = self.to_add_drag_item(to_tree, to_model, last_iter, None, None, child=True, row=row)
                 last_iter = to_child_iter
         else:
             to_child_iter = self.to_add_drag_item(to_tree, to_model, to_parent_iter, pos, ref, child=True)
         
         """Iters have already changed. Redefine"""
         iter = self.get_iter_from_row_reference(ref)
         
         if  ff_model.iter_n_children(iter):
             to_child_iter = self.iter_is_parent(ref, ff_model, to_tree, to_model, to_child_iter)
         if to_tree.current_view == VIEW_PLAIN:
             to_parent_iter = to_child_iter
     return to_child_iter
Пример #8
0
    def add_m3u(self,
                from_model=None,
                from_iter=None,
                to_tree=None,
                to_model=None,
                to_iter=None,
                pos=None,
                row=None):
        if row:
            if get_file_extension(row[self.path[0]]) in [".m3u", ".m3u8"]:
                m3u_file_path = row[self.path[0]]
                m3u_title = row[self.text[0]]
            else:
                return
        else:
            if ((from_model.get_value(from_iter, 0).lower().endswith(".m3u") or
                 from_model.get_value(from_iter, 0).lower().endswith(".m3u8"))
                    and from_model.get_model() is not to_model):
                m3u_file_path = from_model.get_value(from_iter, self.path[0])
                m3u_title = from_model.get_value(from_iter, self.text[0])
            else:
                return

            if m3u_file_path.startswith("http//"):
                return None

        paths = m3u_reader(m3u_file_path)
        paths.insert(0, os.path.splitext(m3u_title)[0])
        first_path = paths[0][0] if isinstance(paths[0], list) else paths[0]
        if first_path:
            list_path = first_path[0].split("/")
            name = list_path[len(list_path) - 2]
            parent = FModel(name)

        new_iter = None
        for i, path in enumerate(paths):
            if isinstance(path, list):
                text = path[1]
                path = path[0]
                bean = FModel(path, path).add_is_file(True)
                if text: bean.text = text

            elif not i:
                bean = FModel(_("m3u playlist: ") +
                              path).add_is_file(False).add_font("bold")
            else:
                bean = FModel(path, path).parent(parent)

            row = self.fill_beans_and_get_rows([bean])[0]

            if new_iter:
                to_iter = new_iter
            new_iter = self.to_add_drag_item(to_tree,
                                             to_model,
                                             to_iter,
                                             pos,
                                             None,
                                             row=row)

        return True
Пример #9
0
    def _plain_append_all(self, beans, parent=None):
        logging.debug("begin plain append all")
        if not beans:
            return

        parent_iter = None
        if parent:
            parent_iter = self.get_iter_from_bean(parent)

        self.current_view = VIEW_PLAIN

        normalized = []
        for model in beans:
            if model.path and model.path.lower().endswith(".iso.wv"):
                logging.debug("begin normalize iso.wv" + str(model.path))
                all = get_beans_from_iso_wv(model.path)

                if not all:
                    break
                for inner in all:
                    normalized.append(inner)
            else:
                normalized.append(model)

        beans = normalized

        counter = 0
        for bean in beans:
            if not bean.path or not get_file_extension(bean.path) == ".cue":
                if bean.is_file and FC().numbering_by_order:
                    counter += 1
                    bean.tracknumber = counter
                else:
                    counter = 0
            self._plain_append(bean, parent_iter)
Пример #10
0
def get_image_by_path(path):

    dir = path if os.path.isdir(path) else os.path.dirname(path)

    if not os.path.isdir(dir):
        return None

    ext_list = ['.jpg', '.png', '.bmp', '.tiff', '.gif']

    dirs = []
    files = []

    for item in os.listdir(dir):
        if os.path.isdir(os.path.join(dir, item)) and item.lower().startswith("cover"):
            dirs.append(item)
        elif get_file_extension(item) in ext_list:
            files.append(item)

    if not files and not dirs:
        return None

    if files:
        for file in files:
            for name in ("cover", "face", "front", "case"):
                if name in file.lower():
                    return os.path.join(dir, file)
        return os.path.join(dir, files[0])

    if dirs:
        for subdir in dirs:
            image = get_image_by_path(os.path.join(dir, subdir))
            if image:
                return image
Пример #11
0
            def task(to_iter):
                all_rows = []
                for ff_path in ff_paths:
                    ff_iter = ff_model.get_iter(ff_path)
                    beans = self.get_all_beans_by_parent(ff_model, ff_iter)
                    all_rows += self.fill_beans_and_get_rows(
                        beans, self.simple_content_filter)

                self.spinner = False

                for i, row in enumerate(all_rows):
                    pos = gtk.TREE_VIEW_DROP_AFTER if i else to_filter_pos
                    if row[self.path[0]] and get_file_extension(
                            row[self.path[0]]) in [".m3u", ".m3u8"]:
                        self.add_m3u(ff_model, ff_iter, to_tree, to_model,
                                     to_iter, pos)
                        continue
                    to_iter = self.to_add_drag_item(to_tree,
                                                    to_model,
                                                    to_iter,
                                                    pos,
                                                    None,
                                                    row=row)
                self.controls.search_progress.stop()
                self.update_tracknumber()
Пример #12
0
def set_cover_from_tags(bean):
    try:
        ext = get_file_extension(bean.path)
        if ext == ".mp3":
            data = _get_pic_from_mp3(ID3(bean.path))
        elif ext == ".flac":
            data = _get_pic_from_flac(FLAC(bean.path))
        else:
            return None
        if data:
            filename = os.path.join(COVERS_DIR, str(crc32(bean.path)) + '.jpg')
            fd = NamedTemporaryFile()
            fd.write(data.data)
            pixbuf = Pixbuf.new_from_file(fd.name)
            pixbuf.savev(filename, "jpeg", ["quality"], ["90"])
            fd.close()
            bean.image = filename
            basename = os.path.splitext(os.path.basename(filename))[0]
            cache_dict = FCache().covers
            if basename in cache_dict:
                cache_dict[basename].append(bean.text)
            else:
                cache_dict[basename] = [bean.text]
            return filename

    except Exception, e:
        pass
Пример #13
0
    def _play(self, bean):

        self.count_errors = 0

        if not bean.path:
            bean.path = get_bean_posible_paths(bean)

        if bean.path and bean.type != FTYPE_RADIO and bean.path.startswith(
                "http"):
            if not url_utils.is_exists(bean.path):
                bean.path = None

        if not bean.path:
            if not self.fill_bean_from_vk(bean):
                if self.vk_service.is_show_authorization():
                    return None

                if self.count_errors < 4:
                    time.sleep(0.5)
                    self.count_errors += 1
                    self.next()

        if bean.path and os.path.isdir(bean.path):
            return None

        self.media_engine.play(bean)
        self.is_scrobbled = False
        self.start_time = False

        if not get_file_extension(bean.path) in FC().video_formats:
            self.update_info_panel(bean)
            self.set_visible_video_panel(False)
Пример #14
0
 def _plain_append_all(self, beans, parent=None):
     logging.debug("begin plain append all")
     if not beans:
         return
     
     parent_iter = None
     if parent:
         parent_iter = self.get_iter_from_bean(parent)
     
     self.current_view = VIEW_PLAIN
     
     normalized = []
     for model in beans:
         if model.path and model.path.lower().endswith(".iso.wv"):
             logging.debug("begin normalize iso.wv" + str(model.path))
             all = get_beans_from_iso_wv(model.path)
             
             if not all:
                 break
             for inner in all:
                 normalized.append(inner)
         else:
             normalized.append(model)
     
     beans = normalized
           
     counter = 0
     for bean in beans:
         if not bean.path or not get_file_extension(bean.path) == ".cue":                                        
             if bean.is_file and FC().numbering_by_order:
                 counter += 1
                 bean.tracknumber = counter
             else: 
                 counter = 0
         self._plain_append(bean, parent_iter)
Пример #15
0
def get_image_by_path(path):

    dir = path if os.path.isdir(path) else os.path.dirname(path)

    if not os.path.isdir(dir):
        return None

    ext_list = ['.jpg', '.png', '.bmp', '.tiff', '.gif']

    dirs = []
    files = []

    for item in os.listdir(dir):
        if os.path.isdir(os.path.join(dir, item)) and item.lower().startswith("cover"):
            dirs.append(item)
        elif get_file_extension(item) in ext_list:
            files.append(item)

    if not files and not dirs:
        return None

    if files:
        for file in files:
            for name in ("cover", "face", "front", "case"):
                if name in file.lower():
                    return os.path.join(dir, file)
        return os.path.join(dir, files[0])

    if dirs:
        for subdir in dirs:
            image = get_image_by_path(os.path.join(dir, subdir))
            if image:
                return image
Пример #16
0
 def task(to_tree, to_model):
     all_rows = []
     for i, path in enumerate(paths):
         from_iter = from_model.get_iter(path)
         row = self.get_row_from_model_iter(from_model, from_iter)
     
         if not i and not current:
             name = row[0]
             self.controls.notetabs._append_tab(name)
             to_tree = self.controls.notetabs.get_current_tree() # because to_tree has changed
             to_model = to_tree.get_model().get_model()
         
         if self.add_m3u(from_model, from_iter, to_tree, to_model, None, None): 
             continue
         beans = self.get_all_beans_by_parent(from_model, from_iter)
         all_rows += self.fill_beans_and_get_rows(beans, self.simple_content_filter)
     self.spinner = False
     for row in all_rows:
         if get_file_extension(row[self.path[0]]) in [".m3u", ".m3u8"]:
             if self.add_m3u(to_model=to_model, row=row):
                 continue
         self.to_add_drag_item(to_tree, to_model, None, None, None, row=row)
     to_tree.update_tracknumber()
     self.controls.search_progress.stop()
 
     if not current:
         '''gobject because rebuild_as_plain use it too'''
         gobject.idle_add(self.controls.play_first_file_in_playlist)
Пример #17
0
def get_mutagen_audio (path):
    logging.debug("GET mutagen audio" + path)
    ext = get_file_extension(path)
    audio = None
    if ext == ".flac":
        audio = FLAC(path)
    if ext == ".ape":
        audio = MonkeysAudio(path)
    if ext == ".mp3":
        audio = MP3(path, ID3=EasyID3)
    if ext == ".wv":
        audio = WavPack(path)
    if ext == ".ogg":
        try:
            audio = OggVorbis(path)
        except:
            from foobnix.thirdparty.mutagen.oggtheora import OggTheora
            try:
                audio = OggTheora(path)
            except:
                from foobnix.thirdparty.mutagen.oggflac import OggFLAC
                try:
                    audio = OggFLAC(path)
                except:
                    from foobnix.thirdparty.mutagen.oggspeex import OggSpeex
                    try:
                        audio = OggSpeex(path)
                    except:
                        logging.error("This file in not ogg format")
                                    
    if ext == ".m4a" or ext == ".mp4" or ext == ".mkv":
        audio = MP4(path)
        
    return audio 
Пример #18
0
def udpate_id3_for_beans(beans):
    for bean in beans:
        if get_file_extension(bean.text) in FC().audio_formats:
            try:
                udpate_id3(bean)
            except Exception, e:
                logging.warn("update id3 error")
Пример #19
0
def get_mutagen_audio (path):
    logging.debug("GET mutagen audio" + path)
    ext = get_file_extension(path)
    audio = None
    if ext == ".flac":
        audio = FLAC(path)
    if ext == ".ape":
        audio = MonkeysAudio(path)
    if ext == ".mp3":
        audio = MP3(path, ID3=EasyID3)
    if ext == ".wv":
        audio = WavPack(path)
    if ext == ".ogg":
        try:
            audio = OggVorbis(path)
        except:
            from foobnix.thirdparty.mutagen.oggtheora import OggTheora
            try:
                audio = OggTheora(path)
            except:
                from foobnix.thirdparty.mutagen.oggflac import OggFLAC
                try:
                    audio = OggFLAC(path)
                except:
                    from foobnix.thirdparty.mutagen.oggspeex import OggSpeex
                    try:
                        audio = OggSpeex(path)
                    except:
                        logging.error("This file in not ogg format")
                                    
    if ext == ".m4a" or ext == ".mp4" or ext == ".mkv":
        audio = MP4(path)
        
    return audio 
Пример #20
0
def get_all_music_with_id3_by_path(path, with_cue_filter=None):
    beans = simple_scanner(path, None)
    all = []
    if with_cue_filter:
        for bean in beans:
            if get_file_extension(bean.path) == ".cue":
                all.append(bean)
    beans = all if all else beans
    return update_id3_wind_filtering(beans)
Пример #21
0
def get_all_music_with_id3_by_path(path, with_cue_filter=None):
    beans = simple_scanner(path, None)
    all = []
    if with_cue_filter:
        for bean in beans:
            if get_file_extension(bean.path) == ".cue":
                all.append(bean)
    beans = all if all else beans
    return update_id3_wind_filtering(beans)
Пример #22
0
def update_id3_for_beans(beans):
    for bean in beans:
        if get_file_extension(bean.text) in FC().audio_formats:
            try:
                update_id3(bean)
            except Exception, e:
                logging.warn("update id3 error - % s" % e)
        if bean.text:
            if (bean.text[0] == "/") or (len(bean.text)>1 and bean.text[1] == ":"):
                bean.text = os.path.basename(bean.text)
Пример #23
0
def update_id3_for_pls(beans):
    result = []
    for bean in beans:
        if bean.path and get_file_extension(bean.path) in [".pls"]:
            reader = PLSReader(bean.path)
            plsbeans = reader.get_common_beans()
            for bean in plsbeans:
                result.append(bean)
        else:
            result.append(bean)
    return result
Пример #24
0
def update_id3_for_pls(beans):
    result = []
    for bean in beans:
        if bean.path and get_file_extension(bean.path) in [".pls"]:
            reader = PLSReader(bean.path)
            plsbeans = reader.get_common_beans()
            for bean in plsbeans:
                result.append(bean)
        else:
            result.append(bean)
    return result
Пример #25
0
def update_id3_for_m3u(beans):
    result = []
    for bean in beans:
        if bean.path and get_file_extension(bean.path) in [".m3u", ".m3u8"]:
            reader = M3UReader(bean.path)
            m3u_beans = reader.get_common_beans()
            for bean in m3u_beans:
                result.append(bean)
        else:
            result.append(bean)
    return result
Пример #26
0
 def check_for_media(self, args):         
     dirs = []
     files = []
     for arg in args:            
         if os.path.isdir(arg):
             dirs.append(arg)
         elif os.path.isfile(arg) and get_file_extension(arg) in FC().all_support_formats:
             files.append(arg)
     if dirs:
         self.on_add_folders(dirs)
     elif files:            
         self.on_add_files(files)
Пример #27
0
 def check_for_media(self, args):         
     dirs = []
     files = []
     for arg in args:            
         if os.path.isdir(arg):
             dirs.append(arg)
         elif os.path.isfile(arg) and get_file_extension(arg) in FC().all_support_formats:
             files.append(arg)
     if dirs:
         self.on_add_folders(dirs)
     elif files:            
         self.on_add_files(files)
Пример #28
0
 def append(self, paths):
     for i, path in enumerate(paths):
         if os.path.isdir(path):
             listdir = filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x),
                              [os.path.join(path, f) for f in os.listdir(path)])
             for k, p in enumerate(listdir):
                 paths.insert(i + k + 1, p)
     rows = self.file_paths_to_rows(paths)
     if not rows:
         return
     #rows = self.playlist_filter(rows)
     for row in rows:
         self.model.append(None, row)
     thread.start_new_thread(self.safe_fill_treerows, ())
Пример #29
0
        def task(rows):
            for row in rows:
                index = self.path[0]
                path = row[index]
                if path and (is_m3u(path)
                             and row not in checked_m3u_rows):
                    checked_m3u_rows.append(row)
                    for r in rows:
                        if (os.path.dirname(r[index]) == os.path.dirname(path) and os.path.isfile(r[index])
                            and not is_m3u(r[index])):
                                m3u_rows_for_delete.append(r)
                                break
                    return task(rows)

                if path and (get_file_extension(path) == ".cue"
                             and row not in checked_cue_rows):

                    checked_cue_rows.append(row)
                    filtered_rows = [r for r in rows if (os.path.dirname(r[index]) != os.path.dirname(path)
                                                           or os.path.isdir(r[index])
                                                           or get_file_extension(r[index]) == ".cue")]
                    return task(filtered_rows)
            return rows
Пример #30
0
 def update_tracknumber(self):
     self.current_view = VIEW_PLAIN
     tn = self.tracknumber[0]
     path = self.path[0]
     isfile = self.is_file[0]
     counter = 0
     for row in self.model:
         if not row[path] or not get_file_extension(row[path]) == ".cue":
             if row[isfile] and FC().numbering_by_order:
                 counter += 1
             else:
                 counter = 0
             if counter:
                 row[tn] = counter
Пример #31
0
 def append(self, paths):
     for i, path in enumerate(paths):
         if os.path.isdir(path):
             listdir = filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x),
                              [os.path.join(path, f) for f in os.listdir(path)])
             for k, p in enumerate(listdir):
                 paths.insert(i + k + 1, p)
     rows = self.file_paths_to_rows(paths)
     if not rows:
         return
     #rows = self.playlist_filter(rows)
     for row in rows:
         self.model.append(None, row)
     thread.start_new_thread(self.safe_fill_treerows, ())
Пример #32
0
 def update_tracknumber(self):
     self.current_view = VIEW_PLAIN
     tn = self.tracknumber[0]
     path = self.path[0]
     isfile = self.is_file[0]
     counter = 0
     for row in self.model:
         if not row[path] or not get_file_extension(row[path]) == ".cue":
             if row[isfile] and FC().numbering_by_order:
                 counter += 1
             else:
                 counter = 0
             if counter:
                 row[tn] = counter
Пример #33
0
 def add_m3u(self, from_model=None, from_iter=None, to_tree=None, to_model=None,
             to_iter=None, pos=None, row=None):
     if row:
         if get_file_extension(row[self.path[0]]) in [".m3u", ".m3u8"]:
             m3u_file_path = row[self.path[0]]
             m3u_title = row[self.text[0]]
         else:
             return
     else:
         if ((from_model.get_value(from_iter, 0).lower().endswith(".m3u") 
         or from_model.get_value(from_iter, 0).lower().endswith(".m3u8"))
         and from_model.get_model() is not to_model):
                 m3u_file_path = from_model.get_value(from_iter, self.path[0])
                 m3u_title = from_model.get_value(from_iter, self.text[0])
         else:
             return
         
         if m3u_file_path.startswith("http//"):
             return None
         
     paths = m3u_reader(m3u_file_path)
     paths.insert(0, os.path.splitext(m3u_title)[0])
     first_path = paths[0][0] if isinstance(paths[0], list) else paths[0]
     if first_path:
         list_path = first_path[0].split("/")
         name = list_path[len(list_path) - 2]
         parent = FModel(name)
         
     new_iter = None
     for i, path in enumerate(paths):
         if isinstance(path, list):
             text = path[1]
             path = path[0]
             bean = FModel(path, path).add_is_file(True)
             if text: bean.text = text
             
                     
         elif not i:
             bean = FModel(_("m3u playlist: ") + path).add_is_file(False).add_font("bold")
         else:
             bean = FModel(path, path).add_is_file(True).parent(parent)
         
         row = self.fill_beans_and_get_rows([bean])[0]                               
                    
         if new_iter:
             to_iter = new_iter
         new_iter = self.to_add_drag_item(to_tree, to_model, to_iter, pos, None,  row=row)
         
     return True
Пример #34
0
 def check_for_media(self, args):
     dirs = []
     files = []
     for arg in args:
         if os.path.isdir(arg):
             dirs.append(arg)
         elif os.path.isfile(arg) and get_file_extension(arg) in FC().all_support_formats:
             files.append(arg)
     if dirs:
         self.on_add_folders(dirs)
     elif files:
         self.on_add_files(files)
         try:
             self.play_first_added(files)
         except:
             logging.error("Can't to play first added file")
Пример #35
0
    def _play(self, bean):
        if not bean.path:
            bean.path = get_bean_posible_paths(bean)

        if not bean.path:
            if not self.fill_bean_from_vk(bean):

                def post_task():
                    self._play(bean)

                if self.vk_service.is_show_authorization(post_task):
                    return

        if not self.check_path(bean.path):
            if bean.iso_path and os.path.exists(bean.iso_path):
                logging.info("Try to remount " + bean.iso_path)
                mount_tmp_iso(bean.iso_path)
            else:
                resource = bean.path if bean.path else bean.text
                logging.error("Resourse " + resource + " not found")
                self.media_engine.state_stop(show_in_tray=False)
                self.statusbar.set_text(_("Resource not found"))
                self.seek_bar.set_text(_("Resource not found"))
                self.count_errors += 1
                time.sleep(2)
                if self.count_errors < 4:
                    if self.play_lock.locked():
                        self.play_lock.release()
                    self.next()
                else:
                    self.seek_bar.set_text(_("Stopped. No resources found"))

                return

        elif os.path.isdir(bean.path):
            return

        self.count_errors = 0
        self.media_engine.play(bean)
        self.is_scrobbled = False
        self.start_time = False

        if not get_file_extension(bean.path) in FC().video_formats:
            if bean.type != FTYPE_RADIO:
                self.update_info_panel(bean)
            self.set_visible_video_panel(False)
Пример #36
0
 def play(self, bean):
     self.statusbar.set_text("")
     if not bean:
         self.state_stop()
         return None
     
     if not bean.is_file: 
         self.state_stop()
         return None
     
     if not bean.path:
         bean.path = get_bean_posible_paths(bean)
                 
     if not bean.path:            
         if not self.fill_bean_from_vk(bean):
             if self.count_errors < 4:
                 logging.debug("Error happen [%s] %s" % (self.count_errors, FCBase().vk_login))
                 time.sleep(0.5)
                 self.count_errors += 1
                 self.next()
             
     
     if bean.path and os.path.isdir(bean.path):
         self.state_stop()
         return None
     
     if bean.type == FTYPE_RADIO:
         self.record.show()
     else:
         self.record.hide()
             
     self.seek_bar.clear()
     self.count_errors = 0
     self.statusbar.set_text(bean.info)
     self.trayicon.set_text(bean.text)
     
     self.movie_window.set_text(bean.text)        
     self.main_window.set_title(bean.text)
     
     self.media_engine.play(bean)  
     self.is_scrobbled = False
     self.start_time = False      
     
     self.update_info_panel(bean)
     if not get_file_extension(bean.path) in FC().video_formats:
         self.set_visible_video_panel(False)
Пример #37
0
 def task(to_iter):
     all_rows = []
     for ff_path in ff_paths:
         ff_iter = ff_model.get_iter(ff_path)
         beans = self.get_all_beans_by_parent(ff_model, ff_iter)
         all_rows += self.fill_beans_and_get_rows(beans, self.simple_content_filter)
     
     self.spinner = False
         
     for i, row in enumerate(all_rows):
             pos = AFTER if i else to_filter_pos
             if row[self.path[0]] and get_file_extension(row[self.path[0]]) in [".m3u", ".m3u8"]:
                 self.add_m3u(ff_model, ff_iter, to_tree, to_model, to_iter, pos)
                 continue
             to_iter = self.to_add_drag_item(to_tree, to_model, to_iter, pos, None, row=row)
     self.controls.search_progress.stop()
     self.update_tracknumber()
Пример #38
0
def get_mutagen_audio (path):
    logging.debug("GET mutagen audio" + path)
    ext = get_file_extension(path)
    audio = None
    if ext == ".flac":
        audio = FLAC(path)
    if ext == ".ape":
        audio = MonkeysAudio(path)
    if ext == ".mp3":
        audio = MP3(path, ID3=EasyID3)
    if ext == ".wv":
        audio = WavPack(path)
    if ext == ".ogg":
        audio = OggFileType(path)
    if ext == ".m4a" or ext == ".mp4":
        audio = MP4(path)
        
    return audio
Пример #39
0
    def iter_is_parent(self,
                       ff_row_ref,
                       ff_model,
                       to_tree,
                       to_model,
                       to_parent_iter,
                       pos=gtk.TREE_VIEW_DROP_INTO_OR_AFTER):
        ff_iter = self.get_iter_from_row_reference(ff_row_ref)
        refs = self.content_filter(ff_iter, ff_model)
        for ref in refs:
            iter = self.get_iter_from_row_reference(ref)
            file_name = ff_model.get_value(iter, self.path[0])
            ext = get_file_extension(file_name)
            if ext == ".cue" and to_tree.current_view == VIEW_PLAIN:
                last_iter = to_parent_iter
                cue_beans = CueReader(file_name).get_common_beans()
                for bean in cue_beans:
                    row = self.get_row_from_bean(bean)
                    to_child_iter = self.to_add_drag_item(to_tree,
                                                          to_model,
                                                          last_iter,
                                                          None,
                                                          None,
                                                          child=True,
                                                          row=row)
                    last_iter = to_child_iter
            else:
                to_child_iter = self.to_add_drag_item(to_tree,
                                                      to_model,
                                                      to_parent_iter,
                                                      pos,
                                                      ref,
                                                      child=True)
            """Iters have already changed. Redefine"""
            iter = self.get_iter_from_row_reference(ref)

            if ff_model.iter_n_children(iter):
                to_child_iter = self.iter_is_parent(ref, ff_model, to_tree,
                                                    to_model, to_child_iter)
            if to_tree.current_view == VIEW_PLAIN:
                to_parent_iter = to_child_iter
        return to_child_iter
Пример #40
0
 def content_filter(self, from_iter, from_model):
     cue_refs = []
     folder_refs = []
     not_cue_refs = []
     for n in xrange(from_model.iter_n_children(from_iter)):
         from_child_iter = from_model.iter_nth_child(from_iter, n)
         row_reference = self.get_row_reference_from_iter(from_model, from_child_iter)
         ext = get_file_extension(from_model.get_value(from_child_iter, self.path[0]))
         if ext in [".m3u", ".m3u8"]: 
             logging.info("m3u is found. Skip it")
             continue
         elif ext == ".cue":
             logging.info("Cue is found. Skip other files")
             cue_refs.append(row_reference)
         else:
             if from_model.iter_has_child(from_child_iter):
                 folder_refs.append(row_reference)
             not_cue_refs.append(row_reference)
     
     return cue_refs + folder_refs if cue_refs else not_cue_refs
Пример #41
0
 def _play(self, bean):
     self.count_errors = 0
     
     if not bean.path:
         bean.path = get_bean_posible_paths(bean)
     
     if bean.path and bean.type != FTYPE_RADIO and bean.path.startswith("http"):
         if not url_utils.is_exists(bean.path):
             bean.path = None
     
     if not bean.path:            
         if not self.fill_bean_from_vk(bean):
             def post_task():
                 self._play(bean)
             if self.vk_service.is_show_authorization(post_task):
                 return None
                 
             if self.count_errors < 4:
                 time.sleep(0.5)
                 self.count_errors += 1
                 if self.play_lock.locked():
                     self.play_lock.release()
                 self.next()
        
     if bean.path:
         if not os.path.exists(bean.path):
             if bean.iso_path and os.path.exists(bean.iso_path):
                 logging.info("Try to remount " + bean.iso_path)
                 mount_tmp_iso(bean.iso_path)
             elif not bean.path.startswith("http"):
                 logging.error("File " + bean.path + " not found")
         elif os.path.isdir(bean.path):
                 return None
     self.media_engine.play(bean)
     self.is_scrobbled = False
     self.start_time = False      
     
     if not get_file_extension(bean.path) in FC().video_formats:
         if bean.type != FTYPE_RADIO:
             self.update_info_panel(bean)
         self.set_visible_video_panel(False)
Пример #42
0
def normalize_text(line):
    if not line:
        return ""
    line = urllib.parse.unquote(line)
    """find in extension"""
    for element in ("[", "(", "*", "#"):
        index = line.find(element)
        if index >= 0:
            line = line[:index]
        index = -1
    """find in prefix"""
    prefix_index = re.search('^([ 0-9.-]*)', line).end()
    line = line[prefix_index:]

    line = capitalize_string(line)
    """remove extension"""
    ext = get_file_extension(line)
    if ext in FC().all_support_formats:
        line = line.replace(ext, "")

    return line.strip()
Пример #43
0
def get_image_by_path(path):
    dir = os.path.dirname(path)
    if not os.path.isdir(dir):
        return None

    ext_list = ['.jpg', '.png', '.bmp', '.tiff', '.gif']

    files = [
        file for file in os.listdir(dir)
        if get_file_extension(file) in ext_list
    ]

    if not files:
        return None

    for file in files:
        for name in ("cover", "face", "front", "case"):
            if name in file.lower():
                return os.path.join(dir, file)

    return os.path.join(dir, files[0])
Пример #44
0
    def content_filter(self, from_iter, from_model):
        cue_refs = []
        folder_refs = []
        not_cue_refs = []
        for n in xrange(from_model.iter_n_children(from_iter)):
            from_child_iter = from_model.iter_nth_child(from_iter, n)
            row_reference = self.get_row_reference_from_iter(
                from_model, from_child_iter)
            ext = get_file_extension(
                from_model.get_value(from_child_iter, self.path[0]))
            if ext in [".m3u", ".m3u8"]:
                logging.info("m3u is found. Skip it")
                continue
            elif ext == ".cue":
                logging.info("Cue is found. Skip other files")
                cue_refs.append(row_reference)
            else:
                if from_model.iter_has_child(from_child_iter):
                    folder_refs.append(row_reference)
                not_cue_refs.append(row_reference)

        return cue_refs + folder_refs if cue_refs else not_cue_refs
Пример #45
0
def normalize_text(line):
    if not line:
        return ""
    line = urllib.unquote(line)
    """find in extension"""
    for element in ("[", "(", "*"):
        index = line.find(element)
        if index >= 0:            
            line = line[:index]
        index = -1
        
    """find in prefix"""
    prefix_index = re.search('^([ 0-9.-]*)', line).end()   
    line = line[prefix_index:]
    
    line = capitalize_string(line)
    
    """remove extension"""
    ext = get_file_extension(line)  
    if ext in FC().all_support_formats:                
        line = line.replace(ext, "")
    
    return line.strip()
Пример #46
0
        def task(to_tree, to_model):
            all_rows = []
            for i, path in enumerate(paths):
                from_iter = from_model.get_iter(path)
                row = self.get_row_from_model_iter(from_model, from_iter)

                if not i and not current:
                    name = row[0]
                    self.controls.notetabs._append_tab(name)
                    to_tree = self.controls.notetabs.get_current_tree(
                    )  # because to_tree has changed
                    to_model = to_tree.get_model().get_model()

                if self.add_m3u(from_model, from_iter, to_tree, to_model, None,
                                None):
                    continue
                beans = self.get_all_beans_by_parent(from_model, from_iter)
                all_rows += self.fill_beans_and_get_rows(
                    beans, self.simple_content_filter)
            self.spinner = False
            for row in all_rows:
                if get_file_extension(row[self.path[0]]) in [".m3u", ".m3u8"]:
                    if self.add_m3u(to_model=to_model, row=row):
                        continue
                self.to_add_drag_item(to_tree,
                                      to_model,
                                      None,
                                      None,
                                      None,
                                      row=row)
            to_tree.update_tracknumber()
            self.controls.search_progress.stop()

            if not current:
                '''gobject because rebuild_as_plain use it too'''
                gobject.idle_add(self.controls.play_first_file_in_playlist)
Пример #47
0
    def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp):
        logging.debug('Playlist on_drag_data_received')
        model = self.get_model().get_model()
        drop_info = self.get_dest_row_at_pos(x, y)

        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)

        files = sorted([file for file in get_files_from_gtk_selection_data(selection)
                if os.path.isdir(file) or get_file_extension(file) in FC().all_support_formats],
                key=lambda x: x[self.text[0]])
        if files:
            '''dnd from the outside of the player'''
            if self.is_empty():
                if len(files) == 1 and os.path.isdir(files[0]):
                    tabname = os.path.basename(files[0])
                else:
                    tabname = os.path.split(os.path.dirname(files[0]))[1]
                self.controls.notetabs.rename_tab(self.scroll, tabname)
            for i, file in enumerate(files):
                if os.path.isdir(file):
                    sorted_dirs = []
                    sorted_files = []
                    for f in sorted(os.listdir(file), key=lambda x: x):
                        f = os.path.join(file, f)
                        if os.path.isdir(f):
                            sorted_dirs.append(f)
                        elif get_file_extension(f) in FC().all_support_formats:
                            sorted_files.append(f)

                    listdir = sorted_dirs + sorted_files
                    '''
                    listdir = sorted(filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x),
                                     [os.path.join(file, f) for f in os.listdir(file)]), key=lambda x: x)
                    '''
                    for k, path in enumerate(listdir):
                        files.insert(i + k + 1, path)

            rows = self.file_paths_to_rows(files)
            if not rows:
                return
            rows = self.playlist_filter(rows)
            for row in rows:
                if drop_info:
                    if (position == Gtk.TREE_VIEW_DROP_BEFORE
                        or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                        model.insert_before(None, iter, row)
                    else:
                        model.insert_after(None, iter, row)
                        iter = model.iter_next(iter)
                else:
                    model.append(None, row)

        else:
            '''dnd inside the player'''
            # ff - from_filter
            ff_tree = Gtk.drag_get_source_widget(context)
            ff_model, ff_paths = ff_tree.get_selection().get_selected_rows()
            treerows = [ff_model[ff_path] for ff_path in ff_paths]

            if self is ff_tree:
                '''internal dnd'''
                ff_row_refs = [Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths]
                for ff_row_ref in ff_row_refs:
                    ff_iter = self.get_iter_from_row_reference(ff_row_ref)
                    f_iter = ff_model.convert_iter_to_child_iter(ff_iter)
                    if drop_info:
                        if (position == Gtk.TREE_VIEW_DROP_BEFORE
                            or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                            model.move_before(f_iter, iter)
                        else:
                            model.move_after(f_iter, iter)
                            iter = model.iter_next(iter)
                    else:
                        model.move_before(f_iter, None)
                return

            else:
                '''dnd from other tree'''
                if self.is_empty():
                    path = treerows[0][self.path[0]]
                    if path:
                        if len(treerows) == 1 and os.path.isdir(path):
                            tabname = os.path.basename(path)
                        else:
                            tabname = os.path.split(os.path.dirname(path))[1]
                        self.controls.notetabs.rename_tab(self.scroll, tabname)
                    else:
                        pass
                for i, treerow in enumerate(treerows):

                    for k, ch_row in enumerate(treerow.iterchildren()):
                        treerows.insert(i + k + 1, ch_row)

                #treerows = self.playlist_filter(treerows)

                for i, treerow in enumerate(treerows):
                    if is_playlist(treerow[self.path[0]]):
                        rows = self.file_paths_to_rows([treerow[self.path[0]]])
                        if rows:
                            rows.reverse()
                            map(lambda row: treerows.insert(i + 1, row), rows)
                            continue
                    row = [col for col in treerow]
                    if drop_info:
                        if (position == Gtk.TREE_VIEW_DROP_BEFORE
                            or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                            model.insert_before(None, iter, row)
                        else:
                            model.insert_after(None, iter, row)
                            iter = model.iter_next(iter)
                    else:
                        model.append(None, row)


        thread.start_new_thread(self.safe_fill_treerows, ())

        context.finish(True, False, timestamp)
        self.stop_emission('drag-data-received')
        return True
Пример #48
0
def is_m3u(path):
    extension = get_file_extension(path)
    if extension and extension.lower() in [".m3u", ".m3u8"]:
        return True
    return False
Пример #49
0
    def parse(self):
        if self.embedded_cue:
            data = self.embedded_cue
        else:
            file = open(self.cue_path, "r")
            data = file.read()
        code = self.code_detecter(correct_encoding(data))
        data = data.replace('\r\n', '\n').split('\n')

        title = ""
        performer = ""
        index = "00:00:00"
        full_file = None

        self.cue_file.image = get_image_by_path(self.cue_path)

        self.files_count = 0

        for line in data:
            if not self.is_valid and not line.startswith(FILE):
                continue
            else: self.is_valid = True

            try:
                line = unicode(line, code)
            except:
                logging.error("There is some problems while converting in unicode")

            line = str(line).strip()
            if not line:
                continue

            if line.startswith(TITLE):
                title = self.get_line_value(line)
                if self.files_count == 0:
                    self.cue_file.title = title


            if line.startswith(PERFORMER):
                performer = self.get_line_value(line)
                if self.files_count == 0:
                    self.cue_file.performer = performer

            if line.startswith(FILE):
                self.files_count += 1
                file = self.get_line_value(line)
                file = os.path.basename(file)

                if "/" in file:
                    file = file[file.rfind("/")+1:]
                if "\\" in file:
                    file = file[file.rfind("\\")+1:]

                dir = os.path.dirname(self.cue_path)
                full_file = os.path.join(dir, file)
                logging.debug("CUE source" + full_file)
                exists = os.path.exists(full_file)
                """if there no source cue file"""

                if not exists:
                    """try to find other source"""
                    ext = file_utils.get_file_extension(full_file)
                    nor = full_file[:-len(ext)]
                    logging.info("Normalized path" + nor)

                    find_source = False
                    for support_ext in FC().audio_formats:
                        try_name = nor + support_ext
                        if os.path.exists(try_name):
                            full_file = try_name
                            logging.debug("Found source for cue file name" + try_name)
                            find_source = True
                            break

                    if not find_source:
                        self.is_valid = False
                        self.files_count -= 1
                        logging.warn("Can't find source for " + line + "  Check source file name")
                        continue

                if self.files_count == 0:
                    self.cue_file.file = full_file

            if line.startswith(INDEX):
                index = self.get_line_value(line)

            if line.startswith("INDEX 01"):
                cue_track = CueTrack(title, performer, index, full_file)
                self.cue_file.append_track(cue_track)

        logging.debug("CUE file parsed " + str(self.cue_file.file))
        return self.normalize()
Пример #50
0
    def play(self, bean):
        self.bean = bean
        
        if not bean:
            return None
        
        path = bean.path

        if not path:
            logging.error("Can't play empty path!!!")
            return None
        
        self.state_stop()
        
        if hasattr(self, "pipeline"):
            self.pipeline.set_state(gst.STATE_NULL)
        
        self.player = self.gstreamer_player()
        
        """equlizer settings"""
        if FC().is_eq_enable:
            pre = self.controls.eq.get_preamp()
            bands = self.controls.eq.get_bands()
            self.set_all_bands(pre, bands)
        
        if path.startswith("http://"):
            self.radio_path = get_radio_source(path)
            logging.debug("Try To play path" + self.radio_path)
            
            if self.bean.type == FTYPE_RADIO:
                time.sleep(2)
                    
            uri = self.radio_path

            self.notify_title(uri)
        else:
            uri = 'file://' + urllib.pathname2url(path)
            if os.name == 'nt':
                uri = 'file:' + urllib.pathname2url(path)

        logging.info("Gstreamer try to play" + uri)
        self.player.set_property("uri", uri)
        
        self.state_pause()
        time.sleep(0.1)        
        if self.remembered_seek_position:
            self.player.seek_simple(gst.Format(gst.FORMAT_TIME), gst.SEEK_FLAG_FLUSH, self.remembered_seek_position)
        else:
            self.seek_seconds(bean.start_sec)
        
        self.remembered_seek_position = 0
        
        self.state_play()
        
        '''trick to mask bug with ape playing'''
        if get_file_extension(bean.path) == '.ape' and bean.start_sec != '0':
            self.volume(0)
            threading.Timer(1.8, lambda: self.volume(FC().volume)).start()
        else:
            self.volume(FC().volume)
        
        logging.debug("current state before thread" + str(self.get_state()) + str(self.play_thread_id))
        self.play_thread_id = thread.start_new_thread(self.playing_thread, ())
        self.pause_thread_id = False
Пример #51
0
def is_m3u(path):
    extension = get_file_extension(path)
    if extension and extension.lower() in [".m3u", ".m3u8"]:
        return True
    return False
Пример #52
0
    def parse(self):
        file = open(self.cue_path, "r")
        code = self.code_detecter(self.cue_path);
        logging.debug("File encoding is" + str(code))

        title = ""
        performer = ""
        index = "00:00:00"
        full_file = None
        
        self.cue_file.image = get_image_by_path(self.cue_path)

        self.files_count = 0

        for line in file:
            if not self.is_valid and not line.startswith(FILE):
                continue
            else: self.is_valid = True
            
            try:
                pass
                line = unicode(line, code)
            except:
                logging.error("File encoding is too strange" + str(code))
                pass

            line = str(line).strip()
            if not line:
                continue

            if line.startswith(TITLE):
                title = self.get_line_value(line)
                if self.files_count == 0:
                    self.cue_file.title = title


            if line.startswith(PERFORMER):
                performer = self.get_line_value(line)
                if self.files_count == 0:
                    self.cue_file.performer = performer

            if line.startswith(FILE):
                self.files_count += 1
                file = self.get_line_value(line)
                file = os.path.basename(file)
                
                if "/" in file:
                    file = file[file.rfind("/")+1:]
                if "\\" in file:
                    file = file[file.rfind("\\")+1:]
                 
                dir = os.path.dirname(self.cue_path)
                full_file = os.path.join(dir, file)
                logging.debug("CUE source" + full_file)
                exists = os.path.exists(full_file)
                """if there no source cue file"""

                if not exists:
                    """try to find other source"""
                    ext = file_utils.get_file_extension(full_file)
                    nor = full_file[:-len(ext)]
                    logging.info("Normalized path" + nor)
                    
                    find_source = False
                    for support_ext in FC().audio_formats:
                        try_name = nor + support_ext
                        if os.path.exists(try_name):
                            full_file = try_name
                            logging.debug("Found source for cue file name" + try_name)
                            find_source = True
                            break;
                    
                    if not find_source:    
                        self.is_valid = False
                        self.files_count -= 1
                        logging.warn("Can't find source for " + line + "  Check source file name")
                        continue
                
                if self.files_count == 0:
                    self.cue_file.file = full_file

            if line.startswith(INDEX):
                index = self.get_line_value(line)

            if line.startswith("INDEX 01"):
                cue_track = CueTrack(title, performer, index, full_file)
                self.cue_file.append_track(cue_track)
        
        logging.debug("CUE file parsed " + str(self.cue_file.file))
        return self.normalize()
Пример #53
0
    def play(self, bean):
        self.bean = bean

        if not bean:
            return None

        path = bean.path

        if not path:
            logging.error("Can't play empty path!!!")
            return None

        self.state_stop(show_in_tray=False)

        if hasattr(self, "pipeline"):
            self.pipeline.set_state(gst.STATE_NULL)

        self.player = self.gstreamer_player()
        """equlizer settings"""
        if FC().is_eq_enable:
            pre = self.controls.eq.get_preamp()
            bands = self.controls.eq.get_bands()
            self.set_all_bands(pre, bands)

        if path.startswith("http://"):
            self.radio_path = get_radio_source(path)
            logging.debug("Try To play path " + self.radio_path)

            if self.bean.type == FTYPE_RADIO:
                time.sleep(2)

            uri = self.radio_path

            self.notify_title(uri)
        else:
            uri = 'file://' + urllib.pathname2url(path)
            if os.name == 'nt':
                uri = 'file:' + urllib.pathname2url(path)

        logging.info("Gstreamer try to play " + uri)

        self.player.set_property("uri", uri)

        self.state_pause(show_in_tray=False)
        time.sleep(0.3)
        if self.remembered_seek_position:
            self.player.seek_simple(gst.Format(gst.FORMAT_TIME),
                                    gst.SEEK_FLAG_FLUSH,
                                    self.remembered_seek_position)
        else:
            self.seek_seconds(bean.start_sec)

        self.remembered_seek_position = 0

        self.state_play()
        '''trick to mask bug with ape playing'''
        if get_file_extension(bean.path) == '.ape' and bean.start_sec != '0':
            self.volume(0)
            threading.Timer(1.8, lambda: self.volume(FC().volume)).start()
        else:
            self.volume(FC().volume)

        logging.debug("current state before thread " + str(self.get_state()) +
                      " thread_id: " + str(self.play_thread_id))
        self.play_thread_id = thread.start_new_thread(self.playing_thread, ())
        self.pause_thread_id = False
Пример #54
0
    def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp):
        logging.debug('Playlist on_drag_data_received')
        model = self.get_model().get_model()
        drop_info = self.get_dest_row_at_pos(x, y)

        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)

        files = sorted([file for file in get_files_from_gtk_selection_data(selection)
                if os.path.isdir(file) or get_file_extension(file) in FC().all_support_formats],
                key=lambda x: x[self.text[0]])
        if files:
            '''dnd from the outside of the player'''
            if self.is_empty():
                if len(files) == 1 and os.path.isdir(files[0]):
                    tabname = os.path.basename(files[0])
                else:
                    tabname = os.path.split(os.path.dirname(files[0]))[1]
                self.controls.notetabs.rename_tab(self.scroll, tabname)
            for i, file in enumerate(files):
                if os.path.isdir(file):
                    sorted_dirs = []
                    sorted_files = []
                    for f in sorted(os.listdir(file), key=lambda x: x):
                        f = os.path.join(file, f)
                        if os.path.isdir(f):
                            sorted_dirs.append(f)
                        elif get_file_extension(f) in FC().all_support_formats:
                            sorted_files.append(f)

                    listdir = sorted_dirs + sorted_files
                    '''
                    listdir = sorted(filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x),
                                     [os.path.join(file, f) for f in os.listdir(file)]), key=lambda x: x)
                    '''
                    for k, path in enumerate(listdir):
                        files.insert(i + k + 1, path)

            rows = self.file_paths_to_rows(files)
            if not rows:
                return
            rows = self.playlist_filter(rows)
            for row in rows:
                if drop_info:
                    if (position == Gtk.TREE_VIEW_DROP_BEFORE
                        or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                        model.insert_before(None, iter, row)
                    else:
                        model.insert_after(None, iter, row)
                        iter = model.iter_next(iter)
                else:
                    model.append(None, row)

        else:
            '''dnd inside the player'''
            # ff - from_filter
            ff_tree = Gtk.drag_get_source_widget(context)
            ff_model, ff_paths = ff_tree.get_selection().get_selected_rows()
            treerows = [ff_model[ff_path] for ff_path in ff_paths]

            if self is ff_tree:
                '''internal dnd'''
                ff_row_refs = [Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths]
                for ff_row_ref in ff_row_refs:
                    ff_iter = self.get_iter_from_row_reference(ff_row_ref)
                    f_iter = ff_model.convert_iter_to_child_iter(ff_iter)
                    if drop_info:
                        if (position == Gtk.TREE_VIEW_DROP_BEFORE
                            or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                            model.move_before(f_iter, iter)
                        else:
                            model.move_after(f_iter, iter)
                            iter = model.iter_next(iter)
                    else:
                        model.move_before(f_iter, None)
                return

            else:
                '''dnd from other tree'''
                if self.is_empty():
                    path = treerows[0][self.path[0]]
                    if path:
                        if len(treerows) == 1 and os.path.isdir(path):
                            tabname = os.path.basename(path)
                        else:
                            tabname = os.path.split(os.path.dirname(path))[1]
                        self.controls.notetabs.rename_tab(self.scroll, tabname)
                    else:
                        pass
                for i, treerow in enumerate(treerows):

                    for k, ch_row in enumerate(treerow.iterchildren()):
                        treerows.insert(i + k + 1, ch_row)

                #treerows = self.playlist_filter(treerows)

                for i, treerow in enumerate(treerows):
                    if is_playlist(treerow[self.path[0]]):
                        rows = self.file_paths_to_rows([treerow[self.path[0]]])
                        if rows:
                            rows.reverse()
                            map(lambda row: treerows.insert(i + 1, row), rows)
                            continue
                    row = [col for col in treerow]
                    if drop_info:
                        if (position == Gtk.TREE_VIEW_DROP_BEFORE
                            or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                            model.insert_before(None, iter, row)
                        else:
                            model.insert_after(None, iter, row)
                            iter = model.iter_next(iter)
                    else:
                        model.append(None, row)


        thread.start_new_thread(self.safe_fill_treerows, ())

        context.finish(True, False, timestamp)
        self.stop_emission('drag-data-received')
        return True
Пример #55
0
    def download(self):
        bean = self.bean
        update = self.update
        if not bean or not bean.path:
            return None

        opener = FancyURLopener()
        remote = opener.open(bean.path)
        remote_size = 0

        if "Content-Length" in remote.headers:
            remote_size = int(remote.headers["Content-Length"])
            bean.size = size2text(remote_size)

        block_size = 4096
        block_count = 0

        ext = get_file_extension(bean.path)

        path = FC().online_save_to_folder
        if not os.path.isdir(path):
            os.makedirs(path)

        if bean.save_to:
            to_file = os.path.join(bean.save_to, bean.text + ".mp3")
        else:
            to_file = get_bean_download_path(bean, FC().online_save_to_folder)

        if not os.path.exists(os.path.dirname(to_file)):
            os.makedirs(os.path.dirname(to_file))

        to_file_tmp = to_file + ".tmp"

        if os.path.exists(to_file_tmp):
            bean.status = DOWNLOAD_STATUS_INACTIVE
            bean.to_file = to_file
            update(bean)
            return None

        if os.path.exists(to_file):
            bean.status = DOWNLOAD_STATUS_COMPLETED
            bean.to_file = to_file
            update(bean)
            return None

        bean.save_to = to_file
        with open(to_file_tmp, "wb") as tmp_file:
            data = True
            """begin download"""
            self.bean.status = DOWNLOAD_STATUS_DOWNLOADING
            self.bean.path = to_file
            self.update(self.bean)

            while data:
                data = remote.read(block_size)
                if data:
                    block_count += 1
                    tmp_file.write(data)
                    #time.sleep(0.1)
                    persent = block_count * block_size * 100.0 / remote_size
                    if block_count % 50 == 0:
                        bean.persent = persent
                        update(bean)
        time.sleep(0.5)
        """update file info on finish"""
        logging.debug("rename %s - %s" % (to_file_tmp, to_file))
        os.rename(to_file_tmp, to_file)
        bean.status = DOWNLOAD_STATUS_COMPLETED
        bean.to_file = to_file
        bean.persent = 100
        update(bean)