Esempio n. 1
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)
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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)
Esempio n. 5
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
Esempio n. 6
0
    def __parse_stations(self, data, genre):
        """
        Parses the list of stations.
        """

        stations = []
        soup = BeautifulSoup(data)
        resulttable = soup.find("div", {"id": "resulttable"})
        if (resulttable):
            for entry in resulttable.findAll("div", {"class": "dirlist"}):
                #print entry
                station = File(self)
                a_tag = entry.find("a", {"class": "playbutton playimage"})
                playing_tag = entry.find("div", {"class": "playingtext"})
                bitrate_tag = entry.find("div", {"class": "dirbitrate"})
                type_tag = entry.find("div", {"class": "dirtype"})

                if (not a_tag or not playing_tag or not bitrate_tag
                        or not type_tag):
                    continue

                station.resource = a_tag["href"]
                station.name = a_tag["title"]
                now_playing = playing_tag["title"]
                bitrate = bitrate_tag.contents[0].strip()

                typename = type_tag.contents[0].strip()
                if (typename == "MP3"):
                    station.mimetype = "audio/mpeg"
                elif (typename == "AAC+"):
                    station.mimetype = "audio/mp4"
                else:
                    station.mimetype = "audio/x-unknown"

                station.path = File.pack_path("/" + urlquote.quote(genre, ""),
                                              station.name, bitrate,
                                              station.mimetype,
                                              station.resource, genre)
                station.info = "Bitrate: %s kb\n" \
                               "Now playing: %s" % (bitrate, now_playing)
                station.icon = theme.shoutcast_station.get_path()
                stations.append(station)
            #end for
        #end if

        if (not stations):
            self.__current_folder.message = "station list not available"
            logging.error("SHOUTcast station listing download failed\n%s",
                          logging.stacktrace())

        stations.sort()
        return stations
Esempio n. 7
0
    def __make_folder(self, month, year):

        f = File(self)
        f.is_local = True
        f.path = File.pack_path("/months", str(month), str(year))
        f.mimetype = "application/x-image-folder"
        f.resource = ""
        f.name = "%s %d" % (_MONTHS[month - 1], year)
        f.acoustic_name = "Folder: " + f.name
        f.comparable = 0 - ((year * 100) + month)
        #f.info = "%d items" % len(self.__folders.get(folder_name, []))
        f.folder_flags = f.ITEMS_ENQUEUEABLE | \
                            f.ITEMS_COMPACT

        return f
Esempio n. 8
0
 def __make_station(self, name, url):
 
     f = File(self)
     f.name = name
     f.info = url
     f.path = File.pack_path("/", name, url)
     f.resource = url
     if (url.endswith(".ram") or url.endswith(".rm")):
         f.mimetype = "application/vnd.rn-realmedia"
     else:
         f.mimetype = "audio/x-unknown"
     f.thumbnailer = "iradio.IRadioThumbnailer"
     f.thumbnailer_param = url
     
     return f
Esempio n. 9
0
    def __make_album(self, ffolder, album):

        f = File(self)
        f.is_local = True
        f.path = File.pack_path("/albums", ffolder, album)
        f.name = album
        f.acoustic_name = f.name
        #f.info = artist
        f.mimetype = "application/x-music-folder"
        f.folder_flags = f.ITEMS_ENQUEUEABLE
        f.comparable = f.name

        if (album == "All Tracks"):
            f.icon = theme.mb_folder_audio.get_path()

        return f
Esempio n. 10
0
    def handle_COM_EV_APP_STARTED(self):

        logging.profile(values.START_TIME, "[app] startup complete")

        # load state
        try:
            path, play_files, play_folder, current_file = state.load(
                _STATEFILE)

            path_stack = []
            for p in path:
                f = self.call_service(msgs.CORE_SVC_GET_FILE, p)
                if (f):
                    path_stack.append(f)
                    self.emit_message(msgs.CORE_EV_FOLDER_VISITED, f)
                #end if
            #end for
            self.__browser.set_path_stack(path_stack)

            #self.__play_files = [ self.call_service(msgs.CORE_SVC_GET_FILE, p)
            #                      for p in play_files
            #                      if self.call_service(msgs.CORE_SVC_GET_FILE, p) ]
            self.__play_folder = self.call_service(msgs.CORE_SVC_GET_FILE,
                                                   play_folder)
            self.__current_file = self.call_service(msgs.CORE_SVC_GET_FILE,
                                                    current_file)

        except:
            logging.warning("could not restore navigator state:\n%s",
                            logging.stacktrace())

        self.__arr.set_visible(True)
        self.render()

        if (values.uri and
            (values.uri.startswith("http://") or os.path.exists(values.uri))):
            ext = os.path.splitext(values.uri)[1]
            mimetype = mimetypes.ext_to_mimetype(ext)
            f = self.call_service(
                msgs.CORE_SVC_GET_FILE,
                "adhoc://" + File.pack_path("/", values.uri, mimetype))
            self.__load_file(f, True)
Esempio n. 11
0
    def __make_track(self, artist, album, title, trackno, resource, mimetype):

        #f = self.call_service(msgs.CORE_SVC_GET_FILE, resource)
        #if (not f): return None

        path = File.pack_path("/tracks", artist, album, title, trackno,
                              resource, mimetype)

        f = File(self)
        f.path = path
        f.is_local = True
        f.resource = resource
        f.name = title
        f.info = artist or "unknown"
        f.mimetype = mimetype
        f.acoustic_name = f.name + ", by " + f.info

        if (album == "All Tracks"):
            f.comparable = f.name.upper()
        else:
            f.comparable = trackno

        return f
Esempio n. 12
0
 def __make_album(self, ffolder, album):
 
     path = File.pack_path("/albums", ffolder, album)
     f = self.call_service(msgs.CORE_SVC_GET_FILE,
                           "audio://albums" + path)
     return f
Esempio n. 13
0
    def __make_video_from_node(self, node):
        """
        Parses the given entry node and returns a file object.
        """

        # get ID
        s = node.get_pcdata("{%s}id" % _XMLNS_ATOM)
        video_id = s[s.rfind("/") + 1:]

        # get title and content
        title = node.get_pcdata("{%s}title" % _XMLNS_ATOM)
        content = node.get_pcdata("{%s}content" % _XMLNS_ATOM)

        # get authors
        author_node = node.get_child("{%s}author" % _XMLNS_ATOM)
        authors = [
            c.get_pcdata() for c in author_node.get_children()
            if c.get_name() == "{%s}name" % _XMLNS_ATOM
        ]
        authors = ", ".join(authors)

        # check for region restriction
        app_control = node.get_child("{%s}control" % _XMLNS_APP)
        if (app_control):
            yt_state = app_control.get_child("{%s}state" % _XMLNS_YT)
            reason_code = ""
            if (yt_state):
                reason_code = yt_state.get_attr("{%s}reasonCode" % _XMLNS_ATOM)
            if (reason_code == "requesterRegion"):
                region_blocked = True
                video_id = _REGION_BLOCKED
        #end if

        group_node = node.get_child("{%s}group" % _XMLNS_MRSS)

        # get thumbnail
        thumbnail_nodes = [
            c for c in group_node.get_children()
            if c.get_name() == "{%s}thumbnail" % _XMLNS_MRSS
        ]
        if (thumbnail_nodes):
            thumbnail_url = thumbnail_nodes[0].get_attr("{%s}url" %
                                                        _XMLNS_ATOM)
        else:
            thumbnail_url = ""

        # get category
        category_node = group_node.get_child("{%s}category" % _XMLNS_MRSS)
        if (category_node):
            category = category_node.get_attr("{%s}label" % _XMLNS_ATOM)
        else:
            category = ""

        # get player URL
        player_node = group_node.get_child("{%s}player" % _XMLNS_MRSS)
        if (player_node):
            player_url = player_node.get_attr("{%s}url" % _XMLNS_ATOM)
        else:
            player_url = _VIDEO_WATCH + os.path.basename(entry.video_id)

        # get duration
        duration_node = group_node.get_child("{%s}duration" % _XMLNS_YT)
        if (duration_node):
            duration = int(duration_node.get_attr("{%s}seconds" % _XMLNS_ATOM))
        else:
            duration = 0

        # get rating
        rating_node = node.get_child("{%s}rating" % _XMLNS_GOOGLE)
        if (rating_node):
            rating = self.__parse_rating(rating_node)
        else:
            rating = "unrated"

        # get view count
        statistics_node = node.get_child("{%s}statistics" % _XMLNS_YT)
        if (statistics_node):
            view_count = int(
                statistics_node.get_attr("{%s}viewCount" % _XMLNS_ATOM))
        else:
            view_count = 0

        secs = duration % 60
        duration /= 60
        mins = duration

        info = "by %s\n" \
               "%d:%02d\t%s\t%s views" \
               % (authors,
                  mins, secs,
                  rating,
                  view_count)

        path = File.pack_path("/videos", title, info, video_id, thumbnail_url)

        return self.__make_video(path)