Created
December 1, 2017 13:54
-
-
Save opn/faaa0da7aa235f0bfbc1bffa93130a20 to your computer and use it in GitHub Desktop.
This is Revigniter controller 'youtube.lc' from the domain 'rest.livecode.world'.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?rev | |
put "index,recentFirst,recentBullets,oldestFirst,recentMarkdown,oldestBullets,fetchAll,fetchThumb,transportAgain" into gControllerHandlers | |
startUsingLibraries | |
on index | |
fedwiki_DeconstructDroppedURL $_POST_RAW, droppedURL, droppedHtml | |
put youtube_ParseDropUrl (droppedURL) into pageJSON | |
fedwiki_ReturnJSON pageJSON | |
end index | |
on transportAgain | |
put $_POST_RAW into someJSON | |
put json_ToArray (someJSON) into createArray | |
put createArray ["title"] into sectionTitle | |
put createArray ["create"]["source"] into sourceArray | |
-- put createArray ["create"]["item"]["title"] into parentTitle | |
if sourceArray is not an array then | |
put fedwiki_ConstructErrorJSON ("This is not create JSON", "Error") into errorJSON | |
fedwiki_ReturnJSON errorJSON | |
return false | |
end if | |
put sourceArray ["transport"] into transportURL | |
put sourceArray ["link_dictionary"] into linkDictionary | |
put linkDictionary [sectionTitle] into snippetArray | |
deconstruct_VideoSnippetArray snippetArray, videoTitle, videoDescription, videoID, thumbNailURL, publishedAt, positionPlusOneNum, tagArray, thumbNailWidth | |
-- put "OrH6UMYAVsk" into videoID | |
put youtube_FetchVideoPageJSON (videoID) into pageJSON | |
fedwiki_ReturnJSON pageJSON | |
end transportAgain | |
on fetchThumb | |
fedwiki_DeconstructDroppedURL $_POST_RAW, droppedURL, droppedHtml | |
put youtube_ParseThumbUrl (droppedURL) into pageJSON | |
fedwiki_ReturnJSON pageJSON | |
end fetchThumb | |
on fetchAll | |
fedwiki_DeconstructDroppedURL $_POST_RAW, droppedURL, droppedHtml | |
put youtube_ParseAllDropUrl (droppedURL) into pageJSON | |
fedwiki_ReturnJSON pageJSON | |
end fetchAll | |
on recentMarkdown | |
fedwiki_DeconstructDroppedURL $_POST_RAW, droppedURL, droppedHtml | |
put youtube_ListAllDropUrl (droppedURL, "recentFirst", true, true) into pageJSON | |
fedwiki_ReturnJSON pageJSON | |
end recentMarkdown | |
on oldestFirst | |
fedwiki_DeconstructDroppedURL $_POST_RAW, droppedURL, droppedHtml | |
put youtube_ListAllDropUrl (droppedURL, "oldestFirst") into pageJSON | |
fedwiki_ReturnJSON pageJSON | |
end oldestFirst | |
on recentFirst | |
fedwiki_DeconstructDroppedURL $_POST_RAW, droppedURL, droppedHtml | |
put youtube_ListAllDropUrl (droppedURL, "recentFirst") into pageJSON | |
fedwiki_ReturnJSON pageJSON | |
end recentFirst | |
on oldestBullets | |
fedwiki_DeconstructDroppedURL $_POST_RAW, droppedURL, droppedHtml | |
put youtube_ListAllDropUrl (droppedURL, "oldestFirst", false) into pageJSON | |
fedwiki_ReturnJSON pageJSON | |
end oldestBullets | |
on recentBullets | |
fedwiki_DeconstructDroppedURL $_POST_RAW, droppedURL, droppedHtml | |
put youtube_ListAllDropUrl (droppedURL, "recentFirst", false) into pageJSON | |
fedwiki_ReturnJSON pageJSON | |
end recentBullets | |
function youtube_ParseDropUrl droppedURL | |
set the itemdelimiter to "/" | |
put item 3 of droppedURL into youtubeBit | |
put item 4 of droppedURL into switchOrArray | |
put item 5 of droppedURL into extraBit | |
if youtubeBit is not "www.youtube.com" then | |
put youtube_FetchNextPageJson (droppedURL, droppedHtml) into pageJSON | |
return pageJSON | |
end if | |
put 10 into pMaxResults | |
put true into pDontLinkTitle | |
set the itemdelimiter to "?" | |
put item 1 of switchOrArray into switchBit | |
switch switchBit | |
case "playlist" | |
-- https://www.youtube.com/playlist?list=PLPj3KCksGbSY-RaXfrGPnY8uEOl6uylky | |
delete item 1 of switchOrArray | |
split switchOrArray with "&" and "=" | |
put switchOrArray ["list"] into playlistID | |
put "" into pPageTitle | |
put youtube_FetchPlayListPageJson (playlistID, pPageTitle, pMaxResults, pDontLinkTitle) into someJSON | |
return someJSON | |
case "watch" | |
-- https://www.youtube.com/watch?v=nU4Ggyobi3k&index=6&list=PLPj3KCksGbSY-RaXfrGPnY8uEOl6uylky | |
delete item 1 of switchOrArray | |
split switchOrArray with "&" and "=" | |
put switchOrArray ["v"] into videoID | |
put youtube_FetchVideoPageJSON (videoID) into someJSON | |
return someJSON | |
case "channel" | |
-- https://www.youtube.com/channel/UCR9gdpWisRwnk_k23GsHfcA | |
put extraBit into channelID | |
put youtube_FetchChannelUploadPageJson (channelID, pMaxResults, pDontLinkTitle) into someJSON | |
fedwiki_ReturnJSON someJSON | |
break | |
case "user" | |
put false into pDontLinkTitle | |
put extraBit into userName | |
put youtube_FetchUserUploadPageJson (userName, pMaxResults, pDontLinkTitle) into someJSON | |
return someJSON | |
default | |
put "Not a link that I can parse." & CR & CR & dropJSON into someInfo | |
put fedwiki_ConstructErrorJSON (someInfo) into someJSON | |
return someJSON | |
end switch | |
end youtube_ParseDropUrl | |
function youtube_ListAllDropUrl droppedURL, pDirection, pNumbered | |
put false into pDontLinkTitle | |
set the itemdelimiter to "/" | |
put item 3 of droppedURL into youtubeBit | |
put item 4 of droppedURL into switchOrArray | |
put item 5 of droppedURL into extraBit | |
set the itemdelimiter to "?" | |
put item 1 of switchOrArray into switchBit | |
switch switchBit | |
case "user" | |
put "Not done users yet for indexes" & CR & CR & dropJSON into someInfo | |
put fedwiki_ConstructErrorJSON (someInfo) into someJSON | |
return someJSON | |
case "channel" | |
put extraBit into channelID | |
put youtube_FetchChannelIndexPageJson (channelID) into pageJSON | |
return pageJSON | |
case "playlist" | |
delete item 1 of switchOrArray | |
split switchOrArray with "&" and "=" | |
put switchOrArray ["list"] into playlistID | |
put empty into pPageTitle | |
put youtube_FetchPlayListIndexPageJson (playlistID, pPageTitle, pDirection, pNumbered, droppedURL) into pageJSON | |
return pageJSON | |
default | |
put "Not a link that I can parse." & CR & CR & dropJSON into someInfo | |
put fedwiki_ConstructErrorJSON (someInfo) into someJSON | |
return someJSON | |
end switch | |
end youtube_ListAllDropUrl | |
function youtube_ParseAllDropUrl droppedURL | |
put false into pDontLinkTitle | |
set the itemdelimiter to "/" | |
put item 3 of droppedURL into youtubeBit | |
put item 4 of droppedURL into switchOrArray | |
put item 5 of droppedURL into extraBit | |
set the itemdelimiter to "?" | |
put item 1 of switchOrArray into switchBit | |
switch switchBit | |
case "playlist" | |
delete item 1 of switchOrArray | |
split switchOrArray with "&" and "=" | |
put switchOrArray ["list"] into playlistID | |
put "" into pPageTitle | |
put youtube_FetchAllPlayListPageJson (playlistID, pPageTitle, pDontLinkTitle) into pageJSON | |
return pageJSON | |
case "channel" | |
-- put wcn_GetChannelID() into channelID | |
put extraBit into channelID | |
put youtube_FetchAllChannelUploadPageJson (channelID, false) into someJSON | |
return someJSON | |
case "user" | |
put extraBit into userName | |
put youtube_FetchAllUserUploadPageJson (userName, pDontLinkTitle) into someJSON | |
return someJSON | |
case "watch" -- only one thing anyway | |
delete item 1 of switchOrArray | |
split switchOrArray with "&" and "=" | |
put switchOrArray ["v"] into videoID | |
put youtube_FetchVideoPageJSON (videoID) into someJSON | |
return someJSON | |
default | |
put "Not a link that I can parse." & CR & CR & dropJSON into someInfo | |
put fedwiki_ConstructErrorJSON (someInfo) into someJSON | |
return someJSON | |
end switch | |
end youtube_ParseAllDropUrl | |
function youtube_ParseThumbUrl droppedURL | |
set the itemdelimiter to "/" | |
put item 3 of droppedURL into youtubeBit | |
put item 4 of droppedURL into switchOrArray | |
put item 5 of droppedURL into extraBit | |
set the itemdelimiter to "?" | |
put item 1 of switchOrArray into switchBit | |
switch switchBit | |
case "playlist" | |
delete item 1 of switchOrArray | |
split switchOrArray with "&" and "=" | |
put switchOrArray ["list"] into playlistID | |
return pageJSON | |
case "channel" | |
put extraBit into channelID | |
return pageJSON | |
case "user" | |
put extraBit into userName | |
return someJSON | |
case "watch" -- only one thing anyway | |
delete item 1 of switchOrArray | |
split switchOrArray with "&" and "=" | |
put switchOrArray ["v"] into videoID | |
put youtube_FetchVideoThumbPageJSON (videoID) into someJSON | |
return someJSON | |
default | |
put "Not a link that I can parse." & CR & CR & dropJSON into someInfo | |
put fedwiki_ConstructErrorJSON (someInfo) into someJSON | |
return someJSON | |
end switch | |
end youtube_ParseThumbUrl | |
command startUsingLibraries | |
start using stack (gAPPPATH & "stacks/lib_Audioboom.livecode") | |
start using stack (gAPPPATH & "stacks/lib_CCC.livecode") | |
start using stack (gAPPPATH & "stacks/lib_Embedly.livecode") | |
start using stack (gAPPPATH & "stacks/lib_Fedwiki.livecode") | |
start using stack (gAPPPATH & "stacks/lib_FedWikiPedia.livecode") | |
start using stack (gAPPPATH & "stacks/lib_MediaWiki.livecode") | |
start using stack (gAPPPATH & "stacks/lib_Text.livecode") | |
start using stack (gAPPPATH & "stacks/lib_XML.livecode") | |
start using stack (gAPPPATH & "stacks/lib_Youtube.livecode") | |
end startUsingLibraries | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment