import gdata.youtube.service
import sys





def getplaylist (playlist_feed, playlist_name):
	"""
	playlist_feed:  YouTubePlaylistEntry
	playlist: name to search
	"""
	entries = [entry for entry in playlist_feed.entry if entry.title.text == playlist_name]
	return entries


playlist_name = sys.argv[1]

# Create a client class which will make HTTP requests with Google Docs server.
with open('password.hide') as f:
  username, password = f.readline().strip().split(':')
  developer_key = f.readline().strip()

yt_service = gdata.youtube.service.YouTubeService()
yt_service.email = username
yt_service.password = password
yt_service.source = 'reddTube'
yt_service.developer_key = developer_key
yt_service.client_id = 'reddTube'
print yt_service.ProgrammaticLogin()

# read user playlists
playlist_feed = yt_service.GetYouTubePlaylistFeed(username='default')

print getplaylist (playlist_feed, playlist_name)



@@ -34,17 +34,144 @@
 rt sys%0A%0A
-%0A
+def get_first(iterable, default=None):%0A    if iterable:%0A        for item in iterable:%0A            return item%0A    return default
 %0A%0A%0Adef g
@@ -178,37 +178,34 @@
 etplaylist (
-playlist_feed
+yt_service
 , playlist_n
@@ -220,210 +220,893 @@
 %22%22%0A%09
-playlist_feed:  YouTubePlaylistEntry%0A%09playlist: name to search%0A%09%22%22%22%0A%09entries = %5Bentry for entry in playlist_feed.entry if entry.title.text == playlist_name%5D%0A%09return entries%0A%0A%0Aplaylist_name = sys.argv%5B1%5D
+yt_service:  YouTube service%0A%09playlist: name to search%0A%09Retruns the playlist object or None%0A%09%22%22%22%0A%09playlist_feed = yt_service.GetYouTubePlaylistFeed(username='default')%0A%09entries = %5Bentry for entry in playlist_feed.entry if entry.title.text == playlist_name%5D%0A%09return get_first(entries)%0A%0Adef create_playlist (yt_service, playlist_name, playlist_description, playlist_public):%0A%09%22%22%22%0A%09yt_service:  YouTube service%0A%09playlist_name: name for the playlist%0A%09playlist_description: description for the playlist%0A%09playlist_public: true for create a public playlist%0A%09Returns the playlist%0A%09%22%22%22%0A%09new_playlistentry = yt_service.AddPlaylist(playlist_name, playlist_description, playlist_public)%0A%0A%09if isinstance(new_playlistentry, gdata.youtube.YouTubePlaylistEntry):%0A%09%09return new_playlistentry%0A%09else:%0A%09%09return None%0A%0A%0A%0Aplaylist_name = sys.argv%5B1%5D%0Aplaylist_description = playlist_name%0Aplaylist_public = True
 %0A%0A# 
@@ -1587,24 +1587,26 @@
 aylists%0A
+%0A%0A
 playlist
 _feed = 
@@ -1601,90 +1601,108 @@
 list
-_feed = yt_service.GetYouTubePlaylistFeed(username='default')%0A%0Aprint getplaylist (
+= getplaylist (yt_service, playlist_name)%0Aif not playlist:%0A%09playlist = create_playlist (yt_service, 
 play
@@ -1706,20 +1706,20 @@
 laylist_
-feed
+name
 , playli
@@ -1721,16 +1721,39 @@
 laylist_
-name)%0A
+description, playlist_public)
 %0A%0A

Change signature to getplaylist