Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from pytube import YouTube
- import dailymotion
- import os
- import sys
- from urlparse import urlparse
- from pprint import pprint
- import subprocess
- from apiclient.discovery import build
- from apiclient.errors import HttpError
- from oauth2client.tools import argparser
- import random
- API_KEY = "" #dailymotion api key
- API_SECRET = "" #dailymotion api secret
- USERNAME = "" #dailymotion username
- PASSWORD = "" #dailymotion password
- DEVELOPER_KEY = "" #youtube api key
- YOUTUBE_API_SERVICE_NAME = "youtube"
- YOUTUBE_API_VERSION = "v3"
- def youtube_search(query,options={}):
- youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
- developerKey=DEVELOPER_KEY)
- # Call the search.list method to retrieve results matching the specified
- # query term.
- search_response = youtube.search().list(
- q=query,
- type='video',
- part="id,snippet",
- videoDuration='short',
- maxResults=25
- ).execute()
- videos = []
- channels = []
- playlists = []
- for search_result in search_response.get("items", []):
- if search_result["id"]["kind"] == "youtube#video":
- videos.append(search_result["id"]["videoId"])
- return videos
- vds = youtube_search(sys.argv.pop(1)) #use first word on command line as search
- #i just pick a random word from 'usr/share/dict/words
- d = dailymotion.Dailymotion()
- d.set_grant_type('password', api_key=API_KEY, api_secret=API_SECRET,
- scope=['manage_videos'], info={'username': USERNAME, 'password': PASSWORD})
- result = random.choice(vds)
- url = "http://youtube.com/watch?v=%s" % result
- print url
- yt = YouTube(url)
- fname = yt.filename
- if os.path.isfile("/tmp/"+fname+".mp4"):
- print "supa udpa"
- os.remove("/tmp/"+fname+".mp4")
- video = yt.get('mp4','360p')
- print "downloading " + fname
- video.download("/tmp")
- print "done downloading " + fname
- carg = ["ffmpeg", "-y", "-i", "/tmp/"+fname+".mp4", "-vcodec", "h264", "-acodec", "mp2", "-preset", "ultrafast", "tmp/"+fname+".mp4"]
- print " ".join(carg)
- FNULL = open(os.devnull, 'w')
- subprocess.call(carg,stdout=FNULL, stderr=subprocess.STDOUT)
- url = d.upload('tmp/'+fname+'.mp4')
- opt = d.post('/me/videos',
- {'url': url, 'title': fname, 'published': 'true', 'channel': 'news'}
- )
- print("url: http://dailymotion.com/video/"+opt['id'])
- os.remove("/tmp/"+fname+".mp4")
- os.remove("tmp/"+fname+".mp4")
Advertisement
Add Comment
Please, Sign In to add comment