def test_init(self):
        d = dailymotion.Dailymotion()
        self.assertEqual(d.api_base_url, 'https://api.dailymotion.com')

        d = dailymotion.Dailymotion(api_base_url='http://api.stage.dailymotion.com', timeout=10, debug=True)
        self.assertEqual(d.api_base_url, 'http://api.stage.dailymotion.com')
        self.assertEqual(d.timeout, 10)
        self.assertEqual(d.debug, True)
Ejemplo n.º 2
0
    def test_session_store_option(self):
        d = dailymotion.Dailymotion(session_store_enabled=False)
        self.assertFalse(d._session_store_enabled)

        d = dailymotion.Dailymotion(session_store_enabled=True)
        self.assertTrue(d._session_store_enabled)

        d = dailymotion.Dailymotion(session_store_enabled=None)
        self.assertEqual(d.DEFAULT_SESSION_STORE, d._session_store_enabled)
Ejemplo n.º 3
0
 def test_file_storage_session(self):
     fs = dailymotion.FileSessionStore(self.session_file_directory)
     d = dailymotion.Dailymotion(
         api_base_url=self.api_base_url,
         oauth_authorize_endpoint_url=self.oauth_authorize_endpoint_url,
         oauth_token_endpoint_url=self.oauth_token_endpoint_url,
         session_store_enabled=True,
         session_store=fs)
     d.set_grant_type('password',
                      api_key=self.api_key,
                      api_secret=self.api_secret,
                      scope=self.scope,
                      info={
                          'username': self.username,
                          'password': self.password
                      })
     access_token = d.get_access_token()
     self.assertEqual(
         isinstance(access_token, str) or isinstance(access_token, unicode),
         True)
     second_access_token = d.get_access_token()
     self.assertEqual(
         isinstance(second_access_token, str)
         or isinstance(second_access_token, unicode), True)
     self.assertEqual(second_access_token, access_token)
     d.logout()
Ejemplo n.º 4
0
 def test_get(self):
     d = dailymotion.Dailymotion()
     videos = d.get('/videos')
     self.assertEqual('has_more' in videos, True)
     self.assertEqual(videos['has_more'], True)
     self.assertEqual('list' in videos, True)
     self.assertEqual(len(videos['list']) > 0, True)
Ejemplo n.º 5
0
def retrieveData(idVideo):
    """
        Retrieve information about the video corresponding to `idVideo`,
        insert it in the database and print it. If the information of the
        video are already in the database, it doesn't query the dailymotion
        api.
    """
    # Create database if it doesn't exists
    if not os.path.exists('videos_data.db'):
        create_db()

    video_data = get_video_infos(idVideo)

    if video_data is None:
        # Query the dailymotion api
        try:
            d = dailymotion.Dailymotion()
            data = d.get('/video/' + idVideo, {
                'fields':
                'title,description,thumbnail_url,duration,views_total'
            })
            video_data = (
                idVideo,
                data['title'],
                data['description'],
                data['duration'],
                data['views_total'],
                data['thumbnail_url'],
            )
            insert_data(video_data)
        except dailymotion.DailymotionApiError as e:
            print("Dailymotion Error: ", e)
            sys.exit(2)

    print_data(video_data)
 def test_set_access_token(self):
     d = dailymotion.Dailymotion()
     d.set_grant_type('password', api_key=self.api_key, api_secret=self.api_secret, scope=self.scope, info={'username': self.username, 'password': self.password})
     d.set_access_token(d.get_access_token())
     response = d.get('/me/?fields=fullname')
     self.assertEqual(isinstance (response.get('fullname'), str) or isinstance(response.get('fullname'), unicode), True)
     d.logout()
    def test_xupload(self):
        d = dailymotion.Dailymotion(
            api_base_url=self.api_base_url,
            oauth_authorize_endpoint_url=self.oauth_authorize_endpoint_url,
            oauth_token_endpoint_url=self.oauth_token_endpoint_url,
            session_store_enabled=True)

        d.set_grant_type('password',
                         api_key=self.api_key,
                         api_secret=self.api_secret,
                         scope=self.scope,
                         info={
                             'username': self.username,
                             'password': self.password
                         })
        url = d.upload(self.file_path, workers=5)
        self.assertEqual(
            re.match(
                'https?://(?:www)?(?:[\w-]{2,255}(?:\.\w{2,6}){1,2})(?:/[\w&%?#-]{1,300})?',
                url) == None, False)
        video = d.post(
            '/videos', {
                'url': url,
                'title': 'my_test_upload_%s' % time.strftime("%c"),
                'published': 'true',
                'channel': 'news'
            })
        self.assertEqual('id' in video, True)
        d.delete('/video/%s' % video['id'])
        d.logout()
Ejemplo n.º 8
0
    def upload_movie(movie_id, file_name):
        """
            Use Dailymotion API to send a movie.

            movie_id  - BioInfuse Movie id
            file_name - file path to the submitted movie file, temporary
        """
        d = dailymotion.Dailymotion()
        d.set_grant_type('password',
                         api_key=API_KEY,
                         api_secret=API_SECRET,
                         scope=['manage_videos'],
                         info={
                             'username': USERNAME,
                             'password': PASSWORD
                         })
        q_movie = Movie.objects.get(id=movie_id)
        url = d.upload(file_name)
        movie = d.post(
            '/me/videos', {
                'url': url,
                'title': q_movie.title,
                'published': 'true',
                'channel': 'tech',
                'private': 'true',
                'description': q_movie.description
            })
        """
        WARNING: the below part is wrong. The actual URL stored in DB is not in
                 an embedding format! Need to retrieve the embed_url field from
                 Dailymotion
        """
        q_movie.movie_url = 'http://www.dailymotion.com/video/' + \
                            str(movie['id'])
        q_movie.save()
 def test_get_access_token(self):
     d = dailymotion.Dailymotion(api_base_url=self.api_base_url,
                             oauth_authorize_endpoint_url=self.oauth_authorize_endpoint_url,
                             oauth_token_endpoint_url=self.oauth_token_endpoint_url)
     d.set_grant_type('password', api_key=self.api_key, api_secret=self.api_secret, scope=self.scope, info={'username': self.username, 'password': self.password})
     access_token = d.get_access_token()
     self.assertEqual(isinstance (access_token, str) or isinstance(access_token, unicode), True)
     d.logout()
Ejemplo n.º 10
0
def userpage(url,page="1") :   
  d = dailymotion.Dailymotion()
  channel=d.get(url+"&page="+page)
  for element in channel["list"]:
      addDir(element["username"], element["id"], 'uservideo', element["avatar_720_url"])  
  page=int(page)+1
  debug("nextpage :"+str(page))
  addDir("Next", url, "userpage","",page=str(page))   
  xbmcplugin.endOfDirectory(addon_handle,succeeded=True,updateListing=False,cacheToDisc=True)     
Ejemplo n.º 11
0
def playlisten(url,page):
   d = dailymotion.Dailymotion()
   video=d.get(url+'&page='+page)
   for element in video["list"]:
     addDir(element["name"], element["id"], 'playlist', element["thumbnail_720_url"])  
   page=int(page)+1
   debug("nextpage :"+str(page))
   addDir("Next", url, "playlisten","",page=str(page))        
   xbmcplugin.endOfDirectory(addon_handle,succeeded=True,updateListing=False,cacheToDisc=True)     
    def test_auth_call(self):
        d = dailymotion.Dailymotion(api_base_url=self.api_base_url,
                                oauth_authorize_endpoint_url=self.oauth_authorize_endpoint_url,
                                oauth_token_endpoint_url=self.oauth_token_endpoint_url,
                                session_store_enabled=True)

        d.set_grant_type('password', api_key=self.api_key, api_secret=self.api_secret, scope=self.scope, info={'username': self.username, 'password': self.password})
        response = d.get('/me/?fields=fullname')
        self.assertEqual(isinstance (response.get('fullname'), str) or isinstance(response.get('fullname'), unicode), True)
        d.logout()
Ejemplo n.º 13
0
def channel(url,page="1"):
  debug("URL channel: "+ url)
  debug("Page :"+page)
  d = dailymotion.Dailymotion()
  channel=d.get(url+"&page="+page)
  for element in channel["list"]:
    addLink(element["title"], element["id"], 'video', "http://www.dailymotion.com/thumbnail/video/"+element["id"])  
  page=int(page)+1
  debug("nextpage :"+str(page))
  addDir("Next", url, "channel","",page=str(page))   
  xbmcplugin.endOfDirectory(addon_handle,succeeded=True,updateListing=False,cacheToDisc=True)     
Ejemplo n.º 14
0
def uservideo(id,page="1")  :
  debug(":uservideo:")  
  debug(":ID:"+id)  
  d = dailymotion.Dailymotion()
  channel=d.get("/user/"+str(id)+"/videos?fields=id,thumbnail_720_url,title&page="+str(page))
  for element in channel["list"]:
      addLink(element["title"], element["id"], 'video', element["thumbnail_720_url"])  
  page=int(page)+1
  debug("nextpage :"+str(page))
  addDir("Next", id, "uservideo","",page=str(page))   
  xbmcplugin.endOfDirectory(addon_handle,succeeded=True,updateListing=False,cacheToDisc=True)     
Ejemplo n.º 15
0
 def _get_metas(self):
     client = dailymotion_api.Dailymotion()
     metas = []
     with codecs.open(self.id_file, 'r', 'utf8') as id_file_handle:
         for video_id in id_file_handle.read().splitlines():
             if not video_id:
                 continue
             metas.append(
                 client.get('/video/%s?fields=id,title,description' %
                            video_id))
     with codecs.open(self.meta_file, 'w', 'utf8') as meta_file_handle:
         json.dump(metas, meta_file_handle)
Ejemplo n.º 16
0
 def test_get_authorization_url(self):
     d = dailymotion.Dailymotion(
         api_base_url=self.api_base_url,
         oauth_authorize_endpoint_url=self.oauth_authorize_endpoint_url)
     d.set_grant_type('authorization',
                      api_key=self.api_key,
                      api_secret=self.api_secret,
                      scope=self.scope,
                      info={'redirect_uri': self.redirect_uri})
     authorization_url = d.get_authorization_url(
         redirect_uri=self.redirect_uri, scope=self.scope)
     self.assertEqual(
         re.match(
             'https?://(?:www)?(?:[\w-]{2,255}(?:\.\w{2,6}){1,2})(?:/[\w&%?#-]{1,300})?',
             authorization_url) == None, False)
Ejemplo n.º 17
0
def video(id)  :
  Quality=addon.getSetting("Quality") 
  debug("Quality :"+Quality)
  d = dailymotion.Dailymotion()
  video=d.get('/video/'+id+'?fields=url')
  url=video["url"]
  vid = YDStreamExtractor.getVideoInfo(url,quality=Quality) #quality is 0=SD, 1=720p, 2=1080p and is a maximum
  try:
      stream_url = vid.streamURL() #This is what Kodi (XBMC) will play
      stream_url=stream_url.split("|")[0]
      debug("stream_url :"+stream_url)
      listitem = xbmcgui.ListItem(path=stream_url)  
      xbmcplugin.setResolvedUrl(addon_handle,True, listitem) 
  except:
     xbmc.executebuiltin('XBMC.Notification("VideoURL not found","VideoURL not found")')
     xbmcplugin.endOfDirectory(addon_handle,succeeded=True,updateListing=False,cacheToDisc=True)     
Ejemplo n.º 18
0
def video(id)  :
  Quality=addon.getSetting("Quality")
  qstring="1280x720"
  if Quality=="0":
    qstring="848x480"
  if Quality=="1":
    qstring="1280x720"
  if Quality=="2":
    qstring="1920x1080"  
  if Quality=="3":
    qstring="##########"
  debug("Quality :"+Quality)
  d = dailymotion.Dailymotion()
  video=d.get('/video/'+id+'?fields=url')
  url=video["url"]
  vid = YDStreamExtractor.getVideoInfo(url,quality=Quality) #quality is 0=SD, 1=720p, 2=1080p and is a maximum
  videos=vid.streams()[0]["ytdl_format"]["formats"]
  erg=""
  videos_arr=[]
  namen_arr=[]  
  for video in videos:
        name=video["format"]                
        namen_arr.append(name)
        videos_arr.append(video["url"])
        if qstring in video["format"] and "hls" in video["format"]:
            erg=video["url"]
            break        
  if Quality=="3":
     dialog = xbmcgui.Dialog()
     nr=dialog.select("Qualität", namen_arr) 
     erg=videos_arr[nr]
  try:
      if erg=="":
        stream_url = vid.streamURL() #This is what Kodi (XBMC) will play
        stream_url=stream_url.split("|")[0]
      else:
        stream_url=erg
      debug("stream_url :"+stream_url)
      listitem = xbmcgui.ListItem(path=stream_url)  
      xbmcplugin.setResolvedUrl(addon_handle,True, listitem) 
  except:
     xbmc.executebuiltin('XBMC.Notification("VideoURL not found","VideoURL not found")')
     xbmcplugin.endOfDirectory(addon_handle,succeeded=True,updateListing=False,cacheToDisc=True)     
Ejemplo n.º 19
0
 def test_set_grant_type(self):
     d = dailymotion.Dailymotion()
     self.assertRaises(dailymotion.DailymotionClientError,
                       d.set_grant_type,
                       'password',
                       api_secret=self.api_secret,
                       scope=self.scope,
                       info={
                           'username': self.username,
                           'password': self.password
                       })
     self.assertRaises(dailymotion.DailymotionClientError,
                       d.set_grant_type,
                       'password',
                       api_secret=self.api_secret,
                       scope=self.scope)
     self.assertRaises(dailymotion.DailymotionClientError,
                       d.set_grant_type,
                       'password',
                       api_secret=self.api_secret,
                       scope=None)
Ejemplo n.º 20
0
def upload(arg):
    d = dailymotion.Dailymotion(
        api_base_url=api_base_url,
        oauth_authorize_endpoint_url=oauth_authorize_endpoint_url,
        oauth_token_endpoint_url=oauth_token_endpoint_url,
        session_store_enabled=True)
    d.set_grant_type('password',
                     api_key=api_key,
                     api_secret=api_secret,
                     scope=['manage_videos'],
                     info={
                         'username': username,
                         'password': password
                     })
    channel = str(arg)[16:-2]
    path = glob.glob("/media/usb/" + channel + "/*avi") + glob.glob(
        "/media/usb/" + channel +
        "/*mp4") + glob.glob("/media/usb/" + channel +
                             "/*flv") + glob.glob("/media/usb/" + channel +
                                                  "/*mov")
    for i in path:
        if nope(i) is None:
            url = d.upload(i)
            d.post(
                '/videos', {
                    'url': url,
                    'title': 'temp_%s' % time.strftime("%c"),
                    'published': 'false',
                    'channel': 'news'
                })
            logging = 'echo "' + i + '" >> ~/VidUploadServer/uploaded_videos.log'
            os.system(logging)
            path = glob.glob("/media/usb/" + channel + "/*avi") + glob.glob(
                "/media/usb/" + channel +
                "/*mp4") + glob.glob("/media/usb/" + channel +
                                     "/*flv") + glob.glob("/media/usb/" +
                                                          channel + "/*mov")
Ejemplo n.º 21
0
 def __init__(self):
     self.daily_client = dailymotion.Dailymotion()
     self.logger = logutils.get_logger("Daily Motion Ingestion")
Ejemplo n.º 22
0
def channels():
  d = dailymotion.Dailymotion()
  videos=d.get('/channels')
  for element in videos["list"]:
    addDir(element["name"], element["id"], 'channelmenu', "",desc=element["description"])  
  xbmcplugin.endOfDirectory(addon_handle,succeeded=True,updateListing=False,cacheToDisc=True)  
Ejemplo n.º 23
0
def add_notes(request, movie_id):
    """
        Where a BioInfuse Member (role 'J') can evaluate a BioInfuse Movie

        request  - html page requested add_notes.html
        movie_id - BioInfuse Movie id
    """
    context = base(request)
    context['movie_id'] = movie_id
    movie = Movie.objects.get(id=movie_id)
    #challenge = Challenge.objects.get(movie=movie)
    """
    WARNING: the below part is a fix. The actual URL stored in DB is not in
             an embedding format! Miss embed/ before video/
    """
    d = dailymotion.Dailymotion()
    d.set_grant_type('password',
                     api_key=API_KEY,
                     api_secret=API_SECRET,
                     scope=['manage_videos'],
                     info={
                         'username': USERNAME,
                         'password': PASSWORD
                     })
    daily_id = re.sub(r'http:\/\/www.dailymotion.com\/video\/', '',
                      movie.movie_url)
    movie_url = d.get('/video/' + daily_id,
                      {'fields': 'embed_url'})['embed_url']
    if request.user.id:
        role = Member.objects.get(user=request.user.id).role
    else:
        role = 'I'
    if request.method == 'GET':
        try:
            votes = Vote.objects.get(id_movie=movie_id)
            notes_form = VoteNotesForm({
                'global_note': votes.global_note,
                'artistic_note': votes.artistic_note,
                'originality_note': votes.originality_note,
                'investment_note': votes.investment_note,
                'take_home_message_note': votes.take_home_message_note,
                'understandable_note': votes.understandable_note,
                'scientific_note': votes.scientific_note,
                'captive_interest_note': votes.captive_interest_note,
                'rigorous_note': votes.rigorous_note
            })
            comment_form = VoteCommentForm({'comment': votes.comment})
        except:
            notes_form = VoteNotesForm()
            comment_form = VoteCommentForm()
    else:
        notes_form = VoteNotesForm(request.POST)
        comment_form = VoteCommentForm(request.POST)
        if notes_form.is_valid() and comment_form.is_valid() and role == 'J':
            membre = Member.objects.get(user=request.user.id)
            comment = comment_form.cleaned_data['comment']
            global_note = notes_form.cleaned_data['global_note']
            artistic = notes_form.cleaned_data['artistic_note']
            originality = notes_form.cleaned_data['originality_note']
            investment = notes_form.cleaned_data['investment_note']
            take_home_message = notes_form.cleaned_data[
                'take_home_message_note']
            understandable = notes_form.cleaned_data['understandable_note']
            scientific = notes_form.cleaned_data['scientific_note']
            captive = notes_form.cleaned_data['captive_interest_note']
            rigorous = notes_form.cleaned_data['rigorous_note']
            submit_notes = Vote.objects.create(
                id_jury=membre,
                id_challenge=movie.challenge,
                id_movie=movie,
                global_note=global_note,
                artistic_note=artistic,
                originality_note=originality,
                investment_note=investment,
                take_home_message_note=take_home_message,
                understandable_note=understandable,
                scientific_note=scientific,
                captive_interest_note=captive,
                rigorous_note=rigorous,
                comment=comment)
            submit_notes.save()

            return HttpResponseRedirect(reverse('bioinfuse:manage_notes'))

    context['role'] = role
    context['movie_url'] = movie_url
    context['movie_desc'] = movie.description
    context['notes_form'] = notes_form
    context['comment_form'] = comment_form
    return render(request, "add_notes.html", context)
Ejemplo n.º 24
0
 def __init__(self, video_id):
     self.client = dailymotion_api.Dailymotion()
     self._id = video_id
Ejemplo n.º 25
0
 def __init__(self, user_id):
     self.client = dailymotion_api.Dailymotion()
     self._id = user_id
Ejemplo n.º 26
0
import json
import re
import config

import csv
import pandas as pd
import dailymotion

import playlists

PLAYLISTS = playlists.DAILYMOTION
# PLAYLISTS = ['_']

# SETUP

d = dailymotion.Dailymotion()

api_key = config.CLIENT_ID
api_secret = config.CLIENT_SECRET
api_username = config.USERNAME
api_password = config.PASSWORD
api_url = config.BASE_URL

d.set_grant_type('password',
                 api_key,
                 api_secret,
                 scope=['userinfo'],
                 info={
                     'username': api_username,
                     'password': api_password
                 })
Ejemplo n.º 27
0
 def __init__(self, channel_id):
     self.client = dailymotion_api.Dailymotion()
     self._id = channel_id