I want to create an application that allows user to upload video to Youtube. Here is the code I tried (adapted from http://code.google.com/p/gdata-python-client/source/browse/tests/gdata_tests/youtube/service_test.py):
my_media_group = gdata.media.Group(
title = gdata.media.Title(text=title),
description = gdata.media.Description(description_type='plain',
text=description),
keywords = gdata.media.Keywords(text= tags),
category = gdata.media.Category(
text='Autos',
scheme='http://gdata.youtube.com/schemas/2007/categories.cat',
label='Autos'),
player=None
)
# Set Geo location to 37,-122 lat, long
where = gdata.geo.Where()
where.set_location((37.0,-122.0))
video_entry = gdata.youtube.YouTubeVideoEntry(media=my_media_group, geo=where)
print "Creating a video entry: done."
print "Uploading video"
new_entry = self.client.InsertVideoEntry(video_entry, filepath)
print "Done uploading video."
It always gets stuck at the second last line:
new_entry = self.client.InsertVideoEntry(video_entry, filepath)
So what's wrong? Is there any requirement about filepath (for example, is the path 'C:\video.avi' valid?)
In fact, I just need a way to upload, so please suggest any possible solution.
Edit: 1. I tried to embbed Youtube Upload widget, but it does not seem to work: (there is only one option to load from webcam, and that does not work either.)
<iframe id="widget" type="text/html" width="640" height="390"
src="https://www.youtube.com/upload_embed" frameborder="0"></iframe>
- I use a QWebview to load Youtube' upload page, but Youtube always returns an error. QWebview: Upload to Youtube return error
Edit 2:
I changed the code to:
def getYtSession(self, email = '', password =''):
# if we do not want to reuse our session.
if email != '' and password != '':
yt_service = gdata.youtube.service.YouTubeService()
yt_service.email = email
yt_service.password = password
#login.
try:
print yt_service.ProgrammaticLogin()
self.email = email
self.password = password
self.logged_in = True
self.emit(QtCore.SIGNAL('doneLogin(QString)'), QtCore.QString(email + " " + password))
return yt_service
except:
#Display a warning dialog.
self.logged_in = False
self.emit(QtCore.SIGNAL('failedLogin()'))
return None
elif self.yt_service: # we want to reuse the session.
return self.yt_service
else:
return gdata.youtube.service.YouTubeService()
and in upload function:
self.yt_service = self.getYtSession(self.email, self.password)
try:
new_entry = self.yt_service.InsertVideoEntry(video_entry, filepath)
print "Done uploading video."
self.emit(QtCore.SIGNAL('doneUpload(QString)'), QtCore.QString('Title: ' + title + '\nPath: ' + filepath))
except:
print "Stack trace:"
traceback.print_stack()
It still does not work. And one more problem: the stack trace give nothing helpful:
Stack trace:Login successfully.
File "D:\workplace\simple-media-player\trunk\MyPlayer\src\QtThread.py", line 19, in run self.function(*self.args,**self.kwargs) File "D:\workplace\simple-media-player\trunk\MyPlayer\src\videoplayer.py", line 490, in doRealUpload traceback.print_stack()
That message ("Login successfully.") is printed by a function invoked when the signal doneLogin(QString) is emitted. If I do not put
new_entry = self.yt_service.InsertVideoEntry(video_entry, filepath)
print "Done uploading video."
self.emit(QtCore.SIGNAL('doneUpload(QString)'), QtCore.QString('Title: ' + title + '\nPath: ' + filepath))
in a try-except, then it prints nothing.
More info: I set the video information as follow: Path: C:/Users/huynh/Desktop/REcord1.wmv Name: 'A test video' Tag: 'test, youtube' Description: fafafa