lost_RD

YouTube Selective Subscriptions

Sep 9th, 2014
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. -- created by /u/revereddesecration on 2014/09/09
  2. -- tested on Win7
  3.  
  4. -- you will need luarocks - see here: http://luarocks.org/en/Download
  5. -- xml module can be installed using "luarocks install xml"
  6. -- more info on the xml module: https://rocks.moonscript.org/modules/gaspard/xml
  7. -- you will also need curl - see here: http://curl.haxx.se/dlwiz/?type=bin
  8.  
  9. -- tprint not required, it just prints tables nicely
  10. assert(require "tprint", "tprint not found - no biggie smalls")
  11. xml = require "xml"
  12.  
  13. -- begin user input section
  14.  
  15. -- channel names must match youtube URL e.g. www.youtube.com/user/GuudeBoulderfist
  16.  
  17. channels = {
  18.     GuudeBoulderfist = {
  19.         patterns = {"Space", "crack"}
  20.     },
  21.     Pyropuncher = {
  22.         patterns = {"Civilization 5"}
  23.     },
  24.     DocM77 = {
  25.         patterns = {"Civilization V"}
  26.     },
  27.     VintageBeef = {
  28.         patterns = {"The Forest"} -- lol
  29.     },
  30.     SuperMCGamer = {
  31.         patterns = {"Zelda: Oracle of Seasons"}
  32.     },
  33.     MillBeeful = {
  34.         patterns = {"Mario Kart 8 :: The Road To 10,000"}
  35.     }
  36. }
  37.  
  38. -- end user input section
  39.  
  40. for channel,tableChannel in pairs(channels) do
  41.     os.execute("curl http://gdata.youtube.com/feeds/api/users/"..channel.."/uploads -o feeds/"..channel..".xml")
  42.     channels[channel].xml = xml.loadpath("feeds/"..channel..".xml")
  43.     channels[channel].videos = {}
  44.  
  45.     for k,v in pairs(channels[channel].xml) do
  46.         if (tonumber(k) or 1) > 16 then
  47.             n = tonumber(k)
  48.             channels[channel].videos[n] = {}
  49.             channels[channel].videos[n].title = v[6][1]
  50.             channels[channel].videos[n].time = v[2][1]
  51.             channels[channel].videos[n].url = string.sub(v[8].href, 1, 42)
  52.             channels[channel].videos[n].thumb = v[15][8].url
  53.         end
  54.     end
  55.     channels[channel].xml = nil
  56. end
  57.  
  58. videos = {}
  59.  
  60. function parseTime(s)
  61.     year = s:sub(1,4)
  62.     month = s:sub(6,7)
  63.     day = s:sub(9,10)
  64.     hour = s:sub(12,13)
  65.     minute = s:sub(15,16)
  66.     second = s:sub(18,19)
  67.     return tonumber(year..month..day..hour..minute..second)
  68. end
  69.  
  70. for channel,tableChannel in pairs(channels) do
  71.     for video,tableVideo in pairs(tableChannel.videos) do
  72.  
  73.         for _,pattern in pairs(tableChannel.patterns) do
  74.             if string.find(tableVideo.title, pattern) then
  75.  
  76.                 videos[parseTime(tableVideo.time)] = {
  77.                     channel = channel,
  78.                     title = tableVideo.title,
  79.                     url = tableVideo.url,
  80.                     thumb = tableVideo.thumb
  81.                 }
  82.             end
  83.         end
  84.  
  85.     end
  86. end
  87.  
  88. html = [[<head>
  89.     <style>
  90.         .thumbnail {
  91.             width: 200px;
  92.             height: 120px;
  93.         }
  94.  
  95.         /* resize images */
  96.         .thumbnail img {
  97.             width: 100%;
  98.             height: auto;
  99.         }
  100.     </style>
  101. </head>
  102.  
  103. <body>
  104.     <table>
  105.         <tr>
  106.             <th>Thumbnail</th>
  107.             <th>Information</th>
  108.         </tr>
  109.         ]]
  110.  
  111. a = {}
  112. for n in pairs(videos) do table.insert(a, n) end
  113. table.sort(a, function(a,b) return a>b end)
  114. for i,n in ipairs(a) do
  115.     html = html..[[<tr>
  116.             <td class="thumbnail">]].."<a href=\""..videos[n].url.."\"><img src=\""..videos[n].thumb.."\" />"..[[</td>
  117.             <td>]]..videos[n].channel.."<br/><a href=\""..videos[n].url.."\">"..videos[n].title.."<a/>"..[[</td>
  118.         </tr>
  119.         ]]
  120. end
  121. html = html..[[
  122.     </table>
  123. </body>]]
  124.  
  125. --print(html)
  126.  
  127. file = io.open("subs.html","w")
  128. file:write(html)
  129. file:close()
  130.  
  131. os.execute("subs.html")
  132. print("success!")
Advertisement
Add Comment
Please, Sign In to add comment