示例#1
0
 def get_file(self, path):
 
     f = File(self)
     f.path = path
     f.mimetype = "video/x-unknown"
     
     return f
示例#2
0
    def get_root(self):

        f = File(self)
        f.name = self.get_name()
        f.path = "/"
        f.mimetype = f.DIRECTORY
        return f
示例#3
0
    def get_file(self, path):

        parts = [ p for p in path.split("/") if p ]
        len_parts = len(parts)
        
        f = None
        if (len_parts == 0):
            # root folder
            f = File(self)
            f.path = "/"
            f.mimetype = f.DIRECTORY
            f.resource = ""
            f.name = self.get_name()
            f.info = "Browse the SHOUTcast directory"
            f.icon = self.get_icon().get_path()
            f.folder_flags = f.ITEMS_ENQUEUEABLE | f.ITEMS_COMPACT
    
        elif (len_parts == 1):
            genre = urlquote.unquote(parts[0])
            f = self.__make_genre(genre)
    
        elif (len_parts == 2):
            f = self.__make_station(parts[1])

        return f
示例#4
0
    def __ls_menu(self, cb, *args):

        for name, category in [("Search", "video"),
                               ("Recently Featured", "recently_featured"),
                               ("Today's Top Rated", "top_rated"),
                               ("Most Viewed", "most_viewed"),
                               ("Most Popular", "most_popular"),
                               ("Music", "music"), ("Movies", "movie"),
                               ("News", "news"),
                               ("For Mobile Phones", "watch_on_mobile")]:
            item = File(self)
            query = ""
            idx = 0
            item.path = File.pack_path("/search", name, category, query, idx)
            item.resource = item.path
            item.name = name
            item.mimetype = File.DIRECTORY
            item.folder_flags = File.ITEMS_UNSORTED
            if (name in _ICONS):
                item.icon = _ICONS[name].get_path()

            cb(item, *args)
        #end for

        cb(None, *args)
示例#5
0
 def cb(pl, name, location):
     f = self.call_service(msgs.CORE_SVC_GET_FILE, location)
     if (f):
         pl.append(f)
     else:
         # insert a placeholder for files that are currently
         # not available
         f = File(self)
         f.name = name
         f.info = location
         pl.append(f)
示例#6
0
    def __make_folder(self, folder_name):

        f = File(self)
        f.is_local = True
        f.path = "/" + urlquote.quote(folder_name, "")
        f.mimetype = f.DIRECTORY
        f.resource = ""
        f.name = folder_name
        f.acoustic_name = "Folder: " + f.name
        f.icon = theme.mb_folder_audioclips.get_path()
        #f.info = "%d items" % len(self.__folders.get(folder_name, []))
        f.folder_flags = f.ITEMS_ENQUEUEABLE

        return f
示例#7
0
    def __parse_group(self, path, node):
    
        f = File(self)
        try:
            f.name = node.get_attr("title")
        except:
            return None
        f.path = path
        f.mimetype = f.DIRECTORY

        if (f.name in _BLACKLISTED):
            return None

        return f
示例#8
0
    def new_file(self, path):

        # present search dialog
        dlg = Dialog()
        dlg.add_entry("Name:", "")
        dlg.add_entry("Location:", "http://")
        values = dlg.wait_for_values()

        if (values):
            name, location = values
            stations = inetstations.get_stations()
            stations.append((location, name))
            inetstations.save_stations(stations)

            item = File(self)
            item.path = self.__encode_path(name, location)
            item.resource = location
            item.name = name
            item.info = location
            if (location.endswith(".ram") or location.endswith(".rm")):
                item.mimetype = "application/vnd.rn-realmedia"
            else:
                item.mimetype = "audio/x-unknown"

            self.emit_message(msgs.CORE_EV_FOLDER_INVALIDATED, self.get_root())
            return item

        else:
            return None
示例#9
0
        def on_receive_node(node):
            if (node.get_name() == "{%s}totalResults" % _XMLNS_OPENSEARCH):
                # read total number of hits
                total_results = int(node.get_pcdata())

                # set a sane limit (YouTube cannot handle more anyway)
                total_results = min(total_results, 20 * _PAGE_SIZE)

                page = 1
                for n in range(1, total_results, _PAGE_SIZE):
                    f = File(self)
                    f.name = "Page %d" % page
                    f.path = File.pack_path("/search", f.name, category, query,
                                            n)
                    f.mimetype = f.DIRECTORY
                    f.info = "Results %d - %d" % (
                        n, min(total_results, n + _PAGE_SIZE - 1))
                    f.folder_flags = File.ITEMS_UNSORTED
                    cb(f, *args)
                    page += 1
                #end for

                cb(None, *args)

            return True
示例#10
0
    def get_file(self, path):

        parts = [p for p in path.split("/") if p]
        len_parts = len(parts)

        f = None
        if (len_parts == 0):
            f = File(self)
            f.name = self.get_name()
            f.info = "Change the configuration"
            f.path = "/"
            f.icon = self.get_icon().get_path()
            f.mimetype = f.DEVICE_ROOT
            f.folder_flags = f.ITEMS_COMPACT

        elif (len_parts == 1):
            cfg_name = parts[-1]
            cs = [c for c in self.__configurators if ` c ` == cfg_name]
            if (cs):
                c = cs[0]
                f = self.__make_configurator(c)
            #end if
        #end if

        return f
示例#11
0
    def __parse_group(self, parent_path, node_nr, node):
    
        f = File(self)
        try:
            f.name = node.get_attr("title")
        except:
            return None
        f.path = File.pack_path(parent_path, `node_nr`, f.name, "")
        f.mimetype = f.DIRECTORY

        if (f.name in _BLACKLISTED):
            return None

        return f
示例#12
0
 def __make_artist(self, artist):
 
     f = File(self)
     f.path = File.pack_path("/artists", artist)
     f.name = artist
     f.acoustic_name = f.name
     f.mimetype = f.DIRECTORY
     f.icon = theme.mb_folder_artist.get_path()
     f.folder_flags = f.ITEMS_ENQUEUEABLE | \
                         f.ITEMS_COMPACT
     return f
示例#13
0
    def __make_genre(self, genre):

        f = File(self)
        f.path = File.pack_path("/genres", genre)
        f.name = genre
        f.acoustic_name = genre
        f.mimetype = f.DIRECTORY
        f.icon = theme.mb_folder_genre.get_path()
        f.folder_flags = f.ITEMS_ENQUEUEABLE | \
                         f.ITEMS_COMPACT
        return f
示例#14
0
    def __on_download(self, folder, f):

        if (f.mimetype == f.DIRECTORY):
            dlg = FileDialog(FileDialog.TYPE_FOLDER, "Save To")
            dlg.run()

            destination = dlg.get_filename()
    
            if (destination):
                self.call_service(msgs.DOWNLOADER_SVC_GET_RECURSIVE,
                                  f, destination)
            
        else:
            dlg = FileDialog(FileDialog.TYPE_SAVE, "Save File")
            name = File.make_safe_name(f.name)
            if (os.path.splitext(f.name)[1]):
                ext = ""
            else:
                ext = os.path.splitext(f.resource)[1]
            
            dlg.set_filename(name + ext)
            dlg.run()
        
            destination = dlg.get_filename()
    
            if (destination):
                self.call_service(msgs.DOWNLOADER_SVC_GET, f.resource,
                                  destination)
示例#15
0
    def commit(self, commitMsg, userId, listOfFiles):
        """stre all the give files"""
        latestCommitId = None
        date = datetime.datetime.utcnow().replace(microsecond=0)
        #parent = None
        files = []
        for itm in listOfFiles:
            filePath = os.path.join(self.path, itm)
            if not os.path.exists(filePath):
                raise InvalidFile

            fd = open(filePath, "r")
            fileObj = File(fd.read())
            self.storage.store_object(fileObj)
            fd.close()
            latestCommitId = fileObj.id
            files.append([itm, fileObj.id])

        parent = self.storage.get_tip()
        if parent != None:
            parent = parent.id
        comObj = Commit(userId, commitMsg, date, parent, files)
        self.storage.store_object(comObj)
        self.storage.update_tip(comObj)

        return latestCommitId
示例#16
0
    def get_root(self):

        f = File(self)
        f.path = "/"
        f.mimetype = f.DIRECTORY
        f.resource = ""
        f.name = self.get_name()
        f.info = "Editable list of radio stations"
        f.icon = self.get_icon()
        f.folder_flags = f.ITEMS_ENQUEUEABLE | \
                         f.ITEMS_ADDABLE | \
                         f.ITEMS_DELETABLE

        return f
示例#17
0
    def __make_folder(self, folder_name):

        f = File(self)
        f.is_local = True
        f.path = "/" + urlquote.quote(folder_name, "")
        f.mimetype = "application/x-image-folder"
        f.resource = ""
        f.name = folder_name
        f.acoustic_name = "Folder: " + f.name
        #f.info = "%d items" % len(self.__folders.get(folder_name, []))
        f.folder_flags = f.ITEMS_ENQUEUEABLE | \
                            f.ITEMS_COMPACT

        return f
示例#18
0
 def __parse_link(self, parent_path, node_nr, node):
 
     try:
         name = node.get_attr("title")
         url = node.get_attr("url")
         category = node.get_attr("category")
     except:
         return None
 
     if (name in _BLACKLISTED):
         return None
 
     if (not url.strip()):
         return None
     elif (url.endswith(".xml")):
         return None
   
     f = File(self)
     f.name = name
     f.resource = url
     f.path = File.pack_path(parent_path, `node_nr`, name, url)
     f.mimetype = "video/x-unknown"
     f.thumbnail = theme.worldtv_device.get_path()
     
     return f
示例#19
0
    def __ls_search(self, path, cb, *args):

        prefix, name, category, query, idx = File.unpack_path(path)
        #print path
        #print prefix, name, category, query, idx
        if (category == "video"):
            self.__video_search(cb, args, query, idx)
        else:
            self.__category_search(category, cb, args, idx)
示例#20
0
    def __make_configurator(self, c):

        f = File(self)
        f.name = c.TITLE
        f.info = c.DESCRIPTION
        f.resource = ` c `
        f.path = "/" + f.resource
        f.mimetype = f.CONFIGURATOR
        f.icon = c.ICON.get_path()

        return f
示例#21
0
    def __load_uri(self, uri, mimetype):

        if (not mimetype):
            ext = os.path.splitext(uri)[1]
            mimetype = mimetypes.ext_to_mimetype(ext)

        f = self.call_service(msgs.CORE_SVC_GET_FILE,
                              "adhoc://" + File.pack_path("/", uri, mimetype))
        print "Loading URI:", f
        if (f):
            self.__load_file(f, True)
示例#22
0
 def get_file(self, path):
 
     f = None
     if (path == "/"):
         f = File(self)
         f.name = "Internet Radio"
         f.info = "Listen to Internet Radio"
         f.path = "/"
         f.mimetype = File.DEVICE_ROOT
         f.icon = self.get_icon().get_path()
         f.folder_flags = File.ITEMS_ADDABLE | File.ITEMS_SORTABLE
         
     else:
         prefix, name, url = File.unpack_path(path)
         f = self.__make_station(name, url)
         
     return f
示例#23
0
    def get_root(self):

        f = File(self)
        f.name = self.get_name()
        f.path = "/"
        f.mimetype = f.DEVICE_ROOT
        f.folder_flags = f.ITEMS_ADDABLE  #| f.ITEMS_COMPACT
        f.icon = self.get_icon().get_path()

        return f
示例#24
0
    def __make_genre(self, genre):

        f = File(self)    
        f.name = genre
        f.path = "/" + urlquote.quote(genre, "")
        f.mimetype = f.DIRECTORY
        f.icon = theme.shoutcast_folder.get_path()
        f.folder_flags = f.ITEMS_ENQUEUEABLE

        return f
示例#25
0
 def get_root(self):
 
     f = File(self)
     f.path = "/"
     f.name = "World TV"
     f.mimetype = f.DIRECTORY
     f.resource = ""
     f.info = "Watch TV streams from all over the world"
     
     return f
示例#26
0
 def get_root(self):
 
     f = File(self)
     f.path = "/"
     f.name = self.get_name()
     f.mimetype = f.DIRECTORY
     f.resource = ""
     f.info = "Listen to internet radio stations"
     
     return f
示例#27
0
    def __make_genre(self, genre, href):

        f = File(self)
        f.name = genre
        f.path = href
        f.mimetype = f.DIRECTORY
        f.icon = theme.icecast_folder.get_path()
        f.folder_flags = f.ITEMS_ENQUEUEABLE

        return f
示例#28
0
    def __ls_playlists(self, begin_at, end_at, cb, *args):

        self.__lists.sort(lambda a, b: cmp(a[0], b[0]))
        playlists = [pl for n, pl in self.__lists]
        if (end_at == 0):
            playlists = playlists[begin_at:]
        else:
            playlists = playlists[begin_at:end_at]

        for pl in playlists:
            f = File(self)
            f.name = pl.get_name()
            #f.info = "%d items" % pl.get_size()
            f.path = "/" + urlquote.quote(f.name)
            f.mimetype = f.DIRECTORY
            f.icon = theme.mb_folder_playlist.get_path()
            f.folder_flags |= f.ITEMS_UNSORTED

            if (pl.get_name() != _PLAYLIST_RECENT_50):
                f.folder_flags |= f.ITEMS_SORTABLE

            cb(f, *args)
        #end for

        cb(None, *args)
示例#29
0
    def get_file(self, path):

        if (self.__needs_playlist_reload):
            self.__load_playlists()
            self.__needs_playlist_reload = False

        if (path == "/"):
            return self.get_root()

        name = urlquote.unquote(path[1:])
        pl = self.__lookup_playlist(name)

        if (pl):
            f = File(self)
            f.name = pl.get_name()
            #f.info = "%d items" % pl.get_size()
            f.path = path
            f.mimetype = f.DIRECTORY
            f.icon = theme.mb_folder_playlist.get_path()

            if (pl.get_name() != _PLAYLIST_RECENT_50):
                f.folder_flags |= f.ITEMS_SORTABLE
            return f
        else:
            return None
示例#30
0
    def get_file(self, path):

        parts = [p for p in path.split("/") if p]
        len_parts = len(parts)

        f = None
        if (len_parts == 0):
            f = File(self)
            f.is_local = True
            f.path = "/"
            f.mimetype = f.DEVICE_ROOT
            f.resource = ""
            f.name = self.get_name()
            f.info = "Browse your video library"
            f.icon = self.get_icon().get_path()
            f.folder_flags = f.ITEMS_ENQUEUEABLE  #| f.ITEMS_COMPACT

        elif (len_parts == 1):
            folder_name = urlquote.unquote(parts[0])
            f = self.__make_folder(folder_name)

        return f