コード例 #1
0
def get_file_id(user_id, user_name, password, posts_id, file_url):

    blip_cli=blip_uploader.Blip_CLI()
    blip_cli.debug = False

    mm = blip_cli.Get_MoreMeta(user_id,user_name,password,posts_id)
    pm = blip_cli.Parse_MoreMeta(mm)
    ams = pm['posts'][0]['additionalMedia']

    for am in pm['posts'][0]['additionalMedia']:
        if am['url'] == file_url:
            id = am['id']

    return id
コード例 #2
0
def get_ids(episode_id):

    blip_cli=blip_uploader.Blip_CLI()
    blip_cli.debug = False

    m = blip_cli.Get_VideoMeta(episode_id)
    rss=xml.dom.minidom.parseString(m)

    node=rss.getElementsByTagName("blip:userid")
    user_id = blip_cli.Get_TextFromDomNode(node[0])

    node=rss.getElementsByTagName("blip:posts_id")
    posts_id = blip_cli.Get_TextFromDomNode(node[0])

    return (user_id,posts_id)
コード例 #3
0
ファイル: ckblip.py プロジェクト: jamiehand/veyepar
    def delete_from_blip(self, episode_id, posts_id, file_id, user, password,
                         reason):
        # http://blip.tv/file/delete/Pyohio-GettingToKnowMongoDBUsingPythonAndIronPython664.flv?reason="just cuz."
        #http://blip.tv/?cmd=delete;id=Veyepar_test-TestEpisode0760.ogv;s=file;undelete=

        if self.last_del_id != episode_id:
            # only print this once per episode_id
            print "http://blip.tv/file/%s" % (episode_id, )
            print "http://blip.tv/file/%s?skin=rss" % (episode_id, )
            print "http://blip.tv/dashboard/episode/%s" % (posts_id, )
            self.last_del_id = episode_id

        print "delete:", file_id
        return

        # user,password = ('veyepar_test','bdff6680')
        fields = {
            # "post": "1",
            "cmd": "delete",
            "skin": "xmlhttprequest",
            "userlogin": user,
            "password": password,
            "item_type": "file",
            "reason": reason,
            "id": file_id
        }

        blip_cli = blip_uploader.Blip_CLI()
        # blip_delete_url="http://blip.tv/file/delete/%s" % file_id
        blip_delete_url = "http://blip.tv/"
        # print blip_delete_url
        response = blip_cli.PostMultipart(blip_delete_url, fields)

        response_xml = response.read()
        if self.options.verbose: print response_xml
        tree = xml.etree.ElementTree.fromstring(response_xml)
        response = tree.find('response')
        if self.options.verbose: print "response.txt", response.text
        notice = response.find('notice')
        if xml.etree.ElementTree.iselement(notice):
            print "notice.text", notice.text

        return response
コード例 #4
0
def pick_one(episode_id):
    """
    pick a random file from the passed episode.
    """

    blip_cli=blip_uploader.Blip_CLI()
    blip_cli.debug = False

    xml_code = blip_cli.Get_VideoMeta(episode_id)
    blip_meta = blip_cli.Parse_VideoMeta(xml_code)

    ogvs = []
    for content in blip_meta['contents']:
        url = content['url']
        if content['type'] == 'video/ogg':
            ogvs.append(url)
        
    r = random.randint(0,len(ogvs)-1)
    ogv=ogvs[r]
    return ogv
コード例 #5
0
ファイル: ckblip.py プロジェクト: jamiehand/veyepar
    def update_meta(self, ep):
        # upload current description.
        # to fix the ones that were missing due to improper unicode handeling

        blip_cli = blip_uploader.Blip_CLI()
        blip_cli.debug = self.options.verbose
        user = ep.show.client.host_user if ep.show.client.host_user \
                else self.options.host_user
        password = pw.blip[user]

        meta = {'title': ep.name, 'description': ep.description}

        response = blip_cli.Upload(
            ep.host_url,
            user,
            password,
            [],
            meta,
        )
        response_xml = response.read()
        if self.options.verbose: print response_xml

        return
コード例 #6
0
def up(blip_user,blip_pw, filename, blip_id=''):
    """
    upload the passed filename.
    if blip_id is passed, add the file to the existing blip episode
    else create a new episode.
    """

    blip_cli=blip_uploader.Blip_CLI()
    blip_cli.debug = False

    meta = { 'title': 'delete test', 'description': '' }
    files = [['', 'Master', filename], ['1', 'Web', filename]]

    response_obj = blip_cli.Upload(
            blip_id, blip_user, blip_pw, files, meta )

    response_xml = response_obj.read()
    tree = xml.etree.ElementTree.fromstring(response_xml)
    response = tree.find('response')
    post_url=response.find('post_url')
    blip_id=post_url.text.split('/')[-1]

    return blip_id
コード例 #7
0
ファイル: ckblip.py プロジェクト: jamiehand/veyepar
    def post(self, ep, file_types_to_upload, user, password):

        blip_cli = blip_uploader.Blip_CLI()

        files = []
        for ext in file_types_to_upload:
            role = roles.get(ext, {'description': "extra", 'num': '9'})
            fileno = role['num']
            role_desc = role['description']
            src_pathname = os.path.join(self.show_dir, ext,
                                        "%s.%s" % (ep.slug, ext))
            files.append((fileno, role_desc, src_pathname))

        src_pathname = '%s/ogv/%s.ogv' % (self.show_dir, ep.slug)

        if self.options.test:
            print "Test mode, not uploading:", files
        else:
            response = blip_cli.Upload(ep.host_url, user, password, files,
                                       {'title': ep.name})

            response_xml = response.read()
            if self.options.verbose: print response_xml
            ep.comment += "\n%s\n" % response_xml
コード例 #8
0
  def process_ep(self, ep):
    if self.options.verbose: print ep.id, ep.name
    if not ep.released:
        if self.options.verbose: print "not released:", ep.released
        return False

    loc = ep.location
    show = ep.show
    client = show.client

    descriptions = [ep.authors, ep.description, show.description, client.description]
    descriptions = [d for d in descriptions if d]
    description = "</p>\n".join(descriptions)
    description = "<br/>\n".join(description.split('\n'))

    blip_cli=blip_uploader.Blip_CLI()
    blip_cli.debug = self.options.verbose

    meta = {
        'title': ep.name,
        'description': description,
        }

# if .target is blank, a new episode will be created and .target set
# else it will use the id of the episode from a previous run. 
    video_id = ep.host_url

    tags = [ self.options.topics, client.slug, client.tags, show.slug, ep.tags ]
    # camelcase the AuthorNames.
    authors = ep.authors.split(',')
    authors = [ a.replace(' ','') for a in authors ]
    tags += authors

    meta['topics'] = ' '.join([tag for tag in tags if tag] )

    if ep.license: 
        license = ep.license
    elif self.options.license:
        license = self.options.license
    else:
        license = 'CC BY-SA'

    meta['license'] = {'CC BY-SA': '13'}[license]

    if self.options.rating:
        meta['content_rating'] = self.options.rating

    if self.options.category:
        meta['categories_id'] = self.options.category

    if self.options.hidden:
        meta['hidden'] = self.options.hidden

    # find a thumbnail
    # check for episode.tumb used in the following:
    # 1. absololute path (dumb?)
    # 2. in tumb dir (smart)
    # 3. relitive to show dir (not completely wonky)
    # 4. in tumb dir, same name as episode.png (smart)
    # if none of those, then grab the thumb from the first cut list file
    found=False
    for thumb in [ 
          ep.thumbnail,
          os.path.join(self.show_dir,'thumb',ep.thumbnail),
          os.path.join(self.show_dir,ep.thumbnail),
          os.path.join(self.show_dir,'thumb',ep.slug+".png"),]:
          if os.path.isfile(thumb): 
              found=True
              break
    if not found:
         for cut in Cut_List.objects.filter(
                 episode=ep,apply=True).order_by('sequence'):
             basename = cut.raw_file.basename()        
             thumb=os.path.join(self.episode_dir, "%s.png"%(basename))
             if os.path.exists(thumb): 
                 found=True
                 break
    if not found: thumb=''

    
# the blip api gets kinda funky around multiple uploads
# so no surprise the code is kinda funky.
    files = []
    exts = self.options.upload_formats
# pull dv from the list
    exts = [e for e in exts if e != 'dv']
    has_master = False
    for ext in exts:
        role=roles.get(ext, {'description':"extra",'num':'9'})
        if role['description'] == 'Master': has_master = True
        fileno=role['num']
        role_desc = role['description']
        src_pathname = os.path.join( self.show_dir, ext, "%s.%s"%(ep.slug,ext))
        files.append([fileno,role_desc,src_pathname])

    if not video_id and not has_master: 
        # If this is a new upload (no id yet) blip needs one marked as master
        # if nothing is marked as master, mark the first one.
        # this seems like such a hack.
        files[0][0]=''
        files[0][1]='Master'

    if self.options.debug_log:

        # put the mlt and .sh stuff into the log 
        # blip and firefox want it to be xml, so jump though some hoops
        log = "<log>\n"
        mlt_pathname = os.path.join( self.show_dir, 'tmp', "%s.mlt"%(ep.slug,))
        log += open(mlt_pathname).read()
        sh_pathname = os.path.join( self.show_dir, 'tmp', "%s.sh"%(ep.slug,))
        shs = open(sh_pathname).read().split('\n')
        shs = [ "<line>\n%s\n</line>\n" % l for l in shs if l]
        log += "<shell_script>\n%s</shell_script>\n" % ''.join(shs)
        log += "</log>"

        # blip says: try something like a tt or srt file
        log_pathname = os.path.join( self.show_dir, 'tmp', "%s.tt"%(ep.slug,))
        log_file=open(log_pathname,'w').write(log)
        # add the log to the list of files to be posted to blip
        files.append(("10","Captions",log_pathname))
        

    # username comes from options, client, first in pw.py
    # password always comes from pw.py
   
    # print "client blip_user", client.blip_user
    blip_user =  self.options.host_user if self.options.host_user \
                    else client.host_user if client.host_user \
                    else pw.host.keys()[0]
    # print "user", blip_user
    blip_pw = pw.blip[blip_user]

    if self.options.test:
        print 'test mode:'
        print 'blip_cli.Upload( video_id, user, pw, files, meta, thumb)'
        print video_id
        print 'files %s' % files
        print 'meta %s' % meta
        print 'thumb %s' % thumb
        print
    
        blipcmd = "./blip_uploader.py --fileno %s --role %s --filename %s" % (files[0])
        blipcmd += " --thumb %s" % thumb 
        for i in meta.items():
            blipcmd += " --%s %s" % i 
        print blipcmd 

    else:
   
        done=False
        while not done:
        
          response_obj = blip_cli.Upload(
            video_id, blip_user, blip_pw, files, meta, thumb)
          reponse_code = "%s: %s" % (
                  response_obj.status, response_obj.reason)
          response_xml = response_obj.read()

          if 'Guru Meditation' in response_xml:
            # buggy xml, will crash if we try to parse it.
            # xml bugged Sep 22 2010: http://support.blip.tv/requests/17356
            # self.options.verbose=True
            # solution is to just loop.
            done=False 
          else:
            done=True

        if self.options.verbose: print response_xml
        ep.comment += "\n%s\n%s\n" % (reponse_code,response_xml)
        ep.save()

        if response_obj.status == 503:
            ep.state=0
            ep.save()
            return False


        """<?xml version="1.0" encoding="UTF-8"?>
<otterResponses>
<response>
Your file called Test Episode #0 has been successfully posted.
<post_url>http://blip.tv/file/3734423</post_url>
</response>

</otterResponses>
"""

        """<?xml version="1.0" encoding="UTF-8"?>
<otterResponses>
<response>
	<notice>You are not authorized to edit this file.  If you believe you have reached this notice in error please contact your community administrator for assistance.</notice>
</response>

</otterResponses>

'<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html>\n  <head>\n    <title>503 Service Unavailable</title>\n  </head>\n  <body>\n    <h1>Error 503 Service Unavailable</h1>\n    <p>Service Unavailable</p>\n    <h3>Guru Meditation:</h3>\n    <p>XID: 1112821342</p>\n    <hr>\n    <p>Varnish cache server</p>\n  </body>\n</html>\n'

<otterResponses>
<response>
	<error>You must upload a file for your post</error>
	
		<hidden>1</hidden>
	
	<conversiontargets>
		<conversiontarget>
			<id>request_transcode_18</id>
			<name>m4v</name>
		</conversiontarget>
	
		<conversiontarget>
			<id>request_transcode_11</id>
			<name>mp3</name>
		</conversiontarget>
	</conversiontargets>
	
</response>

</otterResponses>


"""
# (02:37:51 PM) Juhaz: CarlFK, no. tree is the root element, it can't find itself, only children.

# there is no blip spec, but by looking at various returns:
# all have <otterResponses/response>
# if that has <post_url>, it was successfull
# otherwise look for the error message in <notice>

        tree = xml.etree.ElementTree.fromstring(response_xml)

        response = tree.find('response')
        post_url=response.find('post_url')
        if xml.etree.ElementTree.iselement(post_url):
            print post_url.text
            self.last_url = post_url.text # hook for tests so that it can be browsed
# <post_url>http://blip.tv/file/3734423</post_url>
            blip_id=post_url.text.split('/')[-1]
            if self.options.verbose:
                print "blip id:", blip_id
            ep.host_url = blip_id
            ep.comment += post_url.text
            self.log_info(response.text)
            ret=True
        else:
            # don't print it again if it was just printed 
            if not self.options.verbose: print response_xml
            ep.comment += "upload failed\n%s\n" % response_xml
            # look for the error message
            notice=response.find('notice')
            if xml.etree.ElementTree.iselement(notice):
                print "blip notice:", notice.text
                self.log_info(notice.text)
            ret=False
        ep.save()

        return ret
コード例 #9
0
ファイル: ckblip.py プロジェクト: jamiehand/veyepar
    def up_missing_files(self, ep):
        type_map = (
            {
                'ext': 'ogv',
                'mime': 'video/ogg'
            },
            # {'ext':'flv','mime':'video/x-flv'},
            # {'ext':'m4v','mime':'video/x-m4v'},
            # {'ext':'mp3','mime':'audio/mpeg'},
            {
                'ext': 'mp4',
                'mime': 'audio/mpeg'
            },
        )

        # Episode in veypar has been uploaded to blip,
        # use the local blip id and fetch the blip metadata.
        blip_cli = blip_uploader.Blip_CLI()
        blip_cli.debug = self.options.verbose
        xml_code = blip_cli.Get_VideoMeta(ep.host_url)
        if self.options.verbose: print xml_code
        blip_meta = blip_cli.Parse_VideoMeta(xml_code)

        # get int used to get to episode edit page
        rss = xml.dom.minidom.parseString(xml_code)
        node = rss.getElementsByTagName("blip:posts_id")
        posts_id = blip_cli.Get_TextFromDomNode(node[0])

        file_types_to_upload = []
        user = ep.show.client.host_user if ep.show.client.host_user \
            else self.options.host_user
        password = pw.blip[user]

        for t in type_map:
            # for each format, construct local file name
            pathname = os.path.join(self.show_dir, t['ext'],
                                    "%s.%s" % (ep.slug, t['ext']))
            match = False
            if os.path.exists(pathname):
                st = os.stat(pathname)
                local_size = st.st_size
                for content in blip_meta['contents']:
                    if self.options.verbose: print content
                    if content['type'] == t['mime']:
                        blip_size = int(content['fileSize'])
                        if local_size == blip_size:
                            match = True
                            # ep.state=5
                            # ep.save()
                            if self.options.verbose:
                                print t['ext'], "right size"
                        else:
                            # file size mismatch
                            # probably blip file is out of date
                            # and needs to be deleted.
                            # too bad I can't figure ou the blip api for this.
                            file_id = os.path.basename(content['url'])
                            ret = self.delete_from_blip(
                                ep.host_url, posts_id, file_id, user, password,
                                'old version')
                if not match:
                    file_types_to_upload.append(t['ext'])
            else:
                # no local file, see what's on blip
                matches = [
                    c for c in blip_meta['contents'] if c['type'] == t['mime']
                ]
                if matches:
                    if self.options.verbose:
                        print "On blip but not local", matches
                else:
                    print t[
                        'ext'], "missing from http://blip.tv/file/%s" % ep.host_url, ep

        if file_types_to_upload:
            if self.options.verbose: print "upload:", file_types_to_upload
            # self.post(ep,file_types_to_upload,user,password)
        """