Advertisement
Guest User

Youtube complaint script

a guest
Aug 23rd, 2013
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. import time
  2. import gdata.youtube
  3. import gdata.youtube.service
  4.  
  5. # my Youtube login data
  6. youtube_login = 'fb@frank-buss.de'
  7. youtube_password = 'this-is-not-my-password'
  8.  
  9. # project id, register at https://developers.google.com/youtube/registering_an_application
  10. youtube_project_id = 'foobar1234567'
  11.  
  12. # developer key, get it from https://code.google.com/apis/youtube/dashboard
  13. google_developer_key = 'HJI93........'
  14.  
  15. # complaint details
  16. # the username is the string in the Youtube channel, e.g.
  17. # http://www.youtube.com/channel/UCC1Jo9UvXfS1CmrfbBX759g/videos
  18. complaint_username = 'UCC1Jo9UvXfS1CmrfbBX759g'
  19. complaint_term = 'RIGHTS'
  20. complaint_text = (
  21.     'This is original content from the EEVblog channel, which was uploaded without the permission '
  22.     'from Dave Jones, please remove it. '
  23.     'See http://www.eevblog.com/forum/news/226-of-my-videos-copied/ for details.'
  24. )
  25.  
  26. # start with this EEVblog video copy, in case previous calls to this script exited
  27. eevblog_start_index = 4
  28.  
  29. # connect to Youtube API
  30. print 'login...'
  31. yt_service = gdata.youtube.service.YouTubeService()
  32. yt_service.email = youtube_login
  33. yt_service.password = youtube_password
  34. yt_service.source = youtube_project_id
  35. yt_service.developer_key = google_developer_key
  36. yt_service.client_id = youtube_project_id
  37. yt_service.ProgrammaticLogin()
  38.  
  39. # EEVblog video count
  40. eevblog_count = 0
  41.  
  42. # print video and file a complaint
  43. def printEntryDetailsAndComplain(entry):
  44.     # get title
  45.     title = entry.media.title.text
  46.     if title.startswith('EEVblog '):
  47.         global eevblog_count
  48.         eevblog_count = eevblog_count + 1
  49.         if eevblog_count < eevblog_start_index: return
  50.         # extract ID from URL
  51.         id = entry.id.text
  52.         id = id.split('/')
  53.         id = id[-1]
  54.         # show
  55.         print 'index: %i, id: %s, title: %s' % (eevblog_count, id, title)
  56.         # file a complaint for this video
  57.         yt_service.AddComplaint(complaint_text, complaint_term, id)
  58.         # wait a minute to avoid "too_many_recent_calls" error message
  59.         time.sleep(60)
  60.  
  61. # process all videos of a feed and return the number of processed videos
  62. def printVideoFeed(feed):
  63.     count = len(feed.entry)
  64.     for entry in feed.entry:
  65.         printEntryDetailsAndComplain(entry)
  66.     return count
  67.  
  68. # process all videos of a user
  69. def getAndPrintUserUploads(username):
  70.     index = 1
  71.     while True:
  72.         # build URI, starting at "index"
  73.         uri = 'http://gdata.youtube.com/feeds/api/users/%s/uploads?start-index=%i&max-results=25' % (username, index)
  74.         # get feed
  75.         feed = yt_service.GetYouTubeVideoFeed(uri)
  76.         # process and return, if no more videos
  77.         count = printVideoFeed(feed)
  78.         if count == 0: return
  79.         index = index + count
  80.  
  81. print 'get EEVBlog videos and file complaints'
  82. getAndPrintUserUploads(complaint_username)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement