Your Digital Media Has Never Looked So Good

 
astromo
Topic Author
Posts: 12
Joined: Sun Nov 27, 2011 6:37 pm

Youtube contents in a private channel ?

Sun Nov 27, 2011 6:41 pm

Hello All,

I plan to make a private channel. Some of contents are from youtube. Is it possible technically and legal to include Youtube contents in a private channel. Thanks.
 
bking007
Posts: 4
Joined: Sat Nov 19, 2011 4:00 pm

Re: Youtube contents in a private channel ?

Wed Nov 30, 2011 3:38 pm

I believe it is very much legal to create a private channel that include your own videos.
 
User avatar
gonzotek
** Valued Community Member **
Posts: 2206
Joined: Thu May 06, 2010 12:40 pm
Contact:

Re: Youtube contents in a private channel ?

Wed Nov 30, 2011 3:57 pm

bking007 wrote:
I believe it is very much legal to create a private channel that include your own videos.
Legal, yes. However it might be a violation of the YouTube Terms of Service to use their hosting in a manner not approved by them. They give the hosting away for free because they can attach ads to videos displayed on the website and embedded on other sites. Some devices, like Apple TV, display Youtube without ads, but my understanding is this is possible because the device manufacturer had negotiated a contract with Google to pay for access to it.
Remoku.tv - A free web app for Roku Remote Control!
Want to control your Roku from nearly any phone, computer or tablet? Get started at http://help.remoku.tv
by Apps4TV - Applications for television and beyond: http://www.apps4tv.com
 
astromo
Topic Author
Posts: 12
Joined: Sun Nov 27, 2011 6:37 pm

Re: Youtube contents in a private channel ?

Wed Nov 30, 2011 4:31 pm

Thank you. I intend to develop a channel as a library of my media (some are video files but some have been shared on Youtube). Please suggest me the command or script that I should start with to insert the youtube link in the private channel.
 
timber03
Posts: 35
Joined: Sat Oct 09, 2010 6:29 am
Contact:

Re: Youtube contents in a private channel ?

Wed Nov 30, 2011 11:04 pm

astromo, I have a channel in development that will do just that. I hope to make it available for beta testing in the coming weeks.
Channels created
--------------------
REDBULLTV - RedBull's online sports channel. All sports, all the time.
JTV - Jewelry TV

Other Projects/Creations
-----------------------------
http://www.socialnetworkinc.com - Your Community. Connected.
 
astromo
Topic Author
Posts: 12
Joined: Sun Nov 27, 2011 6:37 pm

Re: Youtube contents in a private channel ?

Thu Dec 01, 2011 12:06 am

What is a basic script to add the content in the videoscreen? And what is the URL to be used for pointing to youtube contents?
 
sftv
Posts: 12
Joined: Thu Apr 14, 2011 8:53 am
Location: USA

Re: Youtube contents in a private channel ?

Thu Dec 01, 2011 7:58 am

astromo wrote:
What is a basic script to add the content in the videoscreen? And what is the URL to be used for pointing to youtube contents?
Last edited by sftv on Sun Dec 04, 2011 8:17 pm, edited 1 time in total.
 
belltown
Posts: 1465
Joined: Thu Dec 09, 2010 1:43 pm
Contact:

Re: Youtube contents in a private channel ?

Fri Dec 02, 2011 11:39 pm

astromo wrote:
And what is the URL to be used for pointing to youtube contents?


You could try this function:

'**********************************************************************************************************************
' ytGetMP4Url - Retrieve a list of MP4 urls from YouTube for the specified video id
'
' Example usage:
'
'   videoId = "S2wAMaM2OYQ"                     ' (required) YouTube Video Id
'                                               '   Alternatively, the full Url of the YouTube video may be specified here
'   timeout = 60000                             ' (optional) Timeout in milliseconds (default: 0 => wait forever)
'   loginCookie = ""                            ' (optional) YouTube login cookie - only required if video requires a login,
'                                               '   e.g. Private or R-Rated videos (default: "")
'                                               '   The login cookie can be obtained by calling ytLoginYouTube
'   mp4VideoList = ytGetMP4Url (videoId, timeout, loginCookie)
'   if mp4VideoList <> Invalid                  ' Invalid returned if no MP4 streams detected
'       sdUrl = mp4VideoList.sdUrl
'       hdUrl = mp4VideoList.hdUrl              ' Will be empty string if no HD MP4 found
'       hd1080pUrl = mp4VideoList.hd1080pUrl    ' Will be empty string if no 1080p MP4 found
'       hlsUrl = mp4VideoList.hlsUrl            ' If an HLS stream is found, set to its index file's Url
'   endif
'**********************************************************************************************************************
function ytGetMP4Url (videoIdOrUrl as string, timeout = 0 as integer, loginCookie = "" as string) as object
    mp4VideoList = {sdUrl: "", hdUrl: "", hd1080pUrl: "", hlsUrl: ""}
    if Left (LCase (videoIdOrUrl), 4) = "http"
        url = videoIdOrUrl
    else
        url = "http://www.youtube.com/get_video_info?hl=en&el=detailpage&video_id=" + videoIdOrUrl
    endif
   
    '
    ' Get the web page containing video information
    '
    htmlString = ""
    port = CreateObject ("roMessagePort")
    ut = CreateObject ("roUrlTransfer")
    ut.SetPort (port)
    ut.AddHeader ("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0 (gzip)")
    if loginCookie <> ""
        ut.AddHeader ("Cookie", loginCookie)
    endif
    ut.SetCertificatesFile ("common:/certs/ca-bundle.crt")
    ut.InitClientCertificates ()
    ut.EnableEncodings (true)
    ut.SetUrl (url)
    if ut.AsyncGetToString ()
        while true
            msg = Wait (timeout, port)
            if type (msg) = "roUrlEvent"
                status = msg.GetResponseCode ()
                print "ytGetMP4Url. MP4 Url Request: Url = " + url + ". status = " + status.ToStr () + ". failureReason = " + msg.GetFailureReason ()
                if status = 200
                    htmlString = msg.GetString ()
                    print "htmlString=" + htmlString
                endif
                exit while
            else if type (msg) = "Invalid"
                ut.AsyncCancel ()
                print "ytGetMP4Url. Timeout"
                exit while
            endif
        end while
    endif
   
    '
    ' urlEncodedFmtStreamMap contains any mp4 urls
    ' TODO: Check if 1080p support has been discontinued
    '
    urlEncodedFmtStreamMap = CreateObject ("roRegex", "\x22url_encoded_fmt_stream_map\x22:\x22([^\x22]+)\x22", "").Match (htmlString)
    if urlEncodedFmtStreamMap.Count () > 1
        commaSplit = CreateObject ("roRegex", ",", "").Split (urlEncodedFmtStreamMap [1])
        for each commaItem in commaSplit
            maVideoUrl = CreateObject ("roRegex", "url=(.+)", "").Match (commaItem)
            if maVideoUrl.Count () = 2
                videoUrl = ut.Unescape (maVideoUrl [1])
                print "videoUrl: " + videoUrl
                pair = {itag: ""}
                ampersandSplit = CreateObject ("roRegex", "&", "").Split (videoUrl)
                for each ampersandItem in ampersandSplit
                    equalsSplit = CreateObject ("roRegex", "=", "").Split (ampersandItem)
                    if equalsSplit.Count () = 2
                        pair [equalsSplit [0]] = equalsSplit [1]
                    endif
                end for
                if Left (LCase (videoUrl), 4) = "http"
                    urlDecoded = ut.Unescape (videoUrl)
                    if pair.itag = "18"
                        mp4VideoList.sdUrl = urlDecoded
                    else if pair.itag = "22"
                        mp4VideoList.hdUrl = urlDecoded
                    else if pair.itag = "37"
                        mp4VideoList.hd1080pUrl = urlDecoded
                    endif
                endif
            endif
        end for
    endif
   
    '
    ' If no mp4 urls, check for live (HLS) feed in the hlsvp attribute
    '
    if mp4VideoList.sdUrl = "" and mp4VideoList.hdUrl = "" and mp4VideoList.hd1080pUrl = ""
        ' If no mp4 video streams were found, search for a live stream HLS manifest (.m3u8) file
        hlsvp = CreateObject ("roRegex", "hlsvp=([^(" + Chr(34) + "|&|$)]*)", "").Match (htmlString)
        if hlsvp.Count () > 1
            hlsUrlDecoded = ut.Unescape (ut.Unescape (hlsvp [1]))
            mp4VideoList.hlsUrl = hlsUrlDecoded
        endif
        if mp4VideoList.hlsUrl = ""
            mp4VideoList = Invalid
        endif
    endif
   
    if mp4VideoList <> invalid
        print "ytGetMP4Url. sdUrl="      + mp4VideoList.sdUrl
        print "ytGetMP4Url. hdUrl="      + mp4VideoList.hdUrl
        print "ytGetMP4Url. hd1080pUrl=" + mp4VideoList.hd1080pUrl
        print "ytGetMP4Url. hlsUrl="     + mp4VideoList.hlsUrl
    else
        print "ytGetMP4Url. No Video Streams Found"
    endif
   
    return mp4VideoList
end function
Last edited by belltown on Tue Sep 01, 2015 9:13 am, edited 4 times in total.
https://github.com/belltown/
 
astromo
Topic Author
Posts: 12
Joined: Sun Nov 27, 2011 6:37 pm

Re: Youtube contents in a private channel ?

Sat Dec 03, 2011 5:51 pm

belltown, thank you so much. I can start from there.
 
buenafe
Posts: 70
Joined: Tue Mar 29, 2011 4:44 pm
Location: USA
Contact:

Re: Youtube contents in a private channel ?

Fri Dec 09, 2011 2:57 pm

Belltown, ditto. Thanks. I've been pounding my head trying to understand how other channels did this. I'm trying to go to the next step. I'm trying to integrate your function to the simplevideoplayer.


Function displayVideo(args As Dynamic)
....
url = "http://youtu.be/nGeKSiCQkPw"   ' The URL for the video
mp4Urls = getMP4Url (url)             ' Get a list of all MP4 URLs
sdUrl = mp4Urls.sdUrl
....
'Swap the commented values below to play different video clips...
 urls = [ sdUrl ]
 qualities = ["SD"]
 StreamFormat = "mp4"
....etc.



I get a bug when running this. (I don't have Roku access while I type this message - I'll update this post later).

I did notice that the generated sdUrl variable seems to be correct because I can cut-and-paste the URL to a web-browser to test.

I do notice that the URL contains ampersands "&" . Do I need to replace these with "&amp;" i nthe brightscript code?
----------------------------------------------------------------------------------
current: two roku XDS 2xs, dtvpal, boxeebox, kylo.tv,
radar: wdlxtv.com
 
astromo
Topic Author
Posts: 12
Joined: Sun Nov 27, 2011 6:37 pm

Re: Youtube contents in a private channel ?

Fri Dec 09, 2011 3:38 pm

Buenafe, this is my script that works. You will need to remove some commands to process the SRT subtitle which causes an error.

'*************************************************************
'** displayVideo()
'*************************************************************

Function displayVideo(args As Dynamic)
    print "Displaying video: "
    p = CreateObject("roMessagePort")
    video = CreateObject("roVideoScreen")
    video.setMessagePort(p)

    bitrates  = [0]          ' 0 = no dots, adaptive bitrate
    'bitrates  = [348]    ' <500 Kbps = 1 dot
    'bitrates  = [664]    ' <800 Kbps = 2 dots
    'bitrates  = [996]    ' <1.1Mbps  = 3 dots
    'bitrates  = [2048]    ' >=1.1Mbps = 4 dots

    'video
   
   url = "http://www.youtube.com/watch?v=RfOSqpZ0jEM&feature=youtube_gdata"   ' The URL for the video
   mp4Urls = getMP4Url (url)             ' Get a list of all MP4 URLs
   sdUrl = mp4Urls.sdUrl
   hdUrl = mp4Urls.hdUrl                 ' Will be empty string if no HD MP4 found
   hd1080pUrl = mp4Urls.hd1080pUrl       ' Will be empty string if no 1080p MP4 found
   
    urls = [sdUrl]
    qualities = ["SD"]
    StreamFormat = "mp4"
    title = "Youtube"
      
    if type(args) = "roAssociativeArray"
        if type(args.url) = "roString" and args.url <> "" then
            urls[0] = args.url
        end if
        if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
            StreamFormat = args.StreamFormat
        end if
        if type(args.title) = "roString" and args.title <> "" then
            title = args.title
        else
            title = ""
        end if
    end if
   
    videoclip = CreateObject("roAssociativeArray")
    videoclip.StreamBitrates = bitrates
    videoclip.StreamUrls = urls
    videoclip.StreamQualities = qualities
    videoclip.StreamFormat = StreamFormat
    videoclip.Title = title
   
    video.SetContent(videoclip)
    video.show()

    lastSavedPos   = 0
    statusInterval = 10 'position must change by more than this number of seconds before saving

    while true
        msg = wait(0, video.GetMessagePort())
        if type(msg) = "roVideoScreenEvent"
            if msg.isScreenClosed() then 'ScreenClosed event
                print "Closing video screen"
                exit while
            else if msg.isPlaybackPosition() then
                nowpos = msg.GetIndex()
                if nowpos > 10000
                   
                end if
                if nowpos > 0
                    if abs(nowpos - lastSavedPos) > statusInterval
                        lastSavedPos = nowpos
                    end if
                end if
            else if msg.isRequestFailed()
                print "play failed: "; msg.GetMessage()
            else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        end if
    end while
End Function


 
bandal
Posts: 260
Joined: Sat Oct 15, 2011 2:17 pm

Re: Youtube contents in a private channel ?

Fri Dec 09, 2011 5:11 pm

Tried it on simplevideoplayer and not working. Can you post all the code in appMain.brs?
 
buenafe
Posts: 70
Joined: Tue Mar 29, 2011 4:44 pm
Location: USA
Contact:

Re: Youtube contents in a private channel ?

Fri Dec 09, 2011 6:31 pm

@astromo - thanks. I can't to try this when I get home

I would have never come up with @belltown's function to get that elusive mp4 link. I unsuccessfully tried to understand a python youtube-dl code which did similar thing. I wonder how these guys do it so easily. So much to learn.
----------------------------------------------------------------------------------
current: two roku XDS 2xs, dtvpal, boxeebox, kylo.tv,
radar: wdlxtv.com
 
astromo
Topic Author
Posts: 12
Joined: Sun Nov 27, 2011 6:37 pm

Re: Youtube contents in a private channel ?

Fri Dec 09, 2011 7:40 pm

This is my code. Make sure you the image files are the same as those in your folder.

' ********************************************************************
' **  Sample PlayVideo App
' **  Copyright (c) 2009 Roku Inc. All Rights Reserved.
' ********************************************************************

Sub Main(args As Dynamic)
    'initialize theme attributes like titles, logos and overhang color
    initTheme()

    'has to live for the duration of the whole app to prevent flashing
    'back to the roku home screen.
    screenFacade = CreateObject("roPosterScreen")
    screenFacade.show()

    item = { ContentType:"episode"
               SDPosterUrl:"file://pkg:/images/MainMenu_Icon_Center_HD.png"
               HDPosterUrl:"file://pkg:/images/MainMenu_Icon_Center_HD.png"
               IsHD:True
               HDBranded:True
               ShortDescriptionLine1:""
               ShortDescriptionLine2:""
               Description:""
               Rating:"NR"
               StarRating:"80"
               Length:1972
               Categories:["Technology","Talk"]
               Title:" "
               }

    showSpringboardScreen(item) 
   
    'exit the app gently so that the screen doesn't flash to black
    screenFacade.showMessage("")
    sleep(25)
End Sub

'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'*************************************************************

Sub initTheme()

    app = CreateObject("roAppManager")
    theme = CreateObject("roAssociativeArray")

    theme.OverhangPrimaryLogoOffsetSD_X = "72"
    theme.OverhangPrimaryLogoOffsetSD_Y = "15"
    theme.OverhangSliceSD = "pkg:/images/Overhang_BackgroundSlice_SD43.png"
    theme.OverhangPrimaryLogoSD  = "pkg:/images/Logo_Overhang_SD43.png"

    theme.OverhangPrimaryLogoOffsetHD_X = "123"
    theme.OverhangPrimaryLogoOffsetHD_Y = "20"
    theme.OverhangSliceHD = "pkg:/images/Overhang_BackgroundSlice_HD.png"
    theme.OverhangPrimaryLogoHD  = "pkg:/images/Logo_Overhang_HD.png"
   
    app.SetTheme(theme)

End Sub


'*************************************************************
'** showSpringboardScreen()
'*************************************************************

Function showSpringboardScreen(item as object) As Boolean
    port = CreateObject("roMessagePort")
    screen = CreateObject("roSpringboardScreen")

    print "showSpringboardScreen"
   
    screen.SetMessagePort(port)
    screen.AllowUpdates(false)
    if item <> invalid and type(item) = "roAssociativeArray"
        screen.SetContent(item)
    endif

    screen.SetDescriptionStyle("generic") 'audio, movie, video, generic
                                        ' generic+episode=4x3,
    screen.ClearButtons()
    screen.AddButton(1,"Play")
    screen.AddButton(2,"Go Back")
    screen.SetStaticRatingEnabled(false)
    screen.AllowUpdates(true)
    screen.Show()

    downKey=3
    selectKey=6
    while true
        msg = wait(0, screen.GetMessagePort())
        if type(msg) = "roSpringboardScreenEvent"
            if msg.isScreenClosed()
                print "Screen closed"
                exit while               
            else if msg.isButtonPressed()
                    print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
                    if msg.GetIndex() = 1
                         displayVideo("")
                    else if msg.GetIndex() = 2
                         return true
                    endif
            else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        else
            print "wrong type.... type=";msg.GetType(); " msg: "; msg.GetMessage()
        endif
    end while


    return true
End Function


'*************************************************************
'** displayVideo()
'*************************************************************

Function displayVideo(args As Dynamic)
    print "Displaying video: "
    p = CreateObject("roMessagePort")
    video = CreateObject("roVideoScreen")
    video.setMessagePort(p)

    bitrates  = [0]          ' 0 = no dots, adaptive bitrate
    'bitrates  = [348]    ' <500 Kbps = 1 dot
    'bitrates  = [664]    ' <800 Kbps = 2 dots
    'bitrates  = [996]    ' <1.1Mbps  = 3 dots
    'bitrates  = [2048]    ' >=1.1Mbps = 4 dots

    'video
   
   url = "http://www.youtube.com/watch?v=RfOSqpZ0jEM&feature=youtube_gdata"   ' The URL for the video
   mp4Urls = getMP4Url (url)             ' Get a list of all MP4 URLs
   sdUrl = mp4Urls.sdUrl
   hdUrl = mp4Urls.hdUrl                 ' Will be empty string if no HD MP4 found
   hd1080pUrl = mp4Urls.hd1080pUrl       ' Will be empty string if no 1080p MP4 found
   
    urls = [sdUrl]
    qualities = ["SD"]
    StreamFormat = "mp4"
    title = "Youtube"
      
    if type(args) = "roAssociativeArray"
        if type(args.url) = "roString" and args.url <> "" then
            urls[0] = args.url
        end if
        if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
            StreamFormat = args.StreamFormat
        end if
        if type(args.title) = "roString" and args.title <> "" then
            title = args.title
        else
            title = ""
        end if
    end if
   
    videoclip = CreateObject("roAssociativeArray")
    videoclip.StreamBitrates = bitrates
    videoclip.StreamUrls = urls
    videoclip.StreamQualities = qualities
    videoclip.StreamFormat = StreamFormat
    videoclip.Title = title
   
    video.SetContent(videoclip)
    video.show()

    lastSavedPos   = 0
    statusInterval = 10 'position must change by more than this number of seconds before saving

    while true
        msg = wait(0, video.GetMessagePort())
        if type(msg) = "roVideoScreenEvent"
            if msg.isScreenClosed() then 'ScreenClosed event
                print "Closing video screen"
                exit while
            else if msg.isPlaybackPosition() then
                nowpos = msg.GetIndex()
                if nowpos > 10000
                   
                end if
                if nowpos > 0
                    if abs(nowpos - lastSavedPos) > statusInterval
                        lastSavedPos = nowpos
                    end if
                end if
            else if msg.isRequestFailed()
                print "play failed: "; msg.GetMessage()
            else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        end if
    end while
End Function


function getMP4Url (urlParam as string) as object
   mp4VideoList = {sdUrl: "", hdUrl: "", hd1080pUrl: ""}
   urlTransferObject = CreateObject ("roUrlTransfer")
   urlTransferObject.SetPort (CreateObject ("roMessagePort"))
   urlTransferObject.SetUrl (urlParam)
   htmlString = urlTransferObject.GetToString ()
   urlEncodedFmtStreamMap = CreateObject ("roRegex", "url_encoded_fmt_stream_map=([^(" + Chr (34) + "|&|$)]*)", "").Match (htmlString)
   if urlEncodedFmtStreamMap.Count () < 2 then return mp4VideoList
   urlEncodedFmtStreamList = CreateObject ("roRegex", "%2C", "").Split (urlEncodedFmtStreamMap [1])
   for each urlEncodedFmtStream in urlEncodedFmtStreamList
      urlStreamMatches = CreateObject ("roRegex", "url%3D(http.*?)%26", "").Match (urlEncodedFmtStream)
      if urlStreamMatches.Count () > 1
         urlDecoded = CreateObject ("roUrlTransfer").Unescape (CreateObject ("roUrlTransfer").Unescape (urlStreamMatches [1]))
         if CreateObject ("roRegex", "itag=18\D", "").IsMatch (urlDecoded)
            mp4VideoList.sdUrl = urlDecoded
         else if CreateObject ("roRegex", "itag=22\D", "").IsMatch (urlDecoded)
            mp4VideoList.hdUrl = urlDecoded
         else if CreateObject ("roRegex", "itag=37\D", "").IsMatch (urlDecoded)
            mp4VideoList.hd1080pUrl = urlDecoded
         endif
      endif
   end for
   return mp4VideoList
end function
 
bandal
Posts: 260
Joined: Sat Oct 15, 2011 2:17 pm

Re: Youtube contents in a private channel ?

Fri Dec 09, 2011 8:00 pm

Your the Man. It works. This is a first that I know of that someone can share the complete code when asked a question. Building my library little by little.
How would I make a list of various urls to select from on a PosterScreen? Lets say I want to see 5 of my youtube videos and want to select which one to play?

Thank You....

DA

Who is online

Users browsing this forum: No registered users and 6 guests