Ejemplo n.º 1
0
 def get(self, template_params=None):
     if template_params is None:
         template_params = {}
     for param in PLAYLIST_PARAMS:
         template_params[param] = self.request.get(param)
     webutils.render_to_response(self, "create_playlist.html",
                                 template_params)
Ejemplo n.º 2
0
    def handle(self, playlist_id):
      try:
        self.playlist_metadata = model.PlaylistMetadata.gql(
          "WHERE playlist_id = :1", playlist_id)[0]
      except IndexError:
        self.error(404)
        self.response.out.write("Party Playlist Picker does not know about playlist %s." %
                                escape(playlist_id))
        return

      if users.get_current_user() != self.playlist_metadata.owner:
        if self.request.get("uuid", -1) != self.playlist_metadata.uuid:
          self.error(401)
          self.response.out.write("You are not authorized to view this page.")
          return

      owner_id = self.playlist_metadata.owner.user_id()
      owner_credentials = StorageByKeyName(CredentialsModel, owner_id,
                                           'credentials').get()
      self.owner_oauth_token = owner_credentials.access_token

      try:
        me = memcacheutils.cache_call(
          key=self.oauth2_decorator.credentials.access_token,
          namespace="oauth2_token_to_user",
          time=memcacheutils.USER_EXPIRATION_SECS,
          f=lambda: googleplusutils.service.people().get(userId="me").execute(
            webutils.create_authorized_http_with_timeout(
              self.oauth2_decorator.credentials)))
      except HttpError, e:
        if e.resp['status'] == 404:
          webutils.render_to_response(self, "no_profile.html")
          return
        raise
 def get(self, playlist_id):
     redirection_url = re.sub(r"/welcome/", r"/edit/", self.request.url, 1)
     quoted_redirection_url = simplejson.dumps(redirection_url)
     template_params = {"quoted_redirection_url": quoted_redirection_url}
     template_params["is_logged_in"] = users.get_current_user() != None
     webutils.render_to_response(self, "welcome_playlist.html",
                                 template_params)
Ejemplo n.º 4
0
 def handle_exception(self, exception, debug_mode):
   """Handle certain global exceptions such as OAuth2 problems."""
   if (isinstance(exception, RequestError) and
       exception.args[0]["status"] == 401):
     body = exception.args[0]["body"]
     if "Stateless token expired" in body:
       self._force_refresh()
       self.redirect(self.request.url)
       return
     if "NoLinkedYouTubeAccount" in body:
       webutils.render_to_response(self, "unlinked_account.html")
       return
   webapp.RequestHandler.handle_exception(self, exception, debug_mode)
 def get(self):
   yt_service = youtubeutils.create_youtube_service(
     self.oauth2_decorator.credentials.access_token)
   (feed, entries) = youtubeutils.fetch_feed_and_entries(
     yt_service.GetYouTubePlaylistFeed, username="******")
   playlists_from_datastore = model.PlaylistMetadata.gql(
     "WHERE owner = :1", users.get_current_user())
   playlist_ids = set(i.playlist_id for i in playlists_from_datastore)
   playlists = []
   for entry in entries:
     id_from_uri = youtubeutils.get_id_from_uri(entry)
     if id_from_uri in playlist_ids:
       playlists.append(dict(id=id_from_uri, title=entry.title.text,
                             num_videos=entry.feed_link[0].count_hint))
   webutils.render_to_response(self, "playlists.html",
                               dict(playlists=playlists))
 def get(self):
     yt_service = youtubeutils.create_youtube_service(
         self.oauth2_decorator.credentials.access_token)
     (feed, entries) = youtubeutils.fetch_feed_and_entries(
         yt_service.GetYouTubePlaylistFeed, username="******")
     playlists_from_datastore = model.PlaylistMetadata.gql(
         "WHERE owner = :1", users.get_current_user())
     playlist_ids = set(i.playlist_id for i in playlists_from_datastore)
     playlists = []
     for entry in entries:
         id_from_uri = youtubeutils.get_id_from_uri(entry)
         if id_from_uri in playlist_ids:
             playlists.append(
                 dict(id=id_from_uri,
                      title=entry.title.text,
                      num_videos=entry.feed_link[0].count_hint))
     webutils.render_to_response(self, "playlists.html",
                                 dict(playlists=playlists))
Ejemplo n.º 7
0
 def get(self):
   """Return an HTML fragment of YT search results."""
   q = self.request.get("q")
   yt_service = youtubeutils.create_youtube_service()
   query = gdata.youtube.service.YouTubeVideoQuery()
   query.vq = q
   results_feed = yt_service.YouTubeQuery(query)
   video_list = [
     dict(id=youtubeutils.get_id_from_uri(i),
          title=i.media.title.text,
          description=i.media.description.text,
          duration=youtubeutils.parse_duration_seconds(
            i.media.duration.seconds),
          thumbnail=i.media.thumbnail[1].url,
          embeddable=youtubeutils.is_embeddable(i.media.content))
     for i in results_feed.entry
   ]
   template_params = {"button_name": "Add", "class_name": "search-item",
                      "video_list": video_list}
   webutils.render_to_response(self, "video_list.html", template_params)
    def get(self, playlist_id):
        friend_list = friendlistutils.render_friend_list(playlist_id, self.people)
        template_params = {"button_name": "Remove", "class_name": "playlist-item", "friend_list": friend_list}
        yt_service_for_owner = youtubeutils.create_youtube_service(self.owner_oauth_token)
        (playlist, entries) = youtubeutils.fetch_feed_and_entries(
            yt_service_for_owner.GetYouTubePlaylistVideoFeed, playlist_id=playlist_id
        )

        edit_playlist_url = "%s/playlists/edit/%s?%s" % (
            self.request.host_url,
            self.playlist_metadata.playlist_id,
            urllib.urlencode({"uuid": self.playlist_metadata.uuid}),
        )
        welcome_page_url = re.sub(r"/edit/", r"/welcome/", edit_playlist_url, 1)

        template_params["title"] = playlist.title.text
        template_params["description"] = playlist.subtitle.text
        template_params["quoted_playlist_id"] = simplejson.dumps(playlist_id)
        template_params["playlist_id"] = playlist_id
        template_params["video_list"] = youtubeutils.prepare_playlist(entries)
        template_params["quoted_edit_url"] = simplejson.dumps(edit_playlist_url)
        template_params["quoted_uuid"] = simplejson.dumps(self.playlist_metadata.uuid)
        template_params["welcome_page_url"] = welcome_page_url
        webutils.render_to_response(self, "edit_playlist.html", template_params)
  def get(self, playlist_id):
    friend_list = friendlistutils.render_friend_list(playlist_id, self.people)
    template_params = {"button_name": "Remove", "class_name": "playlist-item",
                       "friend_list": friend_list}
    yt_service_for_owner = youtubeutils.create_youtube_service(
      self.owner_oauth_token)
    (playlist, entries) = youtubeutils.fetch_feed_and_entries(
      yt_service_for_owner.GetYouTubePlaylistVideoFeed, playlist_id=playlist_id)

    edit_playlist_url = "%s/playlists/edit/%s?%s" % (
      self.request.host_url, self.playlist_metadata.playlist_id,
      urllib.urlencode({"uuid": self.playlist_metadata.uuid}))
    welcome_page_url = re.sub(r"/edit/", r"/welcome/", edit_playlist_url, 1)
    
    template_params["title"] = playlist.title.text
    template_params["description"] = playlist.subtitle.text
    template_params["quoted_playlist_id"] = simplejson.dumps(playlist_id)
    template_params["playlist_id"] = playlist_id
    template_params["video_list"] = youtubeutils.prepare_playlist(entries)
    template_params["quoted_edit_url"] = simplejson.dumps(edit_playlist_url)
    template_params["quoted_uuid"] = simplejson.dumps(
      self.playlist_metadata.uuid)
    template_params["welcome_page_url"] = welcome_page_url
    webutils.render_to_response(self, "edit_playlist.html", template_params)
Ejemplo n.º 10
0
 def get(self):
     if users.get_current_user():
         self.redirect("/playlists")
     else:
         webutils.render_to_response(self, "welcome.html", {})
 def get(self, playlist_id):
   redirection_url = re.sub(r"/welcome/", r"/edit/", self.request.url, 1)
   quoted_redirection_url = simplejson.dumps(redirection_url)
   template_params = {"quoted_redirection_url": quoted_redirection_url}
   template_params["is_logged_in"] = users.get_current_user() != None
   webutils.render_to_response(self, "welcome_playlist.html", template_params)
 def get(self, template_params=None):
   if template_params is None:
     template_params = {}
   for param in PLAYLIST_PARAMS:
     template_params[param] = self.request.get(param)
   webutils.render_to_response(self, "create_playlist.html", template_params)
Ejemplo n.º 13
0
 def get(self):
   if users.get_current_user():
     self.redirect("/playlists")
   else:
     webutils.render_to_response(self, "welcome.html", {})