google-code-export / django-syncr

Automatically exported from code.google.com/p/django-syncr
0 stars 0 forks source link

youtube video_id sometimes syncs incorrectly #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Test code:
from syncr.app import youtube
from syncr.youtube.models import Video
sync = youtube.YoutubeSyncr()
sync.syncVideo('bVOpCGk1ngk')
v = Video.objects.get(video_id='bVOpCGk1ngk')
print v.video_id

What is the expected output? What do you see instead?

output is:
Traceback (most recent call last):
  File "./load_initial_data.py", line 99, in <module>
    v = Video.objects.get(video_id='bVOpCGk1ngk')
  File "/sw/lib/python2.5/site-packages/django/db/models/manager.py", line
82, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/sw/lib/python2.5/site-packages/django/db/models/query.py", line
197, in get
    % self.model._meta.object_name)
syncr.youtube.models.DoesNotExist: Video matching query does not exist.

expected output:
'bVOpCGk1ngk'

If you look in the admin you can see that it synced the video information,
but the video_id is missing the first character - stored as 'VOpCGk1ngk'

What version of the product are you using? On what operating system?
Latest SVN

Please provide any additional information below.

The video you test with is important - I think the issue may only be with
video ids that start with a lowercase letter. Many other videos sync correctly.

Original issue reported on code.google.com by rea...@gmail.com on 29 May 2008 at 5:48

GoogleCodeExporter commented 9 years ago
I should have added:
Thanks for the nice app!

Original comment by rea...@gmail.com on 29 May 2008 at 5:50

GoogleCodeExporter commented 9 years ago
For what it's worth, I've found the solution to this problem. The problem is an 
incorrect use of lstrip, which 
actually strips all occurrences of the letters contained in the string to be 
removed if they lead the string (see 
here: http://python.about.com/od/pythonstandardlibrary/a/string-methods.htm).

Change line 67 from this:

video_id = result.findtext('{%s}id' % 
ATOM_NS).lstrip('http://'+self._youtubeGDataHost+self._youtubeFeedBase+'videos/'
)

to this:

video_id = result.findtext('{%s}id' % ATOM_NS).replace('http://' + 
self._youtubeGDataHost + 
self._youtubeFeedBase + 'videos/', '')

and all is well.

Original comment by matthewt...@gmail.com on 18 Jan 2009 at 9:04

GoogleCodeExporter commented 9 years ago
Thanks for the update, this bug has been open for a long time! I've patched 
this into the subversion trunk. 
Leaving ticket open for a bit to test. Credited you in the changelog. Thanks!

Original comment by jesse.l...@gmail.com on 20 Jan 2009 at 2:16