1--[[ 2 $Id$ 3 4 Copyright © 2016 the VideoLAN team 5 6 Authors: Pierre Ynard 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 21--]] 22 23-- Probe function. 24function probe() 25 return ( vlc.access == "http" or vlc.access == "https" ) 26 and string.match( vlc.path, "^www%.newgrounds%.com/.*/%d+" ) 27end 28 29-- Parse function. 30function parse() 31 local path, title, description, arturl, author 32 while true do 33 local line = vlc.readline() 34 if not line then break end 35 36 if not title then 37 title = string.match( line, "<meta property=\"og:title\" content=\"(.-)\"" ) 38 if title then 39 title = vlc.strings.resolve_xml_special_chars( title ) 40 end 41 end 42 43 if not description then 44 description = string.match( line, "<meta property=\"og:description\" content=\"(.-)\"" ) 45 if description then 46 description = vlc.strings.resolve_xml_special_chars( description ) 47 end 48 end 49 50 if not arturl then 51 arturl = string.match( line, "<meta property=\"og:image\" content=\"(.-)\"" ) 52 if arturl then 53 arturl = vlc.strings.resolve_xml_special_chars( arturl ) 54 end 55 end 56 57 if not author then 58 author = string.match( line, "<em>Author <a [^>]*>([^<]+)</a></em>" ) 59 if author then 60 author = vlc.strings.resolve_xml_special_chars( author ) 61 end 62 end 63 64 if not path then 65 path = string.match( line, 'new embedController%(%[{"url":"([^"]+)"' ) 66 if path then 67 path = string.gsub( path, "\\/", "/" ) 68 end 69 end 70 end 71 72 if not path then 73 vlc.msg.err( "Couldn't extract newgrounds media URL" ) 74 return { } 75 end 76 77 return { { path = path, name = title, description = description, arturl = arturl, artist = author } } 78end 79