~vanvugt/+junk/mediatomb

« back to all changes in this revision

Viewing changes to src/youtube_service.h

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-03-02 13:09:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080302130916-zlljdze3kt7vuq4b
Tags: 0.11.0-1
* New upstream release.
* Include message about which inotify headers will be used when enabling
  inotify runtime support.
* Fixed error with use of INTERFACE in init script. Also removed use of -m
  option.
* Including new config.xml options.
* Added more build dependencies for new upstream release.
* Removed build dependency of libid3-dev, taglib is now preferred.
* mediatomb.xpm and manpage.xml is now included in orig tarball.
* inotify patch is not needed anymore.
* md5 patch has been committed upstream and is no longer needed. Also removed
  README.Debian.
* TwinHelix PNG fix is now used. Removed from TODO.
* Adding dependency of iceweasel for mediatomb package.
* Updated copyright file.
* Updated watch file.
* Updated rules file for proper configure options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*MT*
 
2
    
 
3
    MediaTomb - http://www.mediatomb.cc/
 
4
    
 
5
    youtube_service.h - this file is part of MediaTomb.
 
6
    
 
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
 
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
 
9
    
 
10
    Copyright (C) 2006-2008 Gena Batyan <bgeradz@mediatomb.cc>,
 
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
 
12
                            Leonhard Wimmer <leo@mediatomb.cc>
 
13
    
 
14
    MediaTomb is free software; you can redistribute it and/or modify
 
15
    it under the terms of the GNU General Public License version 2
 
16
    as published by the Free Software Foundation.
 
17
    
 
18
    MediaTomb is distributed in the hope that it will be useful,
 
19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
    GNU General Public License for more details.
 
22
    
 
23
    You should have received a copy of the GNU General Public License
 
24
    version 2 along with MediaTomb; if not, write to the Free Software
 
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
    
 
27
    $Id: youtube_service.h 1698 2008-02-23 20:48:30Z lww $
 
28
*/
 
29
 
 
30
/// \file youtube_service.h
 
31
/// \brief Definition of the YouTubeService class.
 
32
 
 
33
#if defined(YOUTUBE) // make sure to add more ifdefs when we get more services
 
34
 
 
35
#ifndef __YOUTUBE_SERVICE_H__
 
36
#define __YOUTUBE_SERVICE_H__
 
37
 
 
38
#include "zmm/zmm.h"
 
39
#include "mxml/mxml.h"
 
40
#include "online_service.h"
 
41
#include "url.h"
 
42
#include "dictionary.h"
 
43
 
 
44
typedef enum 
 
45
{
 
46
    YT_list_none = 0,
 
47
    YT_list_favorite,
 
48
    YT_list_by_tag,
 
49
    YT_list_by_user,
 
50
    YT_list_featured,
 
51
    YT_list_by_playlist,
 
52
    YT_list_popular,
 
53
    YT_list_by_category_and_tag
 
54
} yt_methods_t;
 
55
 
 
56
typedef enum
 
57
{
 
58
    YT_cat_none                     = 0,
 
59
    YT_cat_film_and_animation       = 1,
 
60
    YT_cat_autos_and_vehicles       = 2,
 
61
    YT_cat_music                    = 10,
 
62
    YT_cat_pets_and_animals         = 15,
 
63
    YT_cat_sports                   = 17,
 
64
    YT_cat_travel_and_places        = 19,
 
65
    YT_cat_gadgets_and_games        = 20,
 
66
    YT_cat_people_and_blogs         = 22,
 
67
    YT_cat_comedy                   = 23,
 
68
    YT_cat_entertainment            = 24,
 
69
    YT_cat_news_and_politics        = 25,
 
70
    YT_cat_howto_and_diy            = 26
 
71
} yt_categories_t;
 
72
 
 
73
/// \brief This is an interface for all online services, the function
 
74
/// handles adding/refreshing content in the database.
 
75
class YouTubeService : public OnlineService
 
76
{
 
77
public:
 
78
    YouTubeService();
 
79
    ~YouTubeService();
 
80
    /// \brief Retrieves user specified content from the service and adds
 
81
    /// the items to the database.
 
82
    virtual bool refreshServiceData(zmm::Ref<Layout> layout);
 
83
 
 
84
    /// \brief Get the type of the service (i.e. YouTube, Shoutcast, etc.)
 
85
    virtual service_type_t getServiceType();
 
86
 
 
87
    /// \brief Get the human readable name for the service
 
88
    virtual zmm::String getServiceName();
 
89
 
 
90
    /// \brief Parse the xml fragment from the configuration and gather
 
91
    /// the user settings in a service task structure.
 
92
    virtual zmm::Ref<zmm::Object> defineServiceTask(zmm::Ref<mxml::Element> xmlopt);
 
93
 
 
94
    /// \brief Get the human readable name of a particular request type, i.e.
 
95
    /// did we request Favorites or Featured videos, etc.
 
96
    static zmm::String getRequestName(yt_methods_t method);
 
97
 
 
98
    /// \brief Get the human readable category name
 
99
    static zmm::String getCategoryName(yt_categories_t category);
 
100
 
 
101
protected:
 
102
    // the handle *must never be used from multiple threads*
 
103
    CURL *curl_handle;
 
104
    // safeguard to ensure the above
 
105
    pthread_t pid;
 
106
 
 
107
    // url retriever class
 
108
    zmm::Ref<URL> url;
 
109
 
 
110
    /// \brief This function will retrieve the XML according to the parametrs
 
111
    zmm::Ref<mxml::Element> getData(zmm::Ref<Dictionary> params);
 
112
 
 
113
    /// \brief This class defines the so called "YouTube task", the task
 
114
    /// holds various parameters that are needed to perform. A task means
 
115
    /// the process of downloading, parsing service data and creating
 
116
    /// CdsObjects.
 
117
    class YouTubeTask : public zmm::Object
 
118
    {
 
119
    public:
 
120
        YouTubeTask();
 
121
 
 
122
        /// \brief Method identifier
 
123
        yt_methods_t method;
 
124
 
 
125
        /// \brief Category identifier, only used with the
 
126
        /// YT_list_by_category_and_tag method
 
127
        yt_categories_t category;
 
128
        
 
129
        /// \brief parameter=value for the REST API URL
 
130
        zmm::Ref<Dictionary> parameters;
 
131
        
 
132
        /// \brief Amount of items that we are allowed to get.
 
133
        int amount;
 
134
 
 
135
        /// \brief Amount of items that have been fetched.
 
136
        int amount_fetched;
 
137
 
 
138
        /// \brief Current page for requests that require paging
 
139
        int current_page;
 
140
 
 
141
        /// \brief Playlist name defined by the user (only set if method
 
142
        /// equals YT_list_by_playlist)
 
143
        zmm::String playlist_name;
 
144
    };
 
145
 
 
146
    /// \brief task that we will be working with when refreshServiceData is
 
147
    /// called.
 
148
    int current_task;
 
149
 
 
150
    /// \brief utility function, returns true if method supports paging
 
151
    bool hasPaging(yt_methods_t method);
 
152
 
 
153
    // helper functions for parsing config.xml
 
154
    zmm::String getCheckAttr(zmm::Ref<mxml::Element> xml, zmm::String attrname);
 
155
    int getCheckPosIntAttr(zmm::Ref<mxml::Element> xml, zmm::String attrname);
 
156
    void addPagingParams(zmm::Ref<mxml::Element> xml, 
 
157
                         zmm::Ref<YouTubeTask> task);
 
158
};
 
159
 
 
160
#endif//__ONLINE_SERVICE_H__
 
161
 
 
162
#endif//YOUTUBE