Update addon.js
Browse files26 unmodified lines2728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713810 unmodified lines14915015115215315415515622 unmodified lines1791801811821831841855 unmodified lines1911921931941951961978 unmodified lines2062072082092102112122132142152162172182192202212222232242252262272282298 unmodified lines2382392402412422432442452462472482492502512522532546 unmodified lines26126226326426526626726826927027127227327423 unmodified lines29829930030130230330430530630730830931031131231331431531631731826 unmodified lines3453463473483493503513523533543553563573586 unmodified lines365366367368369370371372373109 unmodified lines48348448548648748848949049149249349449549648 unmodified lines54554654754854955055113 unmodified lines56556656756856957047 unmodified lines61861962062162262362426 unmodified lines"Ancient Civilizations"];const manifest = {id: "hy.community.ytdocumentaries",version: "0.4.0",name: "YouTube Documentaries",description: "Discover documentaries from YouTube with channels, playlists, and genres",logo: "https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/YouTube_full-color_icon_%282017%29.svg/1280px-YouTube_full-color_icon_%282017%29.svg.png",resources: ["catalog", "meta", "stream"],types: ["movie", "series"],catalogs: [{type: "movie",id: "ytdocs",name: "YouTube Documentaries",extra: [{name: "genre",isRequired: false,options: documentaryGenres // This is the key change - explicitly provide genre options},{ name: "search", isRequired: false },{ name: "skip", isRequired: false }],// Important: Add genres array at catalog level (not just in extra)genres: documentaryGenres},{type: "movie",id: "ytdocs-by-tag",name: "Tagged Docs",extra: [{ name: "search", isRequired: true },{ name: "skip", isRequired: false }]},{// Clearly labeled channel catalogtype: "series",id: "ytdocs-channels",name: "CHANNELS: Documentary",extra: [{name: "genre",isRequired: false,options: ["Education","History","Science","Travel","Wildlife","News","Conspiracy","Technology","Archaeology"]},{ name: "search", isRequired: false },{ name: "skip", isRequired: false }],// Important: Add genres array at catalog levelgenres: ["Education","History","Science","Travel","Wildlife","News","Conspiracy","Technology","Archaeology"]},{// Clearly labeled playlist catalogtype: "series",id: "ytdocs-playlists",name: "PLAYLISTS: Documentary",extra: [{name: "genre",isRequired: false,options: ["Educational","Series","Collections","Lectures","Top Documentaries","Mysteries","Historical Events","Science Explained","Nature & Wildlife"]},{ name: "search", isRequired: false },{ name: "skip", isRequired: false }],// Important: Add genres array at catalog levelgenres: ["Educational","Series","Collections","Lectures","Top Documentaries","Mysteries","Historical Events","Science Explained","Nature & Wildlife"]}],10 unmodified linesconst skip = parseInt(extra.skip || 0);const pageSize = 50;// Handle different catalog typesif (type === "movie" && (id === "ytdocs" || id === "ytdocs-by-tag")) {let searchQuery;if (id === "ytdocs-by-tag") {22 unmodified linesconst metas = videos.map(video => ({id: `yt:${video.id}`,type: "movie",name: video.title,poster: video.thumbnail,description: video.description,5 unmodified linesreturn { metas };}// Handle channel search - explicitly using channel search typeelse if (type === "series" && id === "ytdocs-channels") {// Use genre if provided, otherwise use default or searchconst searchTerm = extra.genre ? extra.genre : "documentary";const searchQuery = extra.search ? `${extra.search} ${searchTerm}` : searchTerm;8 unmodified linesquery: searchQuery,maxResults: pageSize,skip,type: 'channel' // This is the key - must use 'channel'});const metas = channels.map(channel => ({id: `ytchannel:${channel.id}`,type: "series",name: channel.title,poster: channel.thumbnail,posterShape: "square",description: channel.description,genres: ["Documentary", extra.genre || "YouTube Channel"]}));cache.set(cacheKey, metas);return { metas };}// Handle playlist search - explicitly using playlist search typeelse if (type === "series" && id === "ytdocs-playlists") {// Use genre if provided, otherwise use default or searchconst searchTerm = extra.genre ? extra.genre : "documentary";const searchQuery = extra.search ? `${extra.search} ${searchTerm}` : searchTerm;8 unmodified linesquery: searchQuery,maxResults: pageSize,skip,type: 'playlist' // This is the key - must use 'playlist'});const metas = playlists.map(playlist => ({id: `ytplaylist:${playlist.id}`,type: "series",name: playlist.title,poster: playlist.thumbnail,posterShape: "landscape",description: playlist.description,genres: ["Documentary", extra.genre || "YouTube Playlist"]}));cache.set(cacheKey, metas);6 unmodified linesbuilder.defineMetaHandler(async ({ type, id }) => {console.log(`[META] Request for ${type} with id ${id}`);// Handle single video metaif (type === "movie" && id.startsWith("yt:")) {const videoId = id.split(":")[1];const meta = await fetchVideoMeta(videoId);return { meta };}// Handle channel meta with videos as episodeselse if (type === "series" && id.startsWith("ytchannel:")) {const channelId = id.split(":")[1];const cacheKey = `meta_channel_${channelId}`;const cached = cache.get(cacheKey);23 unmodified linesconst meta = {id: `ytchannel:${channelId}`,type: "series",name: channelInfo.title,poster: channelInfo.thumbnail,posterShape: "square",background: channelInfo.banner || channelInfo.thumbnail,description: channelInfo.description,genres: ["Documentary", "YouTube Channel"],videos: videos};cache.set(cacheKey, meta);return { meta };}// Handle playlist meta with videos as episodeselse if (type === "series" && id.startsWith("ytplaylist:")) {const playlistId = id.split(":")[1];const cacheKey = `meta_playlist_${playlistId}`;const cached = cache.get(cacheKey);26 unmodified linesconst meta = {id: `ytplaylist:${playlistId}`,type: "series",name: playlistInfo.title,poster: playlistInfo.thumbnail,posterShape: "landscape",background: playlistInfo.thumbnail,description: playlistInfo.description,genres: ["Documentary", "YouTube Playlist"],videos: videos};cache.set(cacheKey, meta);6 unmodified lines// STREAM HANDLER - DIRECT YOUTUBE INTEGRATIONbuilder.defineStreamHandler(({ type, id }) => {console.log(`[STREAM] Request for ${id}`);if (!id.startsWith("yt:")) {return Promise.resolve({ streams: [] });}const videoId = id.split(":")[1];console.log(`[STREAM] Found YouTube video ID: ${videoId}`);109 unmodified linesconst meta = {id: `yt:${videoId}`,type: "movie",name: item.snippet.title,description: item.snippet.description,poster: item.snippet.thumbnails.high?.url || item.snippet.thumbnails.default?.url,posterShape: "landscape",background: item.snippet.thumbnails.high?.url || item.snippet.thumbnails.default?.url,released: item.snippet.publishedAt,genres: genres,releaseInfo: item.snippet.publishedAt ? new Date(item.snippet.publishedAt).getFullYear().toString() : "",runtime: item.contentDetails?.duration ? convertDuration(item.contentDetails.duration) : null,// Add watch count48 unmodified linestitle: item.snippet.title,description: `${item.snippet.description}\n\nSubscribers: ${formatSubscriberCount(item.statistics?.subscriberCount)}`,thumbnail: item.snippet.thumbnails.high?.url || item.snippet.thumbnails.default?.url,banner: bannerUrl};} catch (error) {console.error("Error fetching channel info:", error);13 unmodified linesreturn subscribers.toString();}async function fetchChannelVideos(channelId, maxResults = 50) {try {const youtube = google.youtube({ version: "v3", auth: "AIzaSyCRFgNu3-oNfGA1IZQ88Qc4k0Pq_jG6IpY" });47 unmodified linestitle: item.snippet.title,description: `${item.snippet.description}\n\nVideos: ${item.contentDetails.itemCount || 'Unknown'} (${privacy})`,thumbnail: item.snippet.thumbnails.high?.url || item.snippet.thumbnails.medium?.url || item.snippet.thumbnails.default?.url,videoCount: item.contentDetails.itemCount};} catch (error) {console.error("Error fetching playlist info:", error);26 unmodified lines2728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512610 unmodified lines13713813914014114214314414514614714814922 unmodified lines1721731741751761771785 unmodified lines1841851861871881891908 unmodified lines1992002012022032042052062072082092102112122132142152162172182192202212222232242252262278 unmodified lines2362372382392402412422432442452462472482492502512522532542552562576 unmodified lines26426526626726826927027127227327427527627727827928028128223 unmodified lines30630730830931031131231331431531631731831932032132232332432532632732826 unmodified lines3553563573583593603613623633643653663673683693706 unmodified lines377378379380381382383384385386387388389390391392109 unmodified lines50250350450550650750850951051151251351451551651748 unmodified lines56656756856957057157257313 unmodified lines58758858959059159259359459559659759859960060160247 unmodified lines65065165265365465565626 unmodified lines"Ancient Civilizations"];// Channel-specific genresconst channelGenres = ["Education","History","Science","Travel","Wildlife","News","Conspiracy","Technology","Archaeology","Space","Anthropology","Culture"];// Playlist-specific genresconst playlistGenres = ["Educational","Series","Collections","Lectures","Top Documentaries","Mysteries","Historical Events","Science Explained","Nature & Wildlife"];const manifest = {id: "hy.community.ytdocumentaries",version: "0.5.0",name: "YouTube Documentaries",description: "Discover documentaries from YouTube with channels, playlists, and genres",logo: "https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/YouTube_full-color_icon_%282017%29.svg/1280px-YouTube_full-color_icon_%282017%29.svg.png",resources: ["catalog", "meta", "stream"],types: ["documentary"], // Single coherent type for better organizationcatalogs: [{// Main catalog for individual documentariestype: "documentary",id: "ytdocs",name: "YouTube Documentaries",extra: [{name: "genre",isRequired: false,options: documentaryGenres},{ name: "search", isRequired: false },{ name: "skip", isRequired: false }],genres: documentaryGenres},{// Channel catalogtype: "documentary",id: "ytdocs-channels",name: "Documentary Channels",extra: [{name: "genre",isRequired: false,options: channelGenres},{ name: "search", isRequired: false },{ name: "skip", isRequired: false }],genres: channelGenres},{// Playlist catalogtype: "documentary",id: "ytdocs-playlists",name: "Documentary Playlists",extra: [{name: "genre",isRequired: false,options: playlistGenres},{ name: "search", isRequired: false },{ name: "skip", isRequired: false }],genres: playlistGenres},{// Tag-based search catalogtype: "documentary",id: "ytdocs-by-tag",name: "Tagged Documentaries",extra: [{ name: "search", isRequired: true },{ name: "skip", isRequired: false }]}],10 unmodified linesconst skip = parseInt(extra.skip || 0);const pageSize = 50;// Only respond to documentary type requestsif (type !== "documentary") {return { metas: [] };}// Handle different catalog typesif (id === "ytdocs" || id === "ytdocs-by-tag") {let searchQuery;if (id === "ytdocs-by-tag") {22 unmodified linesconst metas = videos.map(video => ({id: `yt:${video.id}`,type: "documentary",name: video.title,poster: video.thumbnail,description: video.description,5 unmodified linesreturn { metas };}// Handle channel search - explicitly using channel search typeelse if (id === "ytdocs-channels") {// Use genre if provided, otherwise use default or searchconst searchTerm = extra.genre ? extra.genre : "documentary";const searchQuery = extra.search ? `${extra.search} ${searchTerm}` : searchTerm;8 unmodified linesquery: searchQuery,maxResults: pageSize,skip,type: 'channel'});const metas = channels.map(channel => ({id: `ytchannel:${channel.id}`,type: "documentary",name: channel.title,poster: channel.thumbnail,posterShape: "square",description: channel.description,genres: ["Documentary Channel", extra.genre || "Educational"],videoCount: "Channel", // Use this field to identify as a channel in UIbehaviorHints: {defaultVideoId: null, // Signal this is not a single videohasCollections: true // Signal this item has collections (videos)}}));cache.set(cacheKey, metas);return { metas };}// Handle playlist search - explicitly using playlist search typeelse if (id === "ytdocs-playlists") {// Use genre if provided, otherwise use default or searchconst searchTerm = extra.genre ? extra.genre : "documentary";const searchQuery = extra.search ? `${extra.search} ${searchTerm}` : searchTerm;8 unmodified linesquery: searchQuery,maxResults: pageSize,skip,type: 'playlist'});const metas = playlists.map(playlist => ({id: `ytplaylist:${playlist.id}`,type: "documentary",name: playlist.title,poster: playlist.thumbnail,posterShape: "landscape",description: playlist.description,genres: ["Documentary Playlist", extra.genre || "Collection"],videoCount: "Playlist", // Use this field to identify as a playlist in UIbehaviorHints: {defaultVideoId: null, // Signal this is not a single videohasCollections: true // Signal this item has collections (videos)}}));cache.set(cacheKey, metas);6 unmodified linesbuilder.defineMetaHandler(async ({ type, id }) => {console.log(`[META] Request for ${type} with id ${id}`);// Only respond to documentary type requestsif (type !== "documentary") {return { meta: null };}// Handle single video metaif (id.startsWith("yt:")) {const videoId = id.split(":")[1];const meta = await fetchVideoMeta(videoId);return { meta };}// Handle channel meta with videos as episodeselse if (id.startsWith("ytchannel:")) {const channelId = id.split(":")[1];const cacheKey = `meta_channel_${channelId}`;const cached = cache.get(cacheKey);23 unmodified linesconst meta = {id: `ytchannel:${channelId}`,type: "documentary",name: channelInfo.title,poster: channelInfo.thumbnail,posterShape: "square",background: channelInfo.banner || channelInfo.thumbnail,description: channelInfo.description,genres: ["Documentary Channel", "Educational"],videos: videos,videoCount: channelInfo.videoCount || "Unknown",releaseInfo: `${videos.length} documentaries`};cache.set(cacheKey, meta);return { meta };}// Handle playlist meta with videos as episodeselse if (id.startsWith("ytplaylist:")) {const playlistId = id.split(":")[1];const cacheKey = `meta_playlist_${playlistId}`;const cached = cache.get(cacheKey);26 unmodified linesconst meta = {id: `ytplaylist:${playlistId}`,type: "documentary",name: playlistInfo.title,poster: playlistInfo.thumbnail,posterShape: "landscape",background: playlistInfo.thumbnail,description: playlistInfo.description,genres: ["Documentary Playlist", "Collection"],videos: videos,videoCount: playlistInfo.videoCount || "Unknown",releaseInfo: `${videos.length} documentaries`};cache.set(cacheKey, meta);6 unmodified lines// STREAM HANDLER - DIRECT YOUTUBE INTEGRATIONbuilder.defineStreamHandler(({ type, id }) => {console.log(`[STREAM] Request for ${id}`);// Only respond to documentary type requests or handle YouTube IDsif (type !== "documentary" && !id.startsWith("yt:")) {return Promise.resolve({ streams: [] });}if (!id.startsWith("yt:")) {return Promise.resolve({ streams: [] });}const videoId = id.split(":")[1];console.log(`[STREAM] Found YouTube video ID: ${videoId}`);109 unmodified linesconst meta = {id: `yt:${videoId}`,type: "documentary",name: item.snippet.title,description: item.snippet.description,poster: item.snippet.thumbnails.high?.url || item.snippet.thumbnails.default?.url,posterShape: "landscape",background: item.snippet.thumbnails.maxres?.url ||item.snippet.thumbnails.high?.url ||item.snippet.thumbnails.default?.url,released: item.snippet.publishedAt,genres: genres.length > 0 ? genres : ["Documentary"],releaseInfo: item.snippet.publishedAt ? new Date(item.snippet.publishedAt).getFullYear().toString() : "",runtime: item.contentDetails?.duration ? convertDuration(item.contentDetails.duration) : null,// Add watch count48 unmodified linestitle: item.snippet.title,description: `${item.snippet.description}\n\nSubscribers: ${formatSubscriberCount(item.statistics?.subscriberCount)}`,thumbnail: item.snippet.thumbnails.high?.url || item.snippet.thumbnails.default?.url,banner: bannerUrl,videoCount: formatVideoCount(item.statistics?.videoCount)};} catch (error) {console.error("Error fetching channel info:", error);13 unmodified linesreturn subscribers.toString();}function formatVideoCount(count) {if (!count) return "Unknown";const videos = parseInt(count);if (videos > 1000) {return `${(videos / 1000).toFixed(1)}K videos`;}return `${videos} videos`;}async function fetchChannelVideos(channelId, maxResults = 50) {try {const youtube = google.youtube({ version: "v3", auth: "AIzaSyCRFgNu3-oNfGA1IZQ88Qc4k0Pq_jG6IpY" });47 unmodified linestitle: item.snippet.title,description: `${item.snippet.description}\n\nVideos: ${item.contentDetails.itemCount || 'Unknown'} (${privacy})`,thumbnail: item.snippet.thumbnails.high?.url || item.snippet.thumbnails.medium?.url || item.snippet.thumbnails.default?.url,videoCount: `${item.contentDetails.itemCount || 'Unknown'} videos`};} catch (error) {console.error("Error fetching playlist info:", error);
addon.js+121-89