Guest User

dailybot

a guest
Jun 6th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from pytube import YouTube
  4. import dailymotion
  5. import os
  6. import sys
  7. from urlparse import urlparse
  8. from pprint import pprint
  9. import subprocess
  10. from apiclient.discovery import build
  11. from apiclient.errors import HttpError
  12. from oauth2client.tools import argparser
  13. import random
  14.  
  15. API_KEY    = "" #dailymotion api key
  16. API_SECRET = "" #dailymotion api secret
  17. USERNAME   = "" #dailymotion username
  18. PASSWORD   = "" #dailymotion password
  19.  
  20. DEVELOPER_KEY = "" #youtube api key
  21. YOUTUBE_API_SERVICE_NAME = "youtube"
  22. YOUTUBE_API_VERSION = "v3"
  23.  
  24. def youtube_search(query,options={}):
  25.   youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
  26.     developerKey=DEVELOPER_KEY)
  27.  
  28.   # Call the search.list method to retrieve results matching the specified
  29.   # query term.
  30.   search_response = youtube.search().list(
  31.     q=query,
  32.     type='video',
  33.     part="id,snippet",
  34.     videoDuration='short',
  35.     maxResults=25
  36.   ).execute()
  37.  
  38.   videos = []
  39.   channels = []
  40.   playlists = []
  41.   pprint(search_response)
  42.   # Add each result to the appropriate list, and then display the lists of
  43.   # matching videos, channels, and playlists.
  44.   for search_result in search_response.get("items", []):
  45.     if search_result["id"]["kind"] == "youtube#video":
  46.       videos.append(search_result["id"]["videoId"])
  47.  
  48.   return videos
  49.  
  50. vds = youtube_search(sys.argv.pop(1))
  51.  
  52. d = dailymotion.Dailymotion()
  53.  
  54. d.set_grant_type('password', api_key=API_KEY, api_secret=API_SECRET,
  55.     scope=['manage_videos'], info={'username': USERNAME, 'password': PASSWORD})
  56.  
  57. result = random.choice(vds)
  58.  
  59. url = "http://youtube.com/watch?v=%s" % result 
  60. print url
  61. yt = YouTube(url)
  62. fname = yt.filename
  63. if os.path.isfile("/tmp/"+fname+".mp4"):
  64.     print "supa udpa"
  65.     os.remove("/tmp/"+fname+".mp4")
  66. video = yt.get('mp4','360p')
  67. print "downloading " + fname
  68. video.download("/tmp")
  69. print "done downloading " + fname
  70. carg = ["ffmpeg", "-y", "-i", "/tmp/"+fname+".mp4", "-vcodec", "h264", "-acodec", "mp2", "-preset", "ultrafast", "tmp/"+fname+".mp4"]
  71. print " ".join(carg)
  72. FNULL = open(os.devnull, 'w')
  73. subprocess.call(carg,stdout=FNULL, stderr=subprocess.STDOUT)
  74. url = d.upload('tmp/'+fname+'.mp4')
  75. opt = d.post('/me/videos',
  76.     {'url': url, 'title': fname, 'published': 'true', 'channel': 'news'}
  77. )
  78. print("url: http://dailymotion.com/video/"+opt['id'])
  79. os.remove("/tmp/"+fname+".mp4")
  80. os.remove("tmp/"+fname+".mp4")
Advertisement
Add Comment
Please, Sign In to add comment